#!/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