forked from pizdex/shi-kong-xing-shou
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: make util to print nearest symbol to address
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python3 | ||
import re | ||
import sys | ||
from lib.gbtool import * | ||
|
||
def get_relative_symbol(sym_table, address): | ||
relative = 0 | ||
while not (is_symbol_defined(sym_table, address)): | ||
address -= 1 | ||
relative += 1 | ||
if relative == 0: | ||
return get_symbol(sym_table, address) | ||
return '%s + %d' % (get_symbol(sym_table, address), relative) | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) < 2: | ||
print(f'{sys.argv[0]} address') | ||
print('\taddress can be in BB:AAAA form or as a hex number') | ||
exit(0) | ||
|
||
addr_str = lambda x: '%03x:%04x' % x | ||
|
||
# extract symbols | ||
with open('shi_kong_xing_shou.sym', 'r') as sym: | ||
string = sym.read() | ||
symbol = read_symbols(string) | ||
rom_sym = symbol['rom'] | ||
ram_sym = symbol['ram'] | ||
|
||
# get address | ||
s = sys.argv[1] | ||
s_= re.match('([0-9a-fA-F]+):([0-9a-fA-F]{4})$', s) | ||
if s_: | ||
start = addr2offset(*str2addr(s)) | ||
else: | ||
start = int(s, 16) | ||
|
||
print(get_relative_symbol(rom_sym, start)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters