-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecompyle_3.py
61 lines (57 loc) · 1.71 KB
/
decompyle_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import sys,os,traceback
import decompyle3.bin.decompile as decompiler
__version__='2.0.1'
def run_uncompile(filename):
# 截获sys.stderr中的警告和错误消息
message=""
_write=sys.stderr.write
def write(text,*arg,**kw):
nonlocal message
message+=text # 截获消息
#_write(text,*arg,**kw)
def start_capture(): # 开始监测,修改sys.stderr.write方法
sys.stderr.write=write
def end_capture(): # 停止监测
sys.stderr.write=_write
tofilename=filename[:-1]
try:
sys.stdout=open(tofilename,"w",encoding="utf-8") # 替换sys.stdout
sys.argv[1]=filename
start_capture()
try:decompiler.main_bin() # 运行反编译
except SystemExit:
pass
except KeyboardInterrupt:
end_capture()
return 3
except Exception:
end_capture()
traceback.print_exc(file=sys.stdout)
return 2
else:
end_capture()
if not message:
return 0
else:
sys.stdout.write(message)
return 1
finally:
sys.stdout.close()
if __name__=="__main__":
try:
if len(sys.argv)>1:
files=sys.argv[1:]
sys.argv[0]=decompiler.__file__
sys.argv[1:]=['']
retcodes=[]
for file in files:
retcodes.append(run_uncompile(file))
retcode=max(retcodes) # 取最严重的错误
else:
file=input("拖曳文件到本窗口,然后按回车:\n").strip('"')
sys.argv[0]=decompiler.__file__
sys.argv.append('')
retcode=run_uncompile(file)
finally:
sys.stdout=sys.__stdout__
sys.exit(retcode)