-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcorrect_internal_entrypoint.py
executable file
·49 lines (39 loc) · 1.31 KB
/
correct_internal_entrypoint.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
#!/usr/bin/env python3
import sys
import os
import glob
def process_file(fname):
func_name = None
with open(fname) as f:
l = f.readline()
if not l.startswith("; Entry point: "):
return
l = l.strip()
head, func_name = l.rsplit(None, 1)
assert func_name
print("Processing:", fname)
os.rename(fname, fname + ".bak")
with open(fname + ".bak") as f, open(fname, "w") as f_out:
l = f.readline()
assert l[0] == ";"
# Don't write this line
l = f.readline()
addr, rest = l.split(None, 1)
f_out.write("%s.0 %s:\n" % (addr, func_name))
f_out.write("%s.0 goto %s.0\n" % (addr, func_name))
f_out.write(l)
for l in f:
addr, label = l.split(None, 1)
label = label.strip()
if label[-1] == ":" and not label.startswith("loc_"):
this_name = label[:-1]
if func_name == this_name:
l = l.replace(func_name, func_name + ".0")
f_out.write(l)
if __name__ == "__main__":
if os.path.isdir(sys.argv[1]):
for full_name in glob.glob(sys.argv[1] + "/*"):
if full_name.endswith(".lst") and os.path.isfile(full_name):
process_file(full_name)
else:
process_file(sys.argv[1])