Merge pull request #7020 from sepalani/ida-scripts
Tools: Dolphin symbol map IDA scripts added
This commit is contained in:
commit
c3de9d7b0e
|
@ -0,0 +1,60 @@
|
||||||
|
# Copyright 2018 Dolphin Emulator Project
|
||||||
|
# Licensed under GPLv2+
|
||||||
|
# Refer to the license.txt file included.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
filepath = idc.AskFile(0, "*.map", "Load a Dolphin emulator symbol map")
|
||||||
|
symbol_map = load_dolphin_map(filepath)
|
||||||
|
|
||||||
|
for symbol in symbol_map:
|
||||||
|
addr = int(symbol.vaddr, 16)
|
||||||
|
size = int(symbol.size, 16)
|
||||||
|
idc.MakeUnknown(addr, size, 0)
|
||||||
|
if symbol.section in [".init", ".text"]:
|
||||||
|
idc.MakeCode(addr)
|
||||||
|
success = idc.MakeFunction(
|
||||||
|
addr,
|
||||||
|
idc.BADADDR if not size else (addr+size)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
success = idc.MakeData(addr, idc.FF_BYTE, size, 0)
|
||||||
|
|
||||||
|
if not success:
|
||||||
|
idc.Message("Can't apply properties for symbol:"
|
||||||
|
" {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
|
||||||
|
idc.MakeNameEx(addr, symbol.name, flags)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
ida_main()
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Copyright 2018 Dolphin Emulator Project
|
||||||
|
# Licensed under GPLv2+
|
||||||
|
# Refer to the license.txt file included.
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
DolphinSymbol = namedtuple("DolphinSymbol", [
|
||||||
|
"section", "addr", "size", "vaddr", "align", "name"
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def save_dolphin_map(filepath, text_map, data_map):
|
||||||
|
line = "{0.addr:08x} {0.size:08x} {0.vaddr:08x} {0.align} {0.name}\n"
|
||||||
|
with open(filepath, "w") as f:
|
||||||
|
f.write(".text section layout\n")
|
||||||
|
for symbol in text_map:
|
||||||
|
f.write(line.format(symbol))
|
||||||
|
f.write("\n.data section layout\n")
|
||||||
|
for symbol in data_map:
|
||||||
|
f.write(line.format(symbol))
|
||||||
|
|
||||||
|
|
||||||
|
def ida_main():
|
||||||
|
import idaapi
|
||||||
|
import idautils
|
||||||
|
import idc
|
||||||
|
|
||||||
|
filepath = idc.AskFile(1, "*.map", "Save a Dolphin emulator symbol map")
|
||||||
|
text_map = []
|
||||||
|
data_map = []
|
||||||
|
for ea, name in idautils.Names():
|
||||||
|
f = idaapi.get_func(ea)
|
||||||
|
if f is not None:
|
||||||
|
text_map.append(
|
||||||
|
DolphinSymbol(".text", ea, f.size(), ea, 0, name)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
data_map.append(
|
||||||
|
DolphinSymbol(".data", ea, idc.ItemSize(ea), ea, 0, name)
|
||||||
|
)
|
||||||
|
save_dolphin_map(filepath, text_map, data_map)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
ida_main()
|
|
@ -1,62 +0,0 @@
|
||||||
/* ReadDolphinMap.idc
|
|
||||||
|
|
||||||
Loads Dolphin .map files into IDA Pro.
|
|
||||||
Carl Kenner, 2014
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <idc.idc>
|
|
||||||
|
|
||||||
static main(void)
|
|
||||||
{
|
|
||||||
auto fh;
|
|
||||||
auto fname;
|
|
||||||
auto pusha, popa;
|
|
||||||
auto start, end;
|
|
||||||
auto success;
|
|
||||||
auto count;
|
|
||||||
auto line;
|
|
||||||
auto ea; // column 1
|
|
||||||
auto name; // column 30
|
|
||||||
auto p;
|
|
||||||
auto code;
|
|
||||||
|
|
||||||
fname = AskFile(0,"*.map","Load a .map file from Dolphin emulator...");
|
|
||||||
|
|
||||||
fh = fopen(fname, "r");
|
|
||||||
if (fh == 0) {
|
|
||||||
Message("Can't open %s\n", fname);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Message("Loading %s dolphin map file:\n", fname);
|
|
||||||
|
|
||||||
for (count = 0; 1; count++) {
|
|
||||||
line = readstr(fh);
|
|
||||||
if (line == -1)
|
|
||||||
break;
|
|
||||||
if (strlen(line)>30 && line[0]!=" ") {
|
|
||||||
ea = xtol(substr(line,0,8));
|
|
||||||
name = substr(line,29,strlen(line)-1);
|
|
||||||
if (substr(name,0,3)!="zz_") {
|
|
||||||
if (!MakeNameEx(ea,name,SN_NOCHECK | SN_PUBLIC | SN_NON_AUTO |SN_NOWARN)) {
|
|
||||||
MakeNameEx(ea,name+"_2",SN_NOCHECK | SN_PUBLIC | SN_NON_AUTO );
|
|
||||||
}
|
|
||||||
Message("ea='%x', name='%s'\n", ea, name);
|
|
||||||
} else {
|
|
||||||
MakeNameEx(ea,name,SN_NOCHECK | SN_PUBLIC | SN_AUTO | SN_WEAK | SN_NOWARN);
|
|
||||||
}
|
|
||||||
} else if (strlen(line)>30) {
|
|
||||||
ea = xtol(substr(line,18,18+8));
|
|
||||||
p = strstr(line, " \t");
|
|
||||||
if (p>=30 && ea!=0) {
|
|
||||||
name = substr(line,30,p);
|
|
||||||
code = substr(line,p+2,strlen(line));
|
|
||||||
SetFunctionCmt(ea, code, 0);
|
|
||||||
if (!MakeNameEx(ea,name,SN_NOCHECK | SN_PUBLIC | SN_NON_AUTO |SN_NOWARN)) {
|
|
||||||
MakeNameEx(ea,name+"_2",SN_NOCHECK | SN_PUBLIC | SN_NON_AUTO );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message("Dolphin map file done.\n");
|
|
||||||
}
|
|
Loading…
Reference in New Issue