forked from RushRE/SonicRushAdventure-Decomp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.py
More file actions
134 lines (100 loc) · 4.05 KB
/
progress.py
File metadata and controls
134 lines (100 loc) · 4.05 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from dataclasses import dataclass
import re
import os
@dataclass
class Address:
addr: str
size: str
section: str
name: str
file: str
decompiled: bool
overlays = {
"unknown": [],
}
# read info from xmap file
def ReadXMAP(path):
with open("build/rush2.eu/arm9.elf.xMAP") as file:
region = "unknown"
for line in file:
split = line.strip()
if split.startswith("# ."):
region = split.replace("# .", "")
result = re.match(r"^([0-9A-Fa-f]*) ([0-9A-Fa-f]*) (\.[A-Za-z]*)\s*([A-Za-z0-9_]*)\s*\(([A-Za-z0-9_.]*)([^\)]*)\)", split)
if result:
info = Address(result.group(1), result.group(2), result.group(3), result.group(4), result.group(5), True)
if region not in overlays:
overlays[region] = []
overlays[region].append(info)
#parse any asm (.s) files and set the functions in there to be NOT decompiled
def ParseAsmFiles(includeLib = True):
rootdir = './'
if not includeLib:
rootdir = 'asm/'
for subdir, dirs, files in os.walk(rootdir):
for file in files:
path = os.path.join(subdir, file)
if not path.endswith(".s"):
continue
text = ""
with open(path, 'r') as file:
text = file.read()
for result in re.finditer(r"arm_func_start ([A-Za-z0-9_]*)", text):
labelName = result.group(1)
for key, value in overlays.items():
for i in range(len(value)):
if value[i].name == labelName:
overlays[key][i].decompiled = False
for result in re.finditer(r"thumb_func_start ([A-Za-z0-9_]*)", text):
labelName = result.group(1)
for key, value in overlays.items():
for i in range(len(value)):
if value[i].name == labelName:
overlays[key][i].decompiled = False
#parse any c (.c & .cpp) files and set the functions in there with the "NONMATCH_FUNC" macro to be NOT decompiled
def ParseCFiles(includeLib = True):
rootdir = './'
if not includeLib:
rootdir = 'src/'
for subdir, dir, files in os.walk(rootdir):
for file in files:
path = os.path.join(subdir, file)
if not path.endswith(".c") and not path.endswith(".cpp"):
continue
text = ""
with open(path, 'r') as file:
text = file.read()
for result in re.finditer(r"NONMATCH_FUNC [static ]*([A-Za-z0-9_]*)[*]* [*]*([A-Za-z0-9_]*)", text):
labelName = result.group(2)
for key, value in overlays.items():
for i in range(len(value)):
if value[i].name == labelName:
overlays[key][i].decompiled = False
def PrintProgress():
# calculate config
version = "eu"
includeLib = False # don't include libraries for now, just focus on the actual game logic!
ReadXMAP("build/rush2.{0}/arm9.elf.xMAP".format(version))
ParseAsmFiles(includeLib=includeLib)
ParseCFiles(includeLib=includeLib)
allSrcCount = 0
allTotalCount = 0
for key, value in overlays.items():
srcCount = 0
totalCount = 0
for info in value:
# for now, just count functions (labels in .text section)
if info.section != ".text":
continue
totalCount += 1
allTotalCount += 1
if info.decompiled:
srcCount += 1
allSrcCount += 1
if totalCount == 0:
continue
percent = (srcCount / totalCount) * 100
print("{0}: {1}/{2} => {3}%".format(key, srcCount, totalCount, "{:.2f}".format(percent)))
percent = (allSrcCount / allTotalCount) * 100
print("Total: {0}/{1} => {2}%".format(allSrcCount, allTotalCount, "{:.2f}".format(percent)))
PrintProgress()