forked from decompiler-explorer/decompiler-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecompile_relyze.py
86 lines (66 loc) · 2.1 KB
/
decompile_relyze.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import re
import os
import subprocess
import sys
from pathlib import Path
RELYZE_INSTALL = Path(os.getenv("RELYZE_INSTALL_PATH", "/home/decompiler_user/RelyzeDesktop/app"))
RELYZE_CLI = RELYZE_INSTALL / 'RelyzeCLI.exe'
def relyze_cli_run(params):
if not RELYZE_CLI.is_file():
return False, f'\'{RELYZE_CLI.name}\' not found.'
logfile = Path('log.tmp')
cli = subprocess.run(['wine64', str(RELYZE_CLI), '/output', logfile.name] + params, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
logdata = ''
if logfile.is_file():
with open(logfile.name, 'r', encoding='utf-16-le') as f:
logdata = f.read()
os.remove(logfile.name)
if cli.returncode != 0:
return False, f'{logdata}\n{cli.stdout.decode()}'
return True, logdata
def main():
infile = Path('in.tmp')
outfile = Path('out.tmp')
with open(infile.name, 'wb') as f:
f.write(sys.stdin.buffer.read())
func_timeout = int(os.getenv('DECOMPILER_FUNC_TIMEOUT', 15))
success, res = relyze_cli_run([
'/run',
'/plugin',
'decompiler_explorer.rb',
'/plugin_commandline',
f'/in={infile.name} /out={outfile.name} /func_timeout={func_timeout}'
])
os.remove(infile.name)
if not success:
print(res)
os.remove(outfile.name)
return 1
if outfile.is_file():
with open(outfile.name, 'r') as f:
print(f.read())
os.remove(outfile.name)
else:
print('no output file.')
return 1
return 0
def version():
success, ver = relyze_cli_run(['/version'])
if not success:
return 1
match = re.findall(r'\s(\d+\.\d+\.\d+)\s', ver)
if len(match) == 0:
return 1
print(match[0])
print()
return 0
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == '--name':
print('Relyze')
sys.exit(0)
if len(sys.argv) > 1 and sys.argv[1] == '--url':
print('https://www.relyze.com/')
sys.exit(0)
if len(sys.argv) > 1 and sys.argv[1] == '--version':
sys.exit(version())
sys.exit(main())