diff --git a/README.md b/README.md index 28b27f48..982b3420 100755 --- a/README.md +++ b/README.md @@ -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 ` +#### `./get_symbol.sh |` -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 ``` --- diff --git a/tools/python/get_symbol.py b/tools/python/get_symbol.py index 78c99edd..b8d60469 100644 --- a/tools/python/get_symbol.py +++ b/tools/python/get_symbol.py @@ -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 ") + print("Usage: ./get_symbol ") ##################################################################################