Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了cocos2dx lua 加密大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
cocos2dx lua已经集成了对lua脚本的加解密,见AppDelegate.cpp.
  1. LuaStack*stack=ENGIne->getLuaStack();
  2. stack->setXXTEAKeyAndSign("123",strlen("123"),"cloud",strlen("cloud"));
它是通过XXTEA来加解密的。参数,key,keyLen,signment,signmentLen。它的签名作用可能是用来判断文件是否经过加密的。
好,我们来对文件加密。打开cocos2d-x\external\xxtea文件夹,调用相关函数xxtea_encrypt进行加密,最后在文件开始位置,写上签名就可以了。我把相关操作封装成一个python文件。可以直接调用。
[python]
    importxxteaModule
  1. importos
  2. defReadFile(filePath):
  3. file_object=open(filePath,'rb')
  4. all_the_text=file_object.read()
  5. file_object.close()
  6. returnall_the_text
  7. defWriteFile(filePath,all_the_text):
  8. :rgb(108,'wb')
  9. file_object.write(all_the_text)
  10. defBakFile(filePath,all_the_text):
  11. file_bak=filePath[:len(filePath)-3]+'bak'
  12. WriteFile(file_bak,all_the_text)
  13. defListLua(path):
  14. fileList=[]
  15. forroot,dirs,filesinos.walk(path):
  16. foreachfilesinfiles:
  17. ifeachfiles[-4:]=='.lua':
  18. fileList.append(root+'/'+eachfiles)
  19. returnfileList
  20. defEncodeWithXxteaModule(filePath,key,signment):
  21. all_the_text=ReadFile(filePath)
  22. ifall_the_text[:len(signment)]==signment:
  23. return
  24. #baklua
  25. 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)
  26. signment=signment+encrypt
  27. WriteFile(filePath,signment)
  28. defEncodeLua(projectPath,248)"> path=projectPath+'/src'
  29. fileList=ListLua(path)
  30. forfilesinfileList:
  31. EncodeWithXxteaModule(files,153); font-weight:bold; BACkground-color:inherit">defFixCpp(projectPath,248)"> filePath=projectPath+'/frameworks/runtime-src/Classes/AppDelegate.cpp'
  32. all_the_text=ReadFile(filePath)
  33. #bakcpp
  34. BakFile(filePath,all_the_text)
  35. pos=all_the_text.find('stack->setXXTEAKeyAndSign')
  36. left=all_the_text.find('(',pos)
  37. right=all_the_text.find(';',pos)
  38. word=str.format('("%s",strlen("%s"),"%s",strlen("%s"))'%(key,signment))
  39. all_the_text=all_the_text[:left]+word+all_the_text[right:-1]
  40. projectPath="D:/cocosIDEWork/aseGame/"
  41. key="123"
  42. signment="cloud"
  43. EncodeLua(projectPath,signment)
  44. FixCpp(projectPath,153); font-weight:bold; BACkground-color:inherit">print"encodeok"

整个工程是用cocosIDE生成的。这个工具会自动加密src下的lua,并在 AppDelegate.cpp中设置相应的密码与签名。xxTeaModule是对cocos2d-x\external\xxtea\xxtea.cpp的一个python封装。
相关工具我已打包上传,见地址:http://download.csdn.net/detail/cloud95/7675821

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
猜你在找的Cocos2d-x相关文章