Files
BT411/tools/ghidra_reexport.sh
T
Joe DiPrimaandClaude Fable 5 f44be87ab2 #60 PART 2: the RE-EXPORT -- dark code 90KB -> 41KB, coverage 87.3% -> 93.5%
Installed JDK 21 + Ghidra 12.1.2 (no admin, %LOCALAPPDATA%\bt411-tools beside
DXSDK/cmake; runner uses 8.3 SHORT paths because Ghidra's .bat expands
%JAVA_HOME% unquoted and the profile has a space).

New tooling: reference/ghidra_scripts/ExportGaps.java -- ExportAll's exact
output contract PLUS a gap-fill pass (force disassembly + createFunction at
E8 call targets outside functions, data->code pointers at a plausible
prologue, and the census's discovered starts; iterated to a fixpoint,
logged to gapfill_report.tsv).  tools/ghidra_reexport.sh (headless runner,
'reprocess' mode) and tools/gapdiff.py (score two censused exports);
gapcensus.py now censuses any export dir.

Results: 6267 -> 6472 functions (+205 created in 2 rounds: 195 census
starts, 6 call targets, 4 data pointers; 56.1KB newly covered), ZERO
decompile failures.  Dark real code 90.4 -> 40.8 KB (54.8% recovered);
game-side dark 53.1 -> 21.1 KB; regions 428 -> 321.  EVERY historically
dark function now has pseudocode -- including @0x4c05c4 VehicleDead, the
absence that opened this issue.

VALIDATION: the new pseudocode confirms this week's hand reconstruction of
the crouch field-for-field (mapPosture/duckState/squatCapable/myomerEff/
novice gate/SetLegAnimation/ForceUpdate/stability alarm) -- and exposed one
branch the raw pass missed: AIRBORNE AUTO-RISE (mode 3|4 && legState 1 ->
forced squ), now implemented in mech4.cpp and re-benched un-regressed.

PROMOTION: the re-export is canonical reference/decomp/; the previous export
is preserved at reference/decomp/archive_2025export/ so old
`part_0NN.c:LINE` citations still resolve (addresses are stable across both;
line/shard membership is NOT -- cite @ADDR).

New lead recorded: @0x4c0904 is the MASTER BTPlayer Performance (team
resolution, EndMission console post, score heartbeat) -- our @0x4c083c
PlayerSimulation attribution needs a re-check.  KB: source-completeness,
gotcha #20 (the rule is cheap now -- look it up), CLAUDE.md router/layout.
Log: phases/phase-04-gap-census.md.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-06 11:11:26 -05:00

51 lines
1.9 KiB
Bash

#!/usr/bin/env bash
# #60 re-export -- headless Ghidra: analyze BTL4OPT.EXE, fill the dark regions
# (ExportGaps.java), and write a full pseudocode export we can diff against the
# canonical one.
#
# tools/ghidra_reexport.sh # first run: import + full auto-analysis
# tools/ghidra_reexport.sh reprocess # re-run the script on the saved project
#
# Output: reference/decomp/reexport/{all/part_*.c, functions_index.tsv,
# vtables.tsv, gapfill_report.tsv, headless.log}
# Score it with: python tools/gapcensus.py reference/decomp/reexport
set -e
# NB: Ghidra's launcher .bat uses %JAVA_HOME% UNQUOTED, so a space anywhere in
# these paths kills it ("'C:\Users\Joe' is not recognized"). The tools live under
# the user profile (space in "Joe Laptop"), so use the 8.3 SHORT forms.
TOOLS="/c/Users/JOELAP~1/AppData/Local/BT411-~1"
GHIDRA="$TOOLS/GHIDRA~1.2_P"
export JAVA_HOME='C:\Users\JOELAP~1\AppData\Local\BT411-~1\JDK-21~1.12_'
PROJDIR="$TOOLS/ghidra_projects"
PROJ="BT411"
OUT_W='C:\git\bt411\reference\decomp\reexport'
SCRIPTS_W='C:\git\bt411\reference\ghidra_scripts'
EXE_W='C:\git\bt411\content\BTL4OPT.EXE'
PROJDIR_W="$(cygpath -w "$PROJDIR")"
LOG_W='C:\git\bt411\reference\decomp\reexport\headless.log'
mkdir -p "$PROJDIR" /c/git/bt411/reference/decomp/reexport
if [ ! -x "$GHIDRA/support/analyzeHeadless.bat" ] && [ ! -f "$GHIDRA/support/analyzeHeadless.bat" ]; then
echo "ghidra not found at $GHIDRA" >&2; exit 1
fi
"$TOOLS/JDK-21~1.12_/bin/java.exe" -version 2>&1 | head -1
if [ "$1" = "reprocess" ]; then
MODE=(-process BTL4OPT.EXE -noanalysis)
else
MODE=(-import "$EXE_W")
fi
echo "== analyzeHeadless: ${MODE[0]} =="
"$GHIDRA/support/analyzeHeadless.bat" "$PROJDIR_W" "$PROJ" \
"${MODE[@]}" \
-scriptPath "$SCRIPTS_W" \
-postScript ExportGaps.java "$OUT_W" \
-log "$LOG_W"
echo "== done; scoring =="
python /c/git/bt411/tools/gapcensus.py /c/git/bt411/reference/decomp/reexport | tail -3