diff options
| author | octorock <79596758+octorock@users.noreply.github.com> | 2021-03-07 01:50:27 +0100 |
|---|---|---|
| committer | octorock <79596758+octorock@users.noreply.github.com> | 2021-03-07 01:52:56 +0100 |
| commit | 5304b4759f200759c0cdddec4eb0aaa6ae1b9aaa (patch) | |
| tree | 41ba2a2b1b4ff0e1cf3bbb4e1008787541e16fc8 /tools | |
| parent | 8f7ad0a35c740c32c5763baa2bac998e260b2da9 (diff) | |
Detect CallWithArg that pass a pointer to a script as an argument
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/script_disassembler/definitions.py | 16 | ||||
| -rw-r--r-- | tools/script_disassembler/split_script_data.py | 5 |
2 files changed, 14 insertions, 7 deletions
diff --git a/tools/script_disassembler/definitions.py b/tools/script_disassembler/definitions.py index fac5ce83..8ec704a4 100644 --- a/tools/script_disassembler/definitions.py +++ b/tools/script_disassembler/definitions.py @@ -1,6 +1,10 @@ from utils import barray_to_u16_hex, barray_to_u32_hex, barray_to_s16 import struct +ROM_OFFSET = 0x08000000 +SCRIPTS_START = 0x08008B5C +SCRIPTS_END = 0x08016984 + # A list of all the commands, their correspondingScriptCommand_ functions and what kind of parameters they take commands = [ {'fun': 'ScriptCommandNop', 'params': ''}, @@ -15,7 +19,7 @@ commands = [ {'fun': 'ScriptCommand_JumpAbsoluteIfNot', 'params': 'x'}, {'fun': 'ScriptCommand_JumpAbsoluteSwitch', 'params': 'xx'}, {'fun': 'ScriptCommand_Call', 'params': 'p'}, - {'fun': 'ScriptCommand_CallWithArg', 'params': ['pw', 'p']}, + {'fun': 'ScriptCommand_CallWithArg', 'params': ['px', 'p']}, {'fun': 'ScriptCommand_LoadRoomEntityList', 'params': 'd'}, {'fun': 'ScriptCommand_TestBit', 'params': 'w'}, {'fun': 'ScriptCommand_CheckInventory1', 'params': 's'}, @@ -181,7 +185,11 @@ def get_data_pointer(barray): def get_script_pointer(barray): integers = struct.unpack('I', barray) - return 'script_' + (struct.pack('>I', integers[0]).hex()).upper() + val = integers[0] + if val >= SCRIPTS_START and val <= SCRIPTS_END: + return 'script_' + (struct.pack('>I', val).hex()).upper() + else: + return '0x'+struct.pack('>I', val).hex() def get_script_label(u32): @@ -285,11 +293,11 @@ parameters = { 'read': lambda ctx: get_pointer(ctx.data[ctx.ptr + 2:ctx.ptr + 6]) }, - 'pw': { + 'px': { 'length': 4, 'param': 'a,b', 'expr': ' .word \\a\n .word \\b', - 'read': lambda ctx: get_pointer(ctx.data[ctx.ptr + 2:ctx.ptr + 6]) + ', ' + barray_to_u32_hex(ctx.data[ctx.ptr + 6:ctx.ptr + 14])[0] + 'read': lambda ctx: get_pointer(ctx.data[ctx.ptr + 2:ctx.ptr + 6]) + ', ' + get_script_pointer(ctx.data[ctx.ptr + 6:ctx.ptr + 10]) }, 'd': { # Data pointer 'length': 2, diff --git a/tools/script_disassembler/split_script_data.py b/tools/script_disassembler/split_script_data.py index 58ffa5a0..8d99df3b 100644 --- a/tools/script_disassembler/split_script_data.py +++ b/tools/script_disassembler/split_script_data.py @@ -1,3 +1,4 @@ +from definitions import ROM_OFFSET, SCRIPTS_END, SCRIPTS_START from script_disassembler import disassemble_script, generate_macros import sys @@ -6,9 +7,7 @@ import sys TMC_FOLDER = '../..' -ROM_OFFSET = 0x08000000 -SCRIPTS_START = 0x08008B5C -SCRIPTS_END = 0x08016984 + # Create labels for these additional script instructions # Currently done by splitting the script at that point |
