This repository has been archived by the owner on Sep 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
convertMap.py
101 lines (78 loc) · 2.88 KB
/
convertMap.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
# converts an IDA exported MAP to externals.txt for Kamek
# Example:
# 0001:802342C4 startPause__9RumbleMgrFv
# to
# startPause__9RumbleMgrFv=0x802342C4
import os, sys
if len(sys.argv) < 3:
print(f"Syntax: convertMap.py <inFile> <region>")
sys.exit()
if not os.path.exists(sys.argv[1]):
raise RuntimeError(f"Error: Input file {sys.argv[1]} not found.")
newFile = []
numSymbols = 0
discardedSymbols = 0
curLine = 0
isReadingVars = 0
with open(sys.argv[1], "r") as f:
data = f.readlines()
for line in data:
# IDA maps have 4 lines of stuff we do not care about
# so instead of constantly removing them manually, we get rid of them here.
if curLine < 4:
curLine += 1
continue
# so first we need to split it based on spaces
newLine = line.split(" ")
# now we get the line that has our address
if len(newLine) < 2:
continue
newerLine = newLine[1]
# now we get our address
if line.startswith("Program entry point at"):
continue
addressList = newerLine.split(":")
# now we get our actual address from the gotten data
lineAddress = addressList[1]
# strip some stuff we don't care about
symbol = newLine[-1].strip("\r\n")
# do not include nullsubs and def_addr symbols as well as j_ stubs
if symbol.find("nullsub") != -1 or symbol.find("def_") != -1 or symbol.find("j_") == 0:
discardedSymbols += 1
continue
# so IDA does not allow symbols to start with "sub__", even though some functions do have this name.
# so we replace "subtract__" with "sub__" here.
if symbol.find("subtract__") != -1:
# we get our right side, which is the class that holds this method
symbolHolder = symbol.split("__")
# now we create our symbol, with sub__ and our original class that had this method
symbol = f"sub__{symbolHolder[1]}"
# in order to support vtables and static class variables, we have to read a little more
# there are label names based off of strings, but we do not want these symbols
# so we check for __, which denotes a vtable / function
if isReadingVars:
if symbol.startswith("__vtbl__"):
symbol = f"__vt__{symbol[8:]}"
elif "__" in symbol:
pass
else:
discardedSymbols += 1
continue
# add our address to this list as well as add the symbol to it
newFile.append(f"{symbol}=0x{lineAddress}\n")
numSymbols += 1
# This symbol is the last function that we will have.
# after this function, we will seek out static variables and vtables
if symbol == "__DBEXIWriteRam":
isReadingVars = 1
continue
with open(f"symbols/{sys.argv[2]}.txt", "w") as f:
for line in newFile:
f.write(line)
# now we need to insert our external symbols, which are static variables that are in memory, but not the DOL
# this is to make some stuff easier
#with open("symbols/symbols-external-us.txt") as external:
# data = external.readlines()
#for line in data:
# f.write(line)
print(f"Done. Wrote {numSymbols} symbols, and discarded {discardedSymbols}.")