From 8d386d80278650ac3a983cc0c324de4b853dfce5 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Sat, 16 Nov 2019 13:02:12 -0800 Subject: [PATCH] Add another IDA script --- src/armv5te/arm_interpreter.cpp | 2 +- tools/desktop/applyHalTable.py | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tools/desktop/applyHalTable.py diff --git a/src/armv5te/arm_interpreter.cpp b/src/armv5te/arm_interpreter.cpp index 697aac1..9e6a3b4 100644 --- a/src/armv5te/arm_interpreter.cpp +++ b/src/armv5te/arm_interpreter.cpp @@ -528,7 +528,7 @@ void do_arm_instruction(Instruction i) arm.reg[15] += (int32_t) (i.branch.immed << 8) >> 6;//TODO: this signed int shift is undefined behavior by the C standard arm.reg[15] += 4; if(arm.reg[15] >= 0x2009B130 && arm.reg[15] <= 0x200C7EEB && i.branch.l) - gui_debug_printf("ARM DAL function called:0x%08X from 0x%08X\n", arm.reg[15], arm.reg[14] - 4); + gui_debug_printf("ARM DAL function call, jump from 0x%08X to 0x%08X\n", arm.reg[14] - 4, arm.reg[15]); } else if((insn & 0xF000F10) == 0xE000F10) do_cp15_instruction(i); diff --git a/tools/desktop/applyHalTable.py b/tools/desktop/applyHalTable.py new file mode 100644 index 0000000..bf2b40c --- /dev/null +++ b/tools/desktop/applyHalTable.py @@ -0,0 +1,37 @@ +# jumps to DAL address when given execution address + +import idc +import ida_bytes +import ctypes + + +DAL_JUMP_TABLE = 0x00000024 + + +def getBranchOffset(opcode): + offset = opcode & 0x007FFFFF; + + if opcode & 0x00800000: + offset |= 0xFF800000; + + offset = ctypes.c_int(offset).value; + + offset *= 4 + offset += 8 # account for PC weirdness + + return ctypes.c_int(offset).value + +def writeAddrName(addr, name): + idc.set_name(addr, name + "Entrypoint", SN_NOCHECK) + idc.set_name(addr + getBranchOffset(ida_bytes.get_dword(addr)), name, SN_NOCHECK) + print hex(addr + getBranchOffset(ida_bytes.get_dword(addr))) + +def applyHalTable(): + with open("C:/Users/Emily/Desktop/Projects/PalmOSEmulator/halTable.txt", 'r') as tblFile: + halTable = tblFile.read().split() + + for x in range(0, len(halTable) / 3): + writeAddrName(DAL_JUMP_TABLE + int(halTable[x * 3 + 1], 16), halTable[x * 3 + 2]) + + +applyHalTable() \ No newline at end of file