cocos2dx lua 加密

cocos2dx lua 加密,第1张

概述cocos2dx lua已经集成了对lua脚本的加解密,见AppDelegate.cpp. [cpp]  view plain copy LuaStack* stack = engine->getLuaStack();   stack->setXXTEAKeyAndSign("123", strlen("123"), "cloud", strlen("cloud"));   它是通过XXTEA来加 cocos2dx lua已经集成了对lua脚本的加解密,见AppDelegate.cpp. [cpp] view plain copy LuaStack*stack=engine->getLuaStack(); stack->setXXTEAKeyAndSign("123",strlen("123"),"cloud",strlen("cloud")); 它是通过XXTEA来加解密的。参数,key,keyLen,signment,signmentLen。它的签名作用可能是用来判断文件是否经过加密的。 好,我们来对文件加密。打开cocos2d-x\external\xxtea文件夹,调用相关函数xxtea_encrypt进行加密,最后在文件开始位置,写上签名就可以了。我把相关 *** 作封装成一个python文件。可以直接调用。 [python] importxxteaModule importos defReadfile(filePath): file_object=open(filePath,'rb') all_the_text=file_object.read() file_object.close() returnall_the_text defWritefile(filePath,all_the_text): 'wb') file_object.write(all_the_text) defBakfile(filePath,all_the_text): file_bak=filePath[:len(filePath)-3]+'bak' Writefile(file_bak,all_the_text) defListLua(path): fileList=[] forroot,dirs,filesinos.walk(path): foreachfilesinfiles: ifeachfiles[-4:]=='.lua': fileList.append(root+'/'+eachfiles) returnfileList defEncodeWithXxteaModule(filePath,key,signment): all_the_text=Readfile(filePath) ifall_the_text[:len(signment)]==signment: return #baklua Bakfile(filePath,108); List-style:decimal-leading-zero outsIDe; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> encrypt=xxteaModule.encrypt(all_the_text,key) signment=signment+encrypt Writefile(filePath,signment) defEncodeLua(projectPath,248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> path=projectPath+'/src' fileList=ListLua(path) forfilesinfileList: EncodeWithXxteaModule(files,153); background-color:inherit; Font-weight:bold">defFixCpp(projectPath,248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> filePath=projectPath+'/frameworks/runtime-src/Classes/AppDelegate.cpp' all_the_text=Readfile(filePath) #bakcpp Bakfile(filePath,all_the_text) pos=all_the_text.find('stack->setXXTEAKeyAndSign') left=all_the_text.find('(',pos) right=all_the_text.find(';',pos) word=str.format('("%s",strlen("%s"),"%s",strlen("%s"))'%(key,signment)) all_the_text=all_the_text[:left]+word+all_the_text[right:-1] projectPath="D:/cocosIDEWork/aseGame/" key="123" signment="cloud" EncodeLua(projectPath,signment) FixCpp(projectPath,153); background-color:inherit; Font-weight:bold">print"encodeok"
整个工程是用cocosIDE生成的。这个工具会自动加密src下的lua,并在 AppDelegate.cpp中设置相应的密码与签名。xxTeaModule是对cocos2d-x\external\xxtea\xxtea.cpp的一个python封装。 相关工具我已打包上传,见地址:http://download.csdn.net/detail/cloud95/7675821
转载:http://blog.csdn.net/cloud95/article/details/38110009 总结

以上是内存溢出为你收集整理的cocos2dx lua 加密全部内容,希望文章能够帮你解决cocos2dx lua 加密所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1067344.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存