Files
isaac-port/decompile.sh
T
shweetandClaude Opus 5.5 ad8f933086 Salvage Repentance+ 1.9.7.17 decompilation toolkit, notes and name database
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>
2026-10-24 13:08:19 -04:00

30 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Usage: decompile.sh [--live|--asm] QUERY [MAX]
# QUERY = entry/inner address (0x6c0f30 / 006c0f30) or a regex on the qualified name (grep -E).
# Default reads the pre-dumped corpus dump/all.c (instant, concurrency-safe).
# --asm ADDR [N] prints N (default 20) instructions from ADDR (for functions the decompiler times out on).
# --live runs the Ghidra decompiler on a copy of the saved project (~25s; env DECOMP_TIMEOUT=secs, default 180).
D="$(cd "$(dirname "$0")" && pwd)"
LIVE=0; SCRIPT=Decompile.java
[ "$1" = --live ] && { LIVE=1; shift; }
[ "$1" = --asm ] && { LIVE=1; SCRIPT=Disasm.java; shift; }
Q="$1"; MAX="${2:-20}"
[ -z "$Q" ] && { sed -n '2,7p' "$0"; exit 1; }
if [[ "$Q" =~ ^(0x)?[0-9a-fA-F]{6,8}$ ]]; then
A=$(printf '%08x' $((16#${Q#0x})))
# resolve inner address to containing function (largest entry <= A)
Q=$(awk -F'\t' -v a="$A" '($1 "") <= (a "") {best=$1} END{print best}' <(sort "$D/dump/functions.tsv"))
MODE=addr; ASMADDR=$A
fi
if [ $LIVE = 1 ]; then
# Ghidra locks a project even read-only, so each live run works on a private copy (~160MB, tmpfs-fast)
TMP=$(mktemp -d); OUT="$TMP/out.c"; export JAVA_HOME="$D/jdk"
cp -r "$D/project" "$TMP/project"; rm -f "$TMP"/project/*.lock*
"$D/ghidra_12.2_PUBLIC/support/analyzeHeadless" "$TMP/project" isaac -process isaac-ng.exe -noanalysis -readOnly \
-scriptPath "$D/scripts" -postScript $SCRIPT "${ASMADDR:-$Q}" "$MAX" "$OUT" >/dev/null 2>&1
cat "$OUT"; rm -rf "$TMP"; exit
fi
awk -v q="$Q" -v mode="$MODE" -v max="$MAX" '
/^\/\/@@ / { on = mode == "addr" ? ($2 == q "") : ($3 ~ q); if (on && ++n > max) { print "// ... more matches (raise MAX)"; exit } }
on' "$D/dump/all.c"