[cocos2dx_Lua]在发布时加密lua源文件

前端之家收集整理的这篇文章主要介绍了[cocos2dx_Lua]在发布时加密lua源文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

加密shell脚本

  1. #!/bin/bash
  2. CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. CMP_PATH=$CURRENT_PATH/quick/bin
  4. SRC_PATH=$CURRENT_PATH/../src
  5. OUT_PATH=$CURRENT_PATH/../res/sc
  6. MYSIG="BJGAME"
  7. MYKEY="W@Z#X^^"
  8.  
  9. cd $CMP_PATH
  10. # ./compile_scripts.sh -i $SRC_PATH -x main,config,cocos,framework -o $OUT_PATH/game.tg -e xxtea_zip -es $MYSIG -ek $MYKEY
  11. #android的可能有问题
  12.  
  13. ./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引擎安装目录下

  1. $options = array(
  2. 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'),);
  3.  
  4. -h 帮助
  5. -i 源码目录,input
  6. -o 输出文件或目录,output
  7. -p 包前缀
  8. -x 包括文件夹或文件,如果你有些源文件不想被编译进去的话,将会用到这个参数
  9. -m 编译模式:zipzip压缩格式)、files(离散文件
  10. -e 加密模式:xxtea_zip(对zip包进行 xxtea 加密)、xxtea_chunk(对.luac 进行加密)
  11. -ek 加密密钥
  12. -es 加密签名
  13. -ex 编译后的文件的后缀名
  14. -c 从一个文件加载参数列表
  15. -q 生成过程不输出信息
  16.  
  17. compile mode:
  18. -m zip (default) package all scripts bytecodes to a ZIP archive file.
  19. -m c package all scripts bytecodes to a C source file.
  20. -m files save bytecodes to separate files. -o specifies output dir.
  21.  
  22. encrypt mode:
  23. -e xxtea_zip encrypt ZIP archive file with XXTEA algorithm,-e xxtea_chunk encrypt every bytecodes chunk with XXTEA algorithm.
  24. * default encrypt sign is "XXTEA"
  25. * output file extension name is "bytes"

修改AppDelegate.cpp
  1. bool AppDelegate::applicationDidFinishLaunching()
  2. {
  3. ...
  4. //protofuf lua
  5. luaopen_protobuf_c(L);
  6. LuaStack* stack = engine->getLuaStack();
  7. stack->setXXTEAKeyAndSign("W@Z#X^^",strlen("W@Z#X^^"),"BJGAME",strlen("BJGAME"));
  8. string path = FileUtils::getInstance()->fullPathForFilename("src/main.lua");
  9. CCLOG("path ==%s",path.c_str());
  10.  
  11. size_t pos;
  12. while ((pos = path.find_first_of("\\")) != std::string::npos)
  13. {
  14. path.replace(pos,"/");
  15. }
  16. size_t p = path.find_last_of("/\\");
  17. if (p != path.npos)
  18. {
  19. const string dir = path.substr(0,p);
  20.  
  21. stack->addSearchPath(dir.c_str());
  22. p = dir.find_last_of("/\\");
  23. if (p != dir.npos)
  24. {
  25. stack->addSearchPath(dir.substr(0,p).c_str());
  26. }
  27. }
  28. string env = "__LUA_STARTUP_FILE__=\"";
  29. env.append(path);
  30. env.append("\"");
  31. stack->executeString(env.c_str());
  32. CCLOG("------------------------------------------------");
  33. CCLOG("LOAD LUA FILE: %s",path.c_str());
  34. CCLOG("------------------------------------------------");
  35.  
  36. //#ifdef DEBUG
  37. //
  38. engine->executeScriptFile(path.c_str());
  39. //
  40. //#else
  41. // // stack->executeScriptFile(path.c_str());
  42. // stack->loadChunksFromZIP("res/sc/game.tg");
  43. // string script_main = "";
  44. // script_main += "require(\"main\")";
  45. // // CCLOG("Boot script: \n%s",script_main.c_str());
  46. // engine->executeString(script_main.c_str());
  47. //
  48. //
  49. //#endif
  50.  
  51. return true;
  52. }
最后需要注意的是:编译发布程序的时候要记得把源代码文件夹从项目中移除(不是删除,只是不包含进项目里),不然一切都白费了

猜你在找的Cocos2d-x相关文章