Created
January 3, 2018 07:50
-
-
Save h080294/76ba74b71be652fb9a290dbf4a951a92 to your computer and use it in GitHub Desktop.
某手游lua文件加密脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
import io | |
import os | |
import base64 | |
import pyDes | |
import binascii | |
import sys | |
import crypto | |
import json | |
import zlib | |
sys.modules['Crypto']=crypto | |
from crypto.Cipher import AES | |
""" | |
lua脚本解密后,修改完成,用此脚本重新加密 | |
""" | |
def prepare(resouPath,inportPath): | |
key='\xe9\x74\x7d\x92\xcc\x32\x2e\x7d\x11\x2e\x7c\x34\x51\xd7\xb3\x6a' | |
with open(resouPath, 'rb') as inFile: | |
data = inFile.read() | |
inFile.close() | |
iv=data[0:16] | |
cryptor = AES.new(key,AES.MODE_CBC,iv) | |
with open(inportPath, 'rb') as inFile: | |
data = inFile.read() | |
inFile.close() | |
print "加密函数" | |
print "原文件大小:",len(data) | |
data = zlib.compress(data) | |
print "压缩后的文件大小:",len(data) | |
length = 16 | |
count = len(data) | |
add = length - (count % length) | |
print "需要补充的字节数",add | |
pads = chr(add) | |
print "pads转码值为", pads | |
for i in range(1, add+1): | |
data = data + pads | |
print "填补完成的的大小",len(data) | |
msg = iv+cryptor.encrypt(data) | |
return msg | |
if __name__ == '__main__': | |
resdir = r'/Users/johnhao/Downloads/4' # 源文件夹(直接解压游戏得到的lua加密脚本) | |
indir = r'/Users/johnhao/Downloads/1' # 输入文件夹(修改过的未加密的lua脚本) | |
outdir= r'/Users/johnhao/Downloads/2' # 输出文件夹(存放重新加密的lua脚本) | |
exstr='.lua' #输入文件的扩展名 | |
for path, subdirs, files in os.walk(indir): | |
for filename in files: | |
if filename.endswith(exstr): | |
infilename = path + os.sep + filename | |
size = os.path.getsize(infilename) | |
resouPath = resdir + infilename.replace(indir, '', 1) | |
inportPath = infilename | |
result=prepare(resouPath,inportPath) | |
outfilename = outdir + infilename.replace(indir, '', 1) | |
outPath,outFilename = os.path.split(outfilename) | |
print "outPath",outPath | |
print "outFilename",outFilename | |
if not os.path.exists(outPath): | |
os.makedirs(outPath) | |
with open(outfilename, 'wb') as outFile: | |
print "文件最终长度:", | |
print len(result) | |
outFile.write(result) | |
outFile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment