cocos2dx lua 加密

前端之家收集整理的这篇文章主要介绍了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. @H_403_108@defWriteFile(filePath,all_the_text):
  8. 'wb')
  9. file_object.write(all_the_text)
  10. @H_403_108@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. @H_403_108@forroot,dirs,filesinos.walk(path):
  16. foreachfilesinfiles:
  17. @H_403_108@ifeachfiles[-4:]=='.lua':
  18. fileList.append(root+'/'+eachfiles)
  19. @H_403_108@returnfileList
  20. defEncodeWithXxteaModule(filePath,key,signment):
  21. all_the_text=ReadFile(filePath)
  22. @H_403_108@ifall_the_text[:len(signment)]==signment: @H_403_108@return
  23. #baklua
  24. 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)
  25. signment=signment+encrypt
  26. WriteFile(filePath,signment)
  27. defEncodeLua(projectPath,248)"> path=projectPath+'/src'
  28. fileList=ListLua(path)
  29. forfilesinfileList:
  30. EncodeWithXxteaModule(files,153); font-weight:bold; background-color:inherit">defFixCpp(projectPath,248)"> filePath=projectPath+'/frameworks/runtime-src/Classes/AppDelegate.cpp'
  31. all_the_text=ReadFile(filePath)
  32. #bakcpp
  33. BakFile(filePath,all_the_text)
  34. pos=all_the_text.find('stack->setXXTEAKeyAndSign')
  35. left=all_the_text.find('(',pos)
  36. right=all_the_text.find(';',pos)
  37. word=str.format('("%s",strlen("%s"),"%s",strlen("%s"))'%(key,signment))
  38. all_the_text=all_the_text[:left]+word+all_the_text[right:-1]
  39. projectPath="D:/cocosIDEWork/aseGame/"
  40. key="123"
  41. signment="cloud"
  42. EncodeLua(projectPath,signment)
  43. 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/340748.html

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