-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_single_script_extraction.py
36 lines (26 loc) · 1.19 KB
/
run_single_script_extraction.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
import argparse
from tonguetwister.file_disassembler import FileDisassembler
from tonguetwister.lingo_decompiler import Decompiler
def main(filepath, script_number, function_number):
# Unpack a cst file
parser = FileDisassembler()
parser.load_file(filepath)
parser.unpack()
# Extract a specific lingo script
script = list(parser.lingo_scripts.items())[script_number][1]
namelist = parser.namelist
function = script.functions[function_number]
# Decompile the lingo script
decompiler = Decompiler()
decompiler.to_pseudo_code(function, namelist, script)
for line in decompiler.generated_code:
print(line)
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('filepath', type=str, help='A director data file path, e.g. link/to/folder/data.cst')
parser.add_argument('script_number', metavar='script-number', type=int, help='The script number to decompile')
parser.add_argument('function_number', metavar='function-number', type=int, help='The function number to decompile')
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
main(args.filepath, args.script_number, args.function_number)