-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsymbols.py
38 lines (33 loc) · 1.16 KB
/
symbols.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
# Symbol Map: accessor for data in a dolphin format symbol map
class SymbolMap:
def __init__(self, path, cpp_macros):
self.names = {}
self.addresses = {}
if path is not None:
with open(path) as mapfile:
for line in mapfile.readlines():
# addr size addr2 section(?) name
splt = line.split()
if len(splt) == 0:
continue
if not splt[0][0] == '8':
continue
addr = int(splt[0], 16)
name = splt[4]
self.names[addr] = name
self.addresses[name] = addr
self.cpp_macros = cpp_macros
def has_name(self, addr):
return addr in self.names
def has_address(self, name):
return name in self.addresses
def get_name(self, addr):
if self.has_name(addr):
return self.names[addr]
else:
if self.cpp_macros:
return f"unk_{addr:x}"
else:
return hex(addr)
def get_address(self, name):
return self.addresses[name]