[Cocos2dx]cocos luacompile命令加密lua檔案
阿新 • • 發佈:2018-11-20
用法介紹
命令cocos luacompile --h檢視用法
usage: cocos luacompile [-h] [-v] [-s SRC_DIR_ARR] [-d DST_DIR] [-e] [-k ENCRYPTKEY] [-b ENCRYPTSIGN] [--disable-compile] 對 lua 檔案進行加密和編譯為位元組碼的處理。 optional arguments: -h, --help show this help message and exit -v, --verbose 更多輸出資訊。 -s SRC_DIR_ARR, --src SRC_DIR_ARR 指定需要編譯的 lua 檔案路徑,支援指定多個路徑。 -d DST_DIR, --dst DST_DIR 指定輸出檔案的路徑。 -e, --encrypt 開啟 XXTEA 加密功能。 -k ENCRYPTKEY, --encryptkey ENCRYPTKEY 指定 XXTEA 加密功能的 key 欄位。 -b ENCRYPTSIGN, --encryptsign ENCRYPTSIGN 指定 XXTEA 加密功能的 sign 欄位。 --disable-compile 關閉編譯為位元組碼的功能。
用法
luacompile.sh加密指令碼檔案
luacompile.sh加密指令碼檔案
PWD=`pwd`
COCOS='/Applications/Cocos2d-x/cocos2d-x-3.10/tools/cocos2d-console/bin/cocos'
rm -rf src_et
${COCOS} luacompile -s src -d src_et -e -k kBJMRK -b sTAMX --disable-compile
執行指令碼命令輸出:
通過 luacompile 命令對 lua 檔案進行 XXTEA 加密以及編譯為位元組碼的處理。 編譯為位元組碼的功能基於 LuaJIT v2.0.3,所以目前編譯成位元組碼的檔案不適用於 iOS 64位裝置。 正在處理 lua 檔案。 編譯完成。
把src資料夾下的.lua檔案加密到src_et資料夾下的.luac檔案
程式碼解密
bool AppDelegate::applicationDidFinishLaunching() { ... // set default FPS Director::getInstance()->setAnimationInterval(1.0 / 60.0f); // register lua module auto engine = LuaEngine::getInstance(); ScriptEngineManager::getInstance()->setScriptEngine(engine); LuaStack* stack = engine->getLuaStack(); stack->setXXTEAKeyAndSign("kBJMRK", strlen("kBJMRK"), "sTAMX", strlen("sTAMX")); ... #if COCOS2D_DEBUG if (engine->executeString("require('src/main')")) #else if (engine->executeString("require('src_et/main')")) #endif { return false; } #endif return true; }