2021-10-08 20:18:27 -06:00
|
|
|
# Copyright 2021 Dolphin Emulator Project
|
2018-05-29 23:10:44 -06:00
|
|
|
# Licensed under GPLv2+
|
2021-10-08 20:18:27 -06:00
|
|
|
# Refer to the LICENSES/GPL-2.0-or-later.txt file included.
|
2018-05-29 23:10:44 -06:00
|
|
|
|
|
|
|
from collections import namedtuple
|
|
|
|
|
|
|
|
|
|
|
|
DolphinSymbol = namedtuple("DolphinSymbol", [
|
|
|
|
"section", "addr", "size", "vaddr", "align", "name"
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
def load_dolphin_map(filepath):
|
|
|
|
with open(filepath, "r") as f:
|
|
|
|
section = ""
|
|
|
|
symbol_map = []
|
|
|
|
for line in f.readlines():
|
|
|
|
t = line.strip().split(" ", 4)
|
|
|
|
if len(t) == 3 and t[1] == "section" and t[2] == "layout":
|
|
|
|
section = t[0]
|
|
|
|
continue
|
|
|
|
if not section or len(t) != 5:
|
|
|
|
continue
|
|
|
|
symbol_map.append(DolphinSymbol(section, *t))
|
|
|
|
return symbol_map
|
|
|
|
|
|
|
|
|
|
|
|
def ida_main():
|
|
|
|
import idc
|
|
|
|
|
2021-10-08 20:18:27 -06:00
|
|
|
filepath = ida_kernwin.ask_file(0, "*.map", "Load a Dolphin emulator symbol map")
|
|
|
|
if filepath is None:
|
|
|
|
return
|
2018-05-29 23:10:44 -06:00
|
|
|
symbol_map = load_dolphin_map(filepath)
|
|
|
|
|
|
|
|
for symbol in symbol_map:
|
|
|
|
addr = int(symbol.vaddr, 16)
|
|
|
|
size = int(symbol.size, 16)
|
2021-10-08 20:18:27 -06:00
|
|
|
ida_bytes.del_items(addr, size, 0)
|
2018-05-29 23:10:44 -06:00
|
|
|
if symbol.section in [".init", ".text"]:
|
2021-10-08 20:18:27 -06:00
|
|
|
idc.create_insn(addr)
|
|
|
|
success = ida_funcs.add_func(
|
2018-05-29 23:10:44 -06:00
|
|
|
addr,
|
|
|
|
idc.BADADDR if not size else (addr+size)
|
|
|
|
)
|
|
|
|
else:
|
2021-10-08 20:18:27 -06:00
|
|
|
success = ida_bytes.create_data(addr, idc.FF_BYTE, size, 0)
|
2018-05-29 23:10:44 -06:00
|
|
|
|
|
|
|
if not success:
|
2021-10-08 20:18:27 -06:00
|
|
|
ida_kernwin.msg("Can't apply properties for symbol:"
|
2018-05-29 23:10:44 -06:00
|
|
|
" {0.vaddr} - {0.name}\n".format(symbol))
|
|
|
|
|
|
|
|
flags = idc.SN_NOCHECK | idc.SN_PUBLIC
|
|
|
|
if symbol.name.startswith("zz_"):
|
|
|
|
flags |= idc.SN_AUTO | idc.SN_WEAK
|
|
|
|
else:
|
|
|
|
flags |= idc.SN_NON_AUTO
|
2021-10-08 20:18:27 -06:00
|
|
|
idc.set_name(addr, symbol.name, flags)
|
2018-05-29 23:10:44 -06:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
ida_main()
|