Tidy the repo root: build.sh's derived tables into analysis/, build.sh, decompile.sh and find.sh into scripts/, stale by-products removed, .gitignore regrouped, README describes the src/ layout and the test harness
This commit is contained in:
1 parent
aefd3e2098
commit
7d407d5c19
17 files changed
+140
-86
No files matched your search
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/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
|
||||
# -> REPENTOGON struct fields this exe confirms (getters, Lua field table) -> struct/this types -> final dump.
|
||||
set -e
|
||||
D="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
export JAVA_HOME="$D/jdk" GHIDRA_MAXMEM=24G JAVA_TOOL_OPTIONS="-Djava.io.tmpdir=$D/.tmp" # not /tmp: its user quota is shared
|
||||
mkdir -p "$D/.tmp"
|
||||
G() { "$D/ghidra_12.2_PUBLIC/support/analyzeHeadless" "$D/project" isaac "$@" -scriptPath "$D/scripts" >> "$D/analysis/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"
|
||||
P vtable.py "$D/bin/isaac-ng.exe" "$D/dump/functions.tsv" "$D/analysis/zhl_vtables.tsv" --classes "$D/dump/all.c" > "$D/analysis/classes.tsv" # RTTI: size, bases, slots
|
||||
P merge_fields.py "$D/analysis/build_fields.tsv" "$D/analysis/zhl_fields.tsv" "$D/analysis/lua_fields.tsv" "$D/db/fields.tsv" \
|
||||
<(awk -F'\t' '!/^#/ && $4 != "-" {print $1 "\tsize\t" $4}' "$D/analysis/classes.tsv") # later rows win, "-" deletes
|
||||
P this_types.py "$D/dump/all.c" "$D/analysis/build_fields.tsv" "$D/analysis/build_this.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyTypes.java "$D/analysis/build_fields.tsv" "$D/analysis/build_this.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyGlobals.java "$D/db/globals.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyProtos.java "$D/db" "$D/repentogon/libzhl/functions" # only where RET n agrees
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyLocals.java "$D/db/locals.tsv" # after types: names refer to that decompile
|
||||
}
|
||||
types_dump() { # final dump, built in dump.new and swapped in at the end so readers never see a half-written dump
|
||||
O="$D/dump.new"; command rm -rf "$O"
|
||||
G -process isaac-ng.exe -noanalysis -readOnly -postScript DumpAll.java "$O"
|
||||
P lua_bindings.py "$D/bin/isaac-ng.exe" "$O/all.c" "$O"
|
||||
command cp -f "$D/analysis/npc_ai.tsv" "$O/"; command mv -f "$D/analysis/build_fields.tsv" "$O/zhl_fields.tsv"
|
||||
command rm -f "$O/lua_names.tsv"
|
||||
# the dump gives up after 900 s; retry the big named ones live (UseActiveItem takes ~30-60 min) and splice them in.
|
||||
# With --db --full the exe is unchanged, so the previous dump's copy is reused instead (only newer types missing).
|
||||
for A in $(grep -B1 'decompile failed' "$O/all.c" | awk '/^\/\/@@ / && $3 !~ /^FUN_/ {print $2}'); do
|
||||
if [ -n "$REUSE" ]; then "$D/scripts/decompile.sh" "$A" 1 > "$D/analysis/retry.c" # an old failure stays a failure, no 2 h retry
|
||||
else DECOMP_TIMEOUT=7200 "$D/scripts/decompile.sh" --live "$A" > "$D/analysis/retry.c"; fi
|
||||
P splice.py "$O/all.c" "$D/analysis/retry.c" || true
|
||||
done
|
||||
command rm -f "$D/analysis/retry.c"
|
||||
P apply_db.py "$D/db/names.tsv" "$O" # npc_ai.tsv was written before ApplyDb
|
||||
n() { grep -c '^//@@ ' "$1/all.c" || true; } # a dump cut short (disk full, crash) must not replace a good one
|
||||
[ ! -f "$D/dump/all.c" ] || [ "$(n "$O")" -ge "$(( $(n "$D/dump") * 99 / 100 ))" ] || { echo "dump.new has $(n "$O") functions, dump/ $(n "$D/dump"): kept dump/" >&2; exit 1; }
|
||||
command mv "$D/dump" "$D/dump.old" && command mv "$O" "$D/dump" && command rm -rf "$D/dump.old"
|
||||
source_tree
|
||||
}
|
||||
source_tree() { # generated-src/: the decompiled C++ tree (classes.h + one .cpp per class) for 64-bit Linux, minus what src/ took over
|
||||
command rm -rf "$D/generated-src" && mkdir -p "$D/generated-src"
|
||||
P source_tree.py "$D/generated-src" "$D/analysis/classes.tsv" "$D/dump" "$D/analysis/zhl_vtables.tsv" --check
|
||||
}
|
||||
if [ "$1" = --db ]; then
|
||||
apply_db
|
||||
[ "$2" = --full ] && { REUSE=1 types_dump; exit; }
|
||||
RX="^($( (grep -v '^#' "$D/db/names.tsv" | cut -f2; grep -v '^#' "$D/db/locals.tsv" | grep . | cut -f1 | while read A; do
|
||||
awk -F'\t' -v a="$(printf '%08x' $((16#${A#0x})))" '$1 == a "" {print $2}' "$D/dump/functions.tsv"; done) | sort -u | sed 's/[][().*+?^$|]/\\&/g' | paste -sd'|'))\$"
|
||||
DECOMP_TIMEOUT=900 "$D/scripts/decompile.sh" --live "$RX" 100000 | awk -v d="$D" '/^\/\/@@ /{f=d "/analysis/retry_" $2 ".c"} {print > f}'
|
||||
for F in "$D/analysis"/retry_*.c; do P splice.py "$D/dump/all.c" "$F" || true; done
|
||||
command rm -f "$D/analysis"/retry_*.c "$D/analysis/build_fields.tsv" "$D/analysis/build_this.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/analysis/zhl_matches.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyNames.java "$D/analysis/zhl_matches.tsv" "$D/analysis/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/analysis"
|
||||
cut -f1 "$D/analysis/lua_bindings.tsv" | sort -u > "$D/analysis/lua_classes.txt"
|
||||
G -process isaac-ng.exe -noanalysis -readOnly -postScript LuaAsm.java $LUA_REG "$D/analysis/lua_classes.txt" "$D/analysis/lua_asm.tsv"
|
||||
cat "$D/analysis/lua_names.tsv" "$D/analysis/lua_asm.tsv" | awk -F'\t' '!seen[$1]++' > "$D/analysis/lua_all.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript ApplyNames.java "$D/analysis/zhl_matches.tsv" "$D/analysis/zhl_vtables.tsv" "$D/analysis/lua_all.tsv"
|
||||
G -process isaac-ng.exe -noanalysis -postScript NpcTable.java $NPC_DISPATCH "$D/repentogon/libzhl/functions/Global.zhl" "$D/analysis/npc_ai.tsv"
|
||||
P zhl_fields.py "$D/dump/all.c" "$D/repentogon/libzhl/functions" "$D/analysis/lua_bindings.tsv" "$D/analysis/zhl_fields.tsv" "$D/analysis/lua_all.tsv"
|
||||
P lua_fields.py "$D/dump/all.c" "$D/analysis/lua_names.tsv" "$D/analysis/lua_asm.tsv" "$D/analysis/zhl_fields.tsv" "$D/analysis/lua_fields.tsv"
|
||||
apply_db
|
||||
types_dump
|
||||
Reference in new issue
Block a user