jsc和luac文件 xxtea 解密.

2019/10/14 09:05
阅读数 453
 1 # -*- coding: utf-8 -*- 
 2 import xxtea
 3 import os
 4 
 5 src = "./assets/src"
 6 dst = "./assets/srcd"
 7 
 8 xxtea_sign = ""
 9 xxtea_key = "fc9853c5-78f9-55"
10 xxtea_sign_len = len(xxtea_sign)
11 xxtea_key_len = len(xxtea_key)
12 
13 files = []
14 exts = [".luac",".jsc"]
15 
16 def deep_iterate_dir(rootDir):
17     for lists in os.listdir(rootDir):
18         path = os.path.join(rootDir, lists)
19         if os.path.isdir(path):
20            deep_iterate_dir(path)
21         elif os.path.isfile(path):
22             ext = os.path.splitext(path)[1]
23             if ext in exts:
24                 files.append(path)
25 
26 
27 # 处理一个文件
28 def handle_file(file):
29     with open(file,"rb") as fd:
30         con = fd.read()
31         c2 = xxtea.decrypt(con, xxtea_key,padding=False)
32         fd.close()
33         return c2
34 
35 # 保存文件
36 def save_file(file,outData):
37     dst_rootpath = os.path.split(file)[0]
38     try:
39         # print "creating dir (%s)" % (dst_rootpath)
40         os.makedirs(dst_rootpath)
41     except OSError:
42         if os.path.exists(dst_rootpath) == False:
43             # There was an error on creation, so make sure we know about it
44             raise Exception("Error: create directory %s failed." % dst_rootpath)
45 
46     if file.endswith("c"):
47         file = file[:-1]
48     with open(file,"wb") as fd:
49         con = fd.write(outData)
50         fd.close()
51 
52 # 获取绝对路径
53 def normalize_path(i):
54     tmp = os.path.normpath(i)
55     if not os.path.isabs(tmp):
56         tmp = os.path.abspath(tmp)
57     return tmp
58 
59 # 获取相对路径
60 def get_relative_path(luafile):
61     try:
62         pos = luafile.index(src)
63         return luafile[len(src)+1:]
64     except ValueError:
65         raise Exception("get_relative_path error")
66 
67 def handle_all_files():
68     for file in files:
69         con = handle_file(file)
70         if con:
71             path = os.path.join(dst,get_relative_path(file))
72             save_file(path,con)
73         else:
74             print ("handle %s file error" % file)
75 
76 def main():
77     global src
78     global dst
79     src = normalize_path(src)
80     dst = normalize_path(dst)
81 
82     if not os.path.exists(dst):
83         os.makedirs(dst)
84 
85     deep_iterate_dir(src)
86     handle_all_files()
87 
88 if __name__ == "__main__":
89     main()

 

展开阅读全文
def
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部
返回顶部
顶部