forked from decompiler-explorer/decompiler-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecompile_dewolf.py
57 lines (44 loc) · 1.72 KB
/
decompile_dewolf.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
import os
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
DEWOLF_INSTALL = Path(os.getenv("DEWOLF_INSTALL_PATH", "/home/decompiler_user/dewolf"))
DEWOLF_DECOMPILE_PY = DEWOLF_INSTALL / 'decompile.py'
def main():
with tempfile.TemporaryDirectory() as tempdir:
conts = sys.stdin.buffer.read()
infile = tempfile.NamedTemporaryFile(dir=tempdir, delete=False)
infile.write(conts)
infile.flush()
os.mkdir(tempdir + '/output')
outfile = tempfile.NamedTemporaryFile(dir=tempdir + '/output', delete=False)
outfile.close()
decomp = subprocess.run(['pipenv', 'run', 'python', DEWOLF_DECOMPILE_PY, '-o', outfile.name, infile.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=str(DEWOLF_INSTALL))
if decomp.returncode != 0:
print(f'{decomp.stdout.decode()}\n{decomp.stderr.decode()}')
sys.exit(1)
infile.close()
with open(outfile.name, 'rb') as f:
sys.stdout.buffer.write(f.read())
def version():
p = subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0', 'HEAD'], cwd=str(DEWOLF_INSTALL))
ver = p.strip().decode()
if ver[0] == 'v':
ver = ver[1:]
print(ver)
p = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=str(DEWOLF_INSTALL))
hash = p.strip().decode()
print(hash)
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == '--name':
print('dewolf')
sys.exit(0)
if len(sys.argv) > 1 and sys.argv[1] == '--url':
print('https://github.com/fkie-cad/dewolf')
sys.exit(0)
if len(sys.argv) > 1 and sys.argv[1] == '--version':
version()
sys.exit(0)
main()