加密shell脚本
#!/bin/bashCURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"CMP_PATH=$CURRENT_PATH/quick/binSRC_PATH=$CURRENT_PATH/../srcOUT_PATH=$CURRENT_PATH/../res/scMYSIG="BJGAME"MYKEY="W@Z#X^^"cd $CMP_PATH# ./compile_scripts.sh -i $SRC_PATH -x main,config,cocos,framework -o $OUT_PATH/game.tg -e xxtea_zip -es $MYSIG -ek $MYKEY#androID的可能有问题./compile_scripts.sh -m files -i $SRC_PATH -x main,framework -o $OUT_PATH/ -e xxtea_chunk -es $MYSIG -ek $MYKEY
参数详解
compile_scripts.sh和compile_scripts.PHP在quick-cocos2dx引擎安装目录下
$options = array( array('h','help',false,'show help'),array('i','src',1,null,'source files directory'),array('o','output','output filename | output directory'),array('p','prefix','','package prefix name'),array('x','excludes','excluded packages'),array('m','compile','zip','compile mode'),array('e','encrypt','encrypt mode'),array('ek','key','encrypt key'),array('es','sign','encrypt sign'),array('ex','extname','lua','encrypted file extension name (default is "lua"),only valID for xxtea_chunk'),array('c','config','load options from config file'),array('q','quIEt','quIEt'),array('jit','jit','using luajit compile framework'),); -h 帮助 -i 源码目录,input -o 输出文件或目录,output -p 包前缀 -x 不包括文件夹或文件,如果你有些源文件不想被编译进去的话,将会用到这个参数 -m 编译模式:zip(zip压缩格式)、files(离散文件) -e 加密模式:xxtea_zip(对zip包进行 xxtea 加密)、xxtea_chunk(对.luac 进行加密) -ek 加密密钥 -es 加密签名 -ex 编译后的文件的后缀名 -c 从一个文件加载参数列表 -q 生成过程不输出信息compile mode: -m zip (default) package all scripts bytecodes to a ZIP archive file. -m c package all scripts bytecodes to a C source file. -m files save bytecodes to separate files. -o specifIEs output dir.encrypt mode: -e xxtea_zip encrypt ZIP archive file with XXTEA algorithm,-e xxtea_chunk encrypt every bytecodes chunk with XXTEA algorithm. * default encrypt sign is "XXTEA" * output file extension name is "bytes"
修改AppDelegate.cpp
bool AppDelegate::applicationDIDFinishLaunching(){ ... //protofuf lua luaopen_protobuf_c(L); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("W@Z#X^^",strlen("W@Z#X^^"),"BJGAME",strlen("BJGAME")); string path = fileUtils::getInstance()->fullPathForfilename("src/main.lua"); cclOG("path ==%s",path.c_str()); size_t pos; while ((pos = path.find_first_of("\")) != std::string::npos) { path.replace(pos,"/"); } size_t p = path.find_last_of("/\"); if (p != path.npos) { const string dir = path.substr(0,p); stack->addSearchPath(dir.c_str()); p = dir.find_last_of("/\"); if (p != dir.npos) { stack->addSearchPath(dir.substr(0,p).c_str()); } } string env = "__LUA_STARTUP_file__=\""; env.append(path); env.append("\""); stack->executeString(env.c_str()); cclOG("------------------------------------------------"); cclOG("LOAD LUA file: %s",path.c_str()); cclOG("------------------------------------------------");//#ifdef DEBUG// engine->executeScriptfile(path.c_str());////#else// // stack->executeScriptfile(path.c_str());// stack->loadChunksFromZIP("res/sc/game.tg");// string script_main = "";// script_main += "require(\"main\")";// // cclOG("Boot script: \n%s",script_main.c_str());// engine->executeString(script_main.c_str());//// //#endif return true;}最后需要注意的是:编译发布程序的时候要记得把源代码文件夹从项目中移除(不是删除,只是不包含进项目里),不然一切都白费了 总结
以上是内存溢出为你收集整理的[cocos2dx_Lua]在发布时加密lua源文件全部内容,希望文章能够帮你解决[cocos2dx_Lua]在发布时加密lua源文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)