forked from ACreTeam/ac-decomp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_progress.py
47 lines (40 loc) · 1.61 KB
/
generate_progress.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
from argparse import ArgumentParser
import os.path
import pickle
import json
from typing import Dict, Tuple
import common as c
def load_progress_info(ctx: c.SourceContext, asm_list: str
) -> Tuple[Dict[str, int], Dict[str, int]]:
assert os.path.exists(ctx.labels), "Error: analysis has not ran!"
# Get data
raw = c.get_cmd_stdout(f"{c.PROGRESS} {ctx.binary} {ctx.labels} {ctx.slices}")
dat = json.loads(raw)
assert dat.get("version") == 2, "Outdated progress json version, try a clean & rebuild"
decomp_sizes = dat["decomp_slices_sizes"]
total_sizes = dat["total_sizes"]
symbol_sizes = dat["symbol_sizes"]
# Subtract undecompiled functions in decompiled slices
# TODO: this assumes none of .init is decompiled
with open(asm_list, 'rb') as f:
funcs = pickle.load(f)
for func in funcs:
decomp_sizes[".text"] -= symbol_sizes[str(func)]
return decomp_sizes, total_sizes
def generate_frogress_json(dol_size, dol_total, rel_size, rel_total):
return json.dumps({
"rel": {
"code": rel_size,
"code/total": rel_total
},
"dol": {
"code": dol_size,
"code/total": dol_total
}
})
if __name__=="__main__":
decomp_sizes, total_sizes = load_progress_info(c.DOL_CTX, c.DOL_ASM_LIST)
rel_decomp_sizes, rel_total_sizes = load_progress_info(c.REL_CTX, c.REL_ASM_LIST)
json_str = generate_frogress_json(decomp_sizes[".text"], total_sizes[".text"], rel_decomp_sizes[".text"], rel_total_sizes[".text"])
with open("out/progress.json", "w") as f:
f.write(json_str)