forked from NoxTools/noxscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnsdc.py
More file actions
executable file
·45 lines (38 loc) · 1.48 KB
/
nsdc.py
File metadata and controls
executable file
·45 lines (38 loc) · 1.48 KB
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
#!/usr/bin/env python
import click
import pyparsing
import os
import colorama
import subprocess
from noxscript.decompiler import Decompiler
# increase the recursion limit
import sys
sys.setrecursionlimit(5000)
@click.command(context_settings={'help_option_names': ['-h', '--help']})
@click.argument('scrobj', type=click.File('rb'))
@click.option('--out', '-o', default=None, help='Output file path.')
@click.option('--analyze/--no-analyze', default=True, help='Perform structural analysis.')
@click.option('--object-type/--no-object-type', default=True, help='Use object type.')
@click.option('--pprint/--no-pprint', default=True, help='Run astyle on output.')
@click.option('--verbose', '-v', is_flag=True, help='Verbose mode. Prints AST.')
def cli(scrobj, out, analyze, object_type, pprint, verbose):
'''
NoxScript 3.0 Decompiler - By Andrew Wesie (zoaedk) and Brian Pak (cai)
'''
try:
try:
d = Decompiler(scrobj, object_type=object_type, struct_analysis=analyze)
except Exception as e:
click.secho('Error: %s' % e, fg='red')
return
if out is None:
out = './%s.ns' % (os.path.splitext(os.path.basename(scrobj.name))[0])
if verbose:
d.print_ast()
d.unparse(out)
if pprint:
subprocess.check_call(['astyle', '--mode=c', '--style=break', '-Y', '-j', '-q', '-n', out])
except Exception as e:
click.secho('Error: %s' % e, fg='red')
if __name__ == '__main__':
cli()