mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 20:58:07 +03:00
scripts: extend IDA importer
This commit is contained in:
parent
74edcabd1b
commit
44362e70d5
6 changed files with 3335 additions and 26 deletions
|
@ -154,6 +154,11 @@ Not all options are turned on by default. Refer to `Tomb1Main.json5` for details
|
|||
|
||||

|
||||
|
||||
## Importing data to IDA
|
||||
|
||||
This option requires IDAPython and a recent version of IDA. Install Python 3.8+
|
||||
and IDA 7.5+, then hit alt+f7, then choose `scripts/ida_import.py`.
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the GNU General Public License - see the
|
||||
|
|
2211
docs/ida_types.h
Normal file
2211
docs/ida_types.h
Normal file
File diff suppressed because it is too large
Load diff
1043
docs/ida_variables.txt
Normal file
1043
docs/ida_variables.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,12 +1,25 @@
|
|||
import ctypes
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
import ida_typeinf
|
||||
import idaapi
|
||||
import idc
|
||||
|
||||
PROGRESS_FILE = Path(__file__).parent / "docs" / "progress.txt"
|
||||
REPO_DIR = Path(__file__).parent.parent
|
||||
DOCS_DIR = REPO_DIR / "docs"
|
||||
TYPES_FILE = DOCS_DIR / "ida_types.h"
|
||||
VARIABLES_FILE = DOCS_DIR / "ida_variables.txt"
|
||||
PROGRESS_FILE = DOCS_DIR / "progress.txt"
|
||||
|
||||
|
||||
def to_int(source: str) -> Optional[int]:
|
||||
source = source.strip()
|
||||
if source.startswith("/*"):
|
||||
source = source[2:]
|
||||
if source.endswith("*/"):
|
||||
source = source[:-2]
|
||||
source = source.strip()
|
||||
if not source.replace("-", ""):
|
||||
return None
|
||||
if source.startswith(("0x", "0X")):
|
||||
|
@ -14,27 +27,66 @@ def to_int(source: str) -> Optional[int]:
|
|||
return int(source, 16)
|
||||
|
||||
|
||||
with PROGRESS_FILE.open("r", encoding="utf-8") as handle:
|
||||
for line in handle:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
name, offset, size, flags = line.split(maxsplit=3)
|
||||
offset = to_int(offset)
|
||||
size = to_int(size)
|
||||
def import_types() -> None:
|
||||
print(f"Importing type information from {TYPES_FILE}:")
|
||||
error_count = idaapi.idc_parse_types(str(TYPES_FILE), idc.PT_FILE)
|
||||
print(f" done ({error_count} errors)")
|
||||
|
||||
# ignore inline functions
|
||||
if offset is None:
|
||||
continue
|
||||
|
||||
if not name.startswith("sub_"):
|
||||
default_function_name = f"sub_{offset:x}"
|
||||
print(f"renaming 0x{offset:08x} to {name}")
|
||||
idc.set_name(offset, name)
|
||||
def import_variables() -> None:
|
||||
print(f"Importing variables information from {VARIABLES_FILE}:")
|
||||
with VARIABLES_FILE.open("r") as handle:
|
||||
for line in handle:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
offset, decl = line.split(maxsplit=1)
|
||||
offset = to_int(offset)
|
||||
if True:
|
||||
print(f" renaming 0x{offset:08x} to {decl}")
|
||||
|
||||
if flags == "+":
|
||||
idc.set_color(offset, idc.CIC_FUNC, 0xF0FFEE)
|
||||
elif flags == "x":
|
||||
idc.set_color(offset, idc.CIC_FUNC, 0xD8D8D8)
|
||||
else:
|
||||
idc.set_color(offset, idc.CIC_FUNC, idc.DEFCOLOR)
|
||||
til = idaapi.get_idati()
|
||||
ti = idaapi.tinfo_t()
|
||||
|
||||
name = idaapi.parse_decl(ti, til, decl, idaapi.PT_VAR)
|
||||
if name.startswith("_"):
|
||||
name = name[1:]
|
||||
if not name.startswith('dword_'):
|
||||
idaapi.set_name(offset, name)
|
||||
idaapi.apply_tinfo(offset, ti, 0)
|
||||
print(" done")
|
||||
|
||||
|
||||
def import_functions() -> None:
|
||||
print(f"Importing types information from {PROGRESS_FILE}:")
|
||||
with PROGRESS_FILE.open("r", encoding="utf-8") as handle:
|
||||
for line in handle:
|
||||
line = line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
continue
|
||||
name, offset, size, flags = line.split(maxsplit=3)
|
||||
offset = to_int(offset)
|
||||
size = to_int(size)
|
||||
|
||||
# ignore inline functions
|
||||
if offset is None:
|
||||
continue
|
||||
|
||||
old_name = idc.get_name(offset)
|
||||
if old_name != name and not name.startswith("sub_"):
|
||||
print(f" renaming {old_name} to {name}")
|
||||
idc.set_name(offset, name)
|
||||
|
||||
if flags == "+":
|
||||
idc.set_color(offset, idc.CIC_FUNC, 0xF0FFEE)
|
||||
elif flags == "x":
|
||||
idc.set_color(offset, idc.CIC_FUNC, 0xD8D8D8)
|
||||
else:
|
||||
idc.set_color(offset, idc.CIC_FUNC, idc.DEFCOLOR)
|
||||
print(" done")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import_types()
|
||||
import_variables()
|
||||
import_functions()
|
||||
|
|
|
@ -17,8 +17,6 @@ void mn_update_sound_effects();
|
|||
void mn_get_sound_params(MN_SFX_PLAY_INFO *slot);
|
||||
void mn_stop_sound_effect(int sfx_num, PHD_3DPOS *pos);
|
||||
void mn_adjust_master_volume(int8_t volume);
|
||||
void mn_clear_fx_slot(MN_SFX_PLAY_INFO *slot);
|
||||
void mn_clear_handles(MN_SFX_PLAY_INFO *slot);
|
||||
|
||||
void T1MInjectGameMNSound();
|
||||
|
||||
|
|
|
@ -805,7 +805,7 @@ typedef enum D_FLAGS {
|
|||
D_NEXT = 1 << 3,
|
||||
} D_FLAGS;
|
||||
|
||||
typedef enum APP_SETTINGS_FLAG {
|
||||
typedef enum RENDER_SETTINGS_FLAG {
|
||||
RSF_PERSPECTIVE = 1 << 0,
|
||||
RSF_BILINEAR = 1 << 1,
|
||||
RSF_FPS = 1 << 2,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue