Ghidra 12.2 project and full dump of isaac-ng.exe v1.9.7.17, query scripts, notes indexed by entity, anm2/rooms reimplementations, and db/ (names + fields) that build.sh re-applies. Fixes awk numeric address comparison in find.sh/decompile.sh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
3.9 KiB
Bash
Executable File
59 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# Rebuilds everything from the game exe (e.g. after a game update). ~25 min analysis + 2 dumps of ~25 min.
|
|
# build.sh [--keep-analysis] (skip the re-import/auto-analysis, just redo names/types/dump)
|
|
# build.sh --db (re-apply db/ to the project, re-decompile just the db functions into the dump, ~1 min)
|
|
# build.sh --db --full (same, then redump everything, ~50 min: needed after db/fields.tsv changes)
|
|
# Steps: import+auto-analysis -> ZHL sig/vtable names -> Lua-registration names -> NPC AI table
|
|
# -> struct offsets re-anchored on getters -> struct/this types -> final dump.
|
|
set -e
|
|
D="$(cd "$(dirname "$0")" && pwd)"
|
|
export JAVA_HOME="$D/jdk" GHIDRA_MAXMEM=24G
|
|
G() { "$D/ghidra_12.2_PUBLIC/support/analyzeHeadless" "$D/project" isaac "$@" -scriptPath "$D/scripts" >> "$D/build.log" 2>&1; }
|
|
P() { python3 -I "$D/scripts/$@"; }
|
|
LUA_REG=00866960 # function that registers the Lua API (references "UseActiveItem" etc.; find.sh str '^UseActiveItem$')
|
|
NPC_DISPATCH=006c2990 # Entity_NPC_UpdateAI_dispatch (callee of Entity_NPC::Update with a jump table on type-10)
|
|
|
|
GAME="${GAME:-$HOME/.steam/steam/steamapps/common/The Binding of Isaac Rebirth}"
|
|
apply_db() { # db names -> struct types (zhl + db fields)
|
|
G -process isaac-ng.exe -noanalysis -postScript ApplyDb.java "$D/db/names.tsv"
|
|
grep -hv '^#' "$D/zhl_fields.tsv" "$D/db/fields.tsv" > "$D/build_fields.tsv"
|
|
G -process isaac-ng.exe -noanalysis -postScript ApplyTypes.java "$D/build_fields.tsv"
|
|
}
|
|
types_dump() { # final dump
|
|
G -process isaac-ng.exe -noanalysis -readOnly -postScript DumpAll.java "$D/dump"
|
|
P lua_bindings.py "$D/bin/isaac-ng.exe" "$D/dump/all.c" "$D/dump"
|
|
command cp -f "$D/npc_ai.tsv" "$D/dump/"; command mv -f "$D/build_fields.tsv" "$D/dump/zhl_fields.tsv"
|
|
command rm -f "$D/dump/lua_names.tsv"
|
|
# the dump gives up after 900 s; retry the big named ones (UseActiveItem takes ~30-60 min) and splice them in
|
|
for A in $(grep -B1 'decompile failed' "$D/dump/all.c" | awk '/^\/\/@@ / && $3 !~ /^FUN_/ {print $2}'); do
|
|
DECOMP_TIMEOUT=7200 "$D/decompile.sh" --live "$A" > "$D/retry.c" && P splice.py "$D/dump/all.c" "$D/retry.c" || true
|
|
done
|
|
command rm -f "$D/retry.c"
|
|
P apply_db.py "$D/db/names.tsv" "$D/dump" # npc_ai.tsv was written before ApplyDb
|
|
}
|
|
if [ "$1" = --db ]; then
|
|
apply_db
|
|
[ "$2" = --full ] && { types_dump; exit; }
|
|
RX="^($(grep -v '^#' "$D/db/names.tsv" | cut -f2 | sed 's/[][().*+?^$|]/\\&/g' | paste -sd'|'))\$"
|
|
DECOMP_TIMEOUT=900 "$D/decompile.sh" --live "$RX" 100000 | awk -v d="$D" '/^\/\/@@ /{f=d "/retry_" $2 ".c"} {print > f}'
|
|
for F in "$D"/retry_*.c; do P splice.py "$D/dump/all.c" "$F" || true; done
|
|
command rm -f "$D"/retry_*.c "$D/build_fields.tsv"
|
|
P apply_db.py "$D/db/names.tsv" "$D/dump"; exit
|
|
fi
|
|
|
|
command cp -f "$GAME/isaac-ng.exe" "$D/bin/"
|
|
[ "$1" = --keep-analysis ] || G -import "$D/bin/isaac-ng.exe" -overwrite
|
|
P zhl_match.py "$D/bin/isaac-ng.exe" "$D/repentogon/libzhl/functions" "$D/zhl_matches.tsv"
|
|
G -process isaac-ng.exe -noanalysis -postScript ApplyNames.java "$D/zhl_matches.tsv" "$D/zhl_vtables.tsv"
|
|
G -process isaac-ng.exe -noanalysis -readOnly -postScript DumpAll.java "$D/dump"
|
|
P lua_bindings.py "$D/bin/isaac-ng.exe" "$D/dump/all.c" "$D"
|
|
cut -f1 "$D/lua_bindings.tsv" | sort -u > "$D/lua_classes.txt"
|
|
G -process isaac-ng.exe -noanalysis -readOnly -postScript LuaAsm.java $LUA_REG "$D/lua_classes.txt" "$D/lua_asm.tsv"
|
|
cat "$D/lua_names.tsv" "$D/lua_asm.tsv" | awk -F'\t' '!seen[$1]++' > "$D/lua_all.tsv"
|
|
G -process isaac-ng.exe -noanalysis -postScript ApplyNames.java "$D/zhl_matches.tsv" "$D/zhl_vtables.tsv" "$D/lua_all.tsv"
|
|
G -process isaac-ng.exe -noanalysis -postScript NpcTable.java $NPC_DISPATCH "$D/repentogon/libzhl/functions/Global.zhl" "$D/npc_ai.tsv"
|
|
P fix_offsets.py "$D/dump/all.c" "$D/zhl_fields.tsv" "$D/zhl_fields.tsv.new" "$D/lua_all.tsv"
|
|
command mv -f "$D/zhl_fields.tsv.new" "$D/zhl_fields.tsv"
|
|
apply_db
|
|
types_dump
|