Merge pull request #118 from AntonioCastelli/tools

Added bidirectionality to get_symbol.
This commit is contained in:
David Benepe
2021-06-19 11:17:42 -05:00
committed by GitHub
2 changed files with 37 additions and 17 deletions
+6 -3
View File
@@ -30,7 +30,7 @@ Currently, only the US 1.0 version of the game is supported. US 1.1, EU 1.0, EU
## Modding
If you are modifying the code in the repo, then you should add `NON_MATCHING=1` to the make command.
Example: `make NON_MATCHING=1 -j4`
## Style Guide
@@ -69,14 +69,17 @@ Example: `./rename.sh D_A4001000 SP_IMEM`
---
#### `./get_symbol.sh <ram_address>`
#### `./get_symbol.sh <ram_address>|<symbol>`
Will return the symbol associated with the RAM address found in `/build/us_1.0/dkr.map`. The RAM address must be in base 16. The `0x` prefix is not required.
Given either a RAM address or symbol, returns its `(symbol, address)` pairing as defined in `/build/us_1.0/dkr.map`. If specified, the RAM address must be in base 16. The `0x` prefix is not required.
Example:
```
./get_symbol.sh 0xA4001000
0xA4001000 = SP_IMEM
./get_symbol.sh osCicId
0x80000310 = osCicId
```
---
+31 -14
View File
@@ -12,31 +12,48 @@ def main():
if len(sys.argv) != 2:
show_help()
return
print_symbol(int(sys.argv[1], 16))
symbol, address = find_pairing(sys.argv[1])
if symbol is None or address is None:
if is_address(sys.argv[1]):
print('No symbol was found for the address 0x%08X' % int(sys.argv[1], 16))
else:
print('No address was found for the symbol "%s"' % sys.argv[1])
else:
print('0x%08X = %s' % (address, symbol))
def print_symbol(ramAddress):
def find_pairing(sym_or_addr):
symbol = None
address = None
if is_address(sym_or_addr):
address = int(sym_or_addr, 16)
else:
symbol = sym_or_addr
try:
lines = FileUtil.get_text_from_file(SYMBOLS_TEXT_FILENAME).split('\n')
except:
print('Couldn\'t open file ' + SYMBOLS_TEXT_FILENAME)
return
foundSymbol = False
for line in lines:
matches = re.match(symbol_define_regex, line)
if matches is None:
continue
address = int(matches[1], 16)
if address == ramAddress:
symbol = matches[2]
print('0x%08X = %s' % (address, symbol))
foundSymbol = True
break
if not foundSymbol:
print('No symbol was found for the address "' + hex(ramAddress) + '"')
cur_addr = int(matches[1], 16)
cur_sym = matches[2]
if cur_addr == address:
return cur_sym, address
elif cur_sym == symbol:
return symbol, cur_addr
return None, None
def is_address(symbol):
try:
int(symbol, 16)
return True
except:
return False
def show_help():
print("Usage: ./get_symbol <RAM Address>")
print("Usage: ./get_symbol <RAM Address or symbol>")
##################################################################################