码迷,mamicode.com
首页 > 其他好文 > 详细

cocos lua 加密与解密 混淆 (版本cocos3.4)

时间:2015-03-19 14:50:11      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:cocos2dx   lua   

cocos luacompile

Overview

Compile the .lua files to .luac.

Usage

cocos luacompile [arguments]

Available Arguments

arg available value sample description necessary
-h, --help - - Show the help message and exit no
-s, --src source directory ./projects/MyLuaGame/src Specify source directory of lua files needed to be compiled. yes
-d, --dst destination directory ./projects/MyLuaGame/src Specify destination directory bytecode files to be stored. yes
-e, --encrypt - - Enable the encrypting of lua files. no
-k, --encryptkey any string MyLuaKey Specify the encrypt key for the encrypting of lua scripts. It‘s only take effect when-e, --encrypt is enabled. Default value is 2dxLua. no
-b, --encryptsign any string MyLuaSign Specify the encrypt sign for the encrypting of lua scripts. It‘s only take effect when--encrypt is enabled. Default value is XXTEA. no

Samples

  • cocos luacompile -h. Show the help message.
  • cocos luacompile -s ./projects/MyLuaGame/src -d ./projects/MyLuaGame/src -e -k MyLuaKey -b MyLuaSign
    Compile the *.lua in directory ./projects/MyLuaGame/src to*.luac. Then encrypt the luac files with key is MyLuaKey and sign isMyLuaSign.


我们在实验的过程中出现了一些问题,支持64位的解决方案:

cocos luacompile -s src/ -d out/ -e -k testKey123456 -b testSign123456 --disable-compile

下面给出全过程与测试工程


1.0 cocos luacompile 用法

技术分享

我用的普通的cocos2d lua,没用quick,quick好像可以对整个资源包括图像和音频都加密,打包成zip。但我没用quick.看了下luacompile 的 help,比较简单啊。

先在项目根目录下建立了一个out的文件夹,然后就用这个命令试了下:

cocos luacompile -s src/  -d out/

比预想的顺利,在out目录下看到了很多luac文件。正如命令里说的,支持子目录。网上说luac还是会被反编译。就加上了key。

cocos luacompile -s src/ -d out/ -e -k testKey123456 -b testSign123456

他用的是XXTEA加密算法,可以看这篇文章 《XXTEA 可逆加密解密算法 C++ C#兼容版本》

还需要在AppDelegate.cpp文件的 applicationDidFinishLaunching方法中加入setXXTEAKeyAndSign。这点它那个luacompile 的help就没提了,这是第一个坑。

LuaStack* stack = engine->getLuaStack();
    stack->setXXTEAKeyAndSign("testKey123456", strlen("testKey123456"), "testSign123456", strlen("testSign123456"));

    if (engine->executeScriptFile("src/main.lua")) {
        return false;

2.不支持64bit

第二个坑马上来了:刚开始在IPhone4S模拟器运行好好的,IPhone5s就漆黑一片了。原来这样把lua编译后,虽然速度变快了,但还未支持64位系统,据说cocos2d 年底会给出luajit 64位解决方案,因为苹果要求的啊。

然后因为这个问题我卡了一会儿。网上搜了了也没什么结果,都推荐使用Quick。游戏都写完了,转Quick有点麻烦。

突然注意到luacompile help中最后一个选项:–disable-compile ,然后把命令改成下面这种:

cocos luacompile -s src/ -d out/ -e -k testKey123456 -b testSign123456 --disable-compile


也是出来luac文件,但只是简单用XXTEA加密。这样小游戏完全够用了。



查阅效果图:
技术分享


技术分享


技术分享




cocos lua 加密与解密 混淆 (版本cocos3.4)

标签:cocos2dx   lua   

原文地址:http://blog.csdn.net/kaitiren/article/details/44457109

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!