forked from shinyquagsire23/OpenJKDF2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyze.py
289 lines (221 loc) · 9.29 KB
/
analyze.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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
funclist = open("ida_copypaste_funclist_nostdlib.txt", "r").read().split("\n")
wontimpl_funclist = open("wontimpl.txt", "r").read().split("\n")
funclist_noxref = open("noxrefs.txt").read().split("\n")
exclude_filefrom = ["nullsub", "menu", "init", "show", "gdi", "get", "cheat", "msgbox", "DialogFunc", "devcmd", "do", "idk", "wm", "WinIdk", "util", "cheats", "draw", "thing", "j", "sub", "daRealloc", "daFree", "daAlloc", "WinMain(x,x,x,x)", "WinCalibrateJoystick"]
filefrom_subsys = ["sith", "stdPlatform", "std", "jkGui", "rd", "jk", "Raster", "other"]
file_sizes = {}
decomped_sizes = {}
decomped_funcs = {}
total_funcs = {}
total_size = 0
total_numFuncs = 0
total_numFuncsNoRaster = 0
total_decompFuncs = 0
total_raster = 0
total_bySubsys = {}
total_decomp_bySubsys = {}
total_notdecomp_bySubsys = {}
total_decomp_funcs_bySubsys = {}
total_notdecomp_funcs_bySubsys = {}
total_funcs_bySubsys = {}
for subsys in filefrom_subsys:
total_bySubsys[subsys] = 0
total_funcs_bySubsys[subsys] = 0
total_decomp_funcs_bySubsys[subsys] = 0
total_notdecomp_funcs_bySubsys[subsys] = 0
total_decomp_bySubsys[subsys] = 0
total_notdecomp_bySubsys[subsys] = 0
mapread = open("build_hooks/output.map", "r").read().split("\n")
decompiled_funcs = []
foundFuncs = False
for line in mapread:
if ("SIZEOF_HEADERS" not in line and not foundFuncs):
continue
if (not foundFuncs and "SIZEOF_HEADERS" in line):
foundFuncs = True
if (".data" in line):
break
if (".text" in line):
continue
split = line.split(" ")
funcname = split[len(split)-1]
if ("(" in funcname or "*" in funcname or "0x" in funcname or "." in funcname):
continue
if funcname == "":
continue
filefrom = funcname.split("_")[0]
if (len(funcname.split("_")) < 2 and filefrom[:2] == "rd"):
filefrom = "rdroid"
if (len(funcname.split("_")) < 2 and filefrom[:3] == "std"):
filefrom = "stdPlatform"
if "_" not in funcname and funcname.startswith("sith"):
filefrom = "sith"
is_excluded = False
for exclude in exclude_filefrom:
if (filefrom == exclude) or filefrom == "":
is_excluded = True
break
'''if funcname in funclist_noxref:
print (funcname)
is_excluded = True'''
if is_excluded:
continue
decompiled_funcs += [funcname]
decompiled_funcs = list(decompiled_funcs)
for line in funclist:
split = line.split("\t")
if (len(split) < 3):
continue
funcname = split[0]
sect = split[1]
start = int(split[2], 16)
size = int(split[3], 16)
if funcname == "":
continue
filefrom = funcname.split("_")[0]
if (len(funcname.split("_")) < 2 and filefrom[:2] == "rd"):
filefrom = "rdroid"
if (len(funcname.split("_")) < 2 and filefrom[:3] == "std"):
filefrom = "stdPlatform"
if "_" not in funcname and funcname.startswith("sith"):
filefrom = "sith"
is_excluded = False
for exclude in exclude_filefrom:
if (filefrom == exclude) or filefrom == "":
is_excluded = True
break
# if funcname in funclist_noxref:
# is_excluded = True
if is_excluded:
continue
# if ("Raster" in filefrom):
# continue
if filefrom not in file_sizes:
file_sizes[filefrom] = size
else:
file_sizes[filefrom] += size
if filefrom not in decomped_sizes:
decomped_sizes[filefrom] = 0
if filefrom not in decomped_funcs:
decomped_funcs[filefrom] = 0
total_funcs[filefrom] = 0
#if funcname not in decompiled_funcs:
# print (funcname, filefrom)
found_func_subsys = False
subsys_ident = "other"
for subsys in filefrom_subsys:
if filefrom.startswith(subsys):
found_func_subsys = True
if subsys == "rd" and "Raster" in filefrom:
subsys = "Raster"
subsys_ident = subsys
break
#if not found_func_subsys:
#print (filefrom, subsys_ident)
# Uncomment to see missing funcs
#if subsys != "Raster" and funcname not in decompiled_funcs and funcname not in wontimpl_funclist:
# print (funcname)
if funcname not in decompiled_funcs and funcname not in wontimpl_funclist:
total_notdecomp_bySubsys[subsys_ident] += size
total_notdecomp_funcs_bySubsys[subsys_ident] += 1
else:
total_decomp_bySubsys[subsys_ident] += size
total_decomp_funcs_bySubsys[subsys_ident] += 1
total_bySubsys[subsys_ident] += size
total_funcs_bySubsys[subsys_ident] += 1
if funcname in decompiled_funcs or funcname in wontimpl_funclist:
#print (funcname, filefrom)
decomped_sizes[filefrom] += size
decomped_funcs[filefrom] += 1
total_funcs[filefrom] += 1
total_size += size
total_numFuncs += 1
if subsys_ident == "Raster":
total_raster += size
else:
total_numFuncsNoRaster += 1
#print (filefrom, funcname, sect, start, size)
total_decomp = 0
print ("[file]".ljust(30), "[size]".ljust(10), "[% of text]".ljust(13), "[% complete]".ljust(13), "[decomp / total]".ljust(17))
# 100% functions
for keyvalpair in sorted(file_sizes.items(), key=lambda item: item[1]):
decomp_size = decomped_sizes[keyvalpair[0]]
decomp_percent_num = (decomp_size/total_size)
comp_percent_num = keyvalpair[1]/total_size
if (decomp_percent_num/comp_percent_num < 1.0):
continue
total_decomp += decomp_size
comp_percent = '{:.3%}'.format(comp_percent_num)
decomp_percent = '{:.3%}'.format(decomp_percent_num/comp_percent_num)
decomp_fraction = str(decomped_funcs[keyvalpair[0]]).rjust(3) + " / " + str(total_funcs[keyvalpair[0]])
total_decompFuncs += decomped_funcs[keyvalpair[0]]
#total_numFuncs += total_funcs[keyvalpair[0]]
print (keyvalpair[0].ljust(30), hex(keyvalpair[1]).ljust(10), comp_percent.ljust(13), decomp_percent.ljust(13), decomp_fraction.ljust(17))
# Not-100% functions
for keyvalpair in sorted(file_sizes.items(), key=lambda item: item[1]):
decomp_size = decomped_sizes[keyvalpair[0]]
decomp_percent_num = (decomp_size/total_size)
comp_percent_num = keyvalpair[1]/total_size
if (decomp_percent_num/comp_percent_num >= 1.0):
continue
total_decomp += decomp_size
comp_percent = '{:.3%}'.format(comp_percent_num)
decomp_percent = '{:.3%}'.format(decomp_percent_num/comp_percent_num)
decomp_fraction = str(decomped_funcs[keyvalpair[0]]).rjust(3) + " / " + str(total_funcs[keyvalpair[0]])
total_decompFuncs += decomped_funcs[keyvalpair[0]]
#total_numFuncs += total_funcs[keyvalpair[0]]
print (keyvalpair[0].ljust(30), hex(keyvalpair[1]).ljust(10), comp_percent.ljust(13), decomp_percent.ljust(13), decomp_fraction.ljust(17))
def percent_str(val, total):
return '{:.3%}'.format(val/total)
def frac_str(val, val2):
return str(val).rjust(4) + " / " + str(val2)
def decomp_totalPercent(val):
return percent_str(val, total_size)
def decomp_totalPercent_noraster(val):
return percent_str(val, total_size - total_raster)
print ("---------------------------------------------------------------------------------\n")
print ("Total completion:")
print ("-----------------")
print (decomp_totalPercent(total_decomp) + " by weight")
print (decomp_totalPercent_noraster(total_decomp) + " by weight excluding rasterizer")
print (str(total_decompFuncs) + " / " + str(total_numFuncs) + " functions")
print (str(total_decompFuncs) + " / " + str(total_numFuncsNoRaster) + " functions excluding rasterizer")
print ("")
print ("Subsystem Breakdown (Not Decomp'd)")
print ("----------------------------------")
totalAll = 0
totalFuncsAll = 0
numFuncsAll = 0
print ("[subsys]".ljust(15) + "[% of text]".ljust(13) + "[TODO / total]")
for subsys in filefrom_subsys:
subsys_total = total_bySubsys[subsys]
subsys_numFuncs = total_funcs_bySubsys[subsys]
total = total_notdecomp_bySubsys[subsys]
numFuncs = total_notdecomp_funcs_bySubsys[subsys]
totalAll += total
totalFuncsAll += numFuncs
numFuncsAll += subsys_numFuncs
print (subsys.ljust(15) + decomp_totalPercent(total).ljust(15) + frac_str(numFuncs, subsys_numFuncs))
print ("-----------------------------------------")
print ("total".ljust(15) + decomp_totalPercent(totalAll).ljust(15) + frac_str(totalFuncsAll, numFuncsAll))
print ("")
print ("Subsystem Breakdown (Not Decomp'd, Excl Raster)")
print ("-----------------------------------------------")
totalAll = 0
totalFuncsAll = 0
numFuncsAll = 0
print ("[subsys]".ljust(15) + "[% of text]".ljust(13) + "[TODO / total]")
for subsys in filefrom_subsys:
if subsys == "Raster":
continue
subsys_total = total_bySubsys[subsys]
subsys_numFuncs = total_funcs_bySubsys[subsys]
total = total_notdecomp_bySubsys[subsys]
numFuncs = total_notdecomp_funcs_bySubsys[subsys]
totalAll += total
totalFuncsAll += numFuncs
numFuncsAll += subsys_numFuncs
print (subsys.ljust(15) + decomp_totalPercent_noraster(total).ljust(15) + frac_str(numFuncs, subsys_numFuncs))
print ("-----------------------------------------")
print ("total".ljust(15) + decomp_totalPercent_noraster(totalAll).ljust(15) + frac_str(totalFuncsAll, numFuncsAll))
print ("")