
正文
jsc和luac文件 xxtea 解密.
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
# -*- coding: utf-8 -*-
import xxtea
import os src = "./assets/src"
dst = "./assets/srcd" xxtea_sign = ""
xxtea_key = "fc9853c5-78f9-55"
xxtea_sign_len = len(xxtea_sign)
xxtea_key_len = len(xxtea_key) files = []
exts = [".luac",".jsc"] def deep_iterate_dir(rootDir):
for lists in os.listdir(rootDir):
path = os.path.join(rootDir, lists)
if os.path.isdir(path):
deep_iterate_dir(path)
elif os.path.isfile(path):
ext = os.path.splitext(path)[1]
if ext in exts:
files.append(path) # 处理一个文件
def handle_file(file):
with open(file,"rb") as fd:
con = fd.read()
c2 = xxtea.decrypt(con, xxtea_key,padding=False)
fd.close()
return c2 # 保存文件
def save_file(file,outData):
dst_rootpath = os.path.split(file)[0]
try:
# print "creating dir (%s)" % (dst_rootpath)
os.makedirs(dst_rootpath)
except OSError:
if os.path.exists(dst_rootpath) == False:
# There was an error on creation, so make sure we know about it
raise Exception("Error: create directory %s failed." % dst_rootpath) if file.endswith("c"):
file = file[:-1]
with open(file,"wb") as fd:
con = fd.write(outData)
fd.close() # 获取绝对路径
def normalize_path(i):
tmp = os.path.normpath(i)
if not os.path.isabs(tmp):
tmp = os.path.abspath(tmp)
return tmp # 获取相对路径
def get_relative_path(luafile):
try:
pos = luafile.index(src)
return luafile[len(src)+1:]
except ValueError:
raise Exception("get_relative_path error") def handle_all_files():
for file in files:
con = handle_file(file)
if con:
path = os.path.join(dst,get_relative_path(file))
save_file(path,con)
else:
print ("handle %s file error" % file) def main():
global src
global dst
src = normalize_path(src)
dst = normalize_path(dst) if not os.path.exists(dst):
os.makedirs(dst) deep_iterate_dir(src)
handle_all_files() if __name__ == "__main__":
main()





