|
| 1 | +""" |
| 2 | +copies mapped symbols from objdiff.json to symbols.txt |
| 3 | +
|
| 4 | +objdiff allows one to map symbols from the programmer's decompiled binary to the original target binary. |
| 5 | +this script will find those mapped symbols, and write the programmer's updated names to `symbols.txt`. |
| 6 | +
|
| 7 | +example: say you have changed the signature/name of a function from foo(short) -> bar(long). |
| 8 | +now, the symbol from your new object is `bar__Fl`, but symbols.txt still says `foo__Fs`. |
| 9 | +objdiff allows you to map `bar__Fl` in your new object to `foo__Fs` in the target object. |
| 10 | +this script will automatically replace `foo__Fs` with `bar__Fl` in `symbols.txt`. |
| 11 | +""" |
| 12 | + |
| 13 | +import json |
| 14 | + |
| 15 | +with open("./objdiff.json") as f: |
| 16 | + objdiff_config = json.load(f) |
| 17 | + |
| 18 | +units = objdiff_config["units"] |
| 19 | + |
| 20 | +symbol_mappings = {} |
| 21 | +for unit in units: |
| 22 | + symbol_mapping = unit.get("symbol_mappings") |
| 23 | + if symbol_mapping is None: |
| 24 | + continue |
| 25 | + symbol_mappings.update(symbol_mapping) |
| 26 | + del unit['symbol_mappings'] |
| 27 | + |
| 28 | + |
| 29 | +def process_symbols_txt(symbols_txt_path): |
| 30 | + with open(symbols_txt_path) as f: |
| 31 | + symbols = f.readlines() |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + for i, line in enumerate(symbols): |
| 36 | + tokens = line.split() |
| 37 | + old_symbol = tokens[0] |
| 38 | + |
| 39 | + new_symbol = symbol_mappings.get(old_symbol) |
| 40 | + |
| 41 | + if new_symbol is None: |
| 42 | + continue |
| 43 | + |
| 44 | + tokens[0] = new_symbol |
| 45 | + symbols[i] = " ".join(tokens) + "\n" |
| 46 | + |
| 47 | + with open(symbols_txt_path, "w") as f: |
| 48 | + f.writelines(symbols) |
| 49 | + |
| 50 | +process_symbols_txt("./config/RMCP01/module/symbols.txt") |
| 51 | +process_symbols_txt("./config/RMCP01/symbols.txt") |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +with open("./objdiff.json", "w") as f: |
| 56 | + json.dump(objdiff_config, f) |
0 commit comments