Files
BFM-decomp/tools/ghidra_import.sh
T
Drew T 3207d52491 feat(phase-3.5): prototype research spike — go/no-go (protos don't accelerate Gen1 matching)
- extract_proto_exe.py: subdir-aware proto main-EXE extraction (reuses iso9660); extracted
  sep8 SLUS_007.26 (413,696 B) + aug31 MUSASHI/USA_DEMO.EXE (415,744 B, base 0x80018000)
- ghidra_import.sh: reusable headless import; both protos imported into the bfm project
  (sep8 1726 funcs, aug31 1737 funcs, both PsyQ 4.0.0), R9-verified
- DumpFunctionSignatures.java + match_protos.py: 3-tier (exact/norm/seq) cross-binary
  correspondence; MIPS normalizer validated by anchors
- FINDINGS: (T2) no debug symbols in either proto — Hidden Palace "no symbols" VERIFIED;
  recon "Sep-8 less-stripped" REFUTED by per-file byte compare. (T3) Sep-8 99.6% byte-identical
  to retail (only 3 funcs differ: DebugMenuHandler, CdReadSectorReadyCB, SaveLoadRoutine);
  Aug-31 66% norm-identical, 862 1:1 correspondences. (T4) demo shares retail's 18-entry
  game-mode dispatch architecture but the handler code diverged — Q#10 resolved
- VERDICT (docs/proto-correspondence.md): NO-GO as a Gen1 label/symbol accelerator; GO to retain
  Sep-8 (Phase-6 compiler corroborant) + both (Gen2 assets); proto-side labels in
  config/symbols.proto-{sep8,demo}.txt (R13-tagged, never feed symbols.us.txt)
- reorg extracted/ into per-ROM subfolders (extracted/retail/, extracted/proto/); nested
  gitignore allowlist; extractor defaults updated; manifest --verify PASS
- memory-map.md: Phase-3.5 block + demo dispatch anchors; Q#10 RESOLVED; §5 proto notes VERIFIED
- ghidra_mcp_start.sh: PROG arg to serve a prototype
- rules R13 (proto-provenance/confidence tagging), R14 (verify recon counts vs bytes)
- bumps project version 1.3.0 -> 1.3.1
2026-06-14 03:19:23 -06:00

50 lines
2.2 KiB
Bash

#!/usr/bin/env bash
# tools/ghidra_import.sh <exe-path>
#
# Import a PS-X EXE into the "bfm" Ghidra project HEADLESS, the same way the retail
# SLUS_007.26 was imported (Phase 1): auto-detect the PSX loader, run auto-analysis
# (which applies PsyQ Signatures + DetectPsyQ), import the PsyQ 4.0 type archive
# (ImportPsyqGdt.java), then DumpProgramInfo.java to print language/base/func-count/
# PsyQ version. analyzeHeadless commits + saves the imported program on a clean exit.
#
# The program name in the project defaults to the EXE's basename (e.g. importing
# extracted/proto/sep8_SLUS_007.26 creates program "sep8_SLUS_007.26").
#
# PRECONDITION: the MCP server must be STOPPED (the project lock is exclusive).
# Run tools/ghidra_mcp_stop.sh first. Used in Phase 3.5 to add the two prototypes
# (sep8_SLUS_007.26, aug31_USA_DEMO.EXE) alongside retail; reusable for any PS-X EXE.
set -uo pipefail
EXE="${1:?usage: ghidra_import.sh <path-to-ps-x-exe>}"
GHIDRA="${GHIDRA_INSTALL_DIR:-$HOME/ghidra_12.1_PUBLIC}"
PROJ_DIR="$HOME/bfm-decomp/ghidra"
PROJ="bfm"
SCRIPTS="$HOME/bfm-decomp/tools/ghidra_scripts"
GDT="${PSYQ_GDT:-$GHIDRA/Ghidra/Extensions/ghidra_psx_ldr/data/psyq400.gdt}"
PORT="8080"
[ -f "$EXE" ] || { echo "import: ERROR — exe not found: $EXE" >&2; exit 2; }
[ -f "$GDT" ] || { echo "import: ERROR — PsyQ gdt not found: $GDT" >&2; exit 2; }
# Guard: a serving MCP server holds the exclusive project lock — refuse to collide.
if ss -tln 2>/dev/null | grep -qE ":$PORT([^0-9]|$)"; then
echo "import: ERROR — MCP server serving on :$PORT. Run tools/ghidra_mcp_stop.sh first." >&2
exit 2
fi
# Clear a stale lock only when no analyzer is alive (mirrors ghidra_mcp_start.sh).
if ! pgrep -f 'ghidra.app.util.headless.AnalyzeHeadless' >/dev/null 2>&1; then
rm -f "$PROJ_DIR/$PROJ.lock" "$PROJ_DIR/$PROJ.lock~" 2>/dev/null || true
fi
echo "import: ===== importing '$EXE' into project '$PROJ' ====="
echo "import: gdt=$GDT (program name = basename; -overwrite for idempotent re-import)"
"$GHIDRA/support/analyzeHeadless" "$PROJ_DIR" "$PROJ" \
-import "$EXE" -overwrite \
-scriptPath "$SCRIPTS" \
-postScript ImportPsyqGdt.java "$GDT" \
-postScript DumpProgramInfo.java
rc=$?
echo "import: ===== analyzeHeadless exit=$rc for '$EXE' ====="
exit $rc