Files
BFM-decomp/tools/ghidra_mcp_verify.sh
T
Drew T bd5e21b366 feat(phase-3): file-loader & overlay-map RE + PCSX-Redux runtime oracle
- RE'd the full file-loader/overlay subsystem in Ghidra via MCP: CdReadRequest ->
  CdReadStateMachine (hand-rolled CdControl SeekL/ReadN reader, NOT PsyQ CdRead);
  LIST.CD RAM cache cdFileLocTable + ResourceGetCdLoc/resourceIdMap lookup; LZSS
  staging buffer 0x80079A70; loadDestPtrTable; ~50 symbols named (T1-T5,T8)
- T6b MILESTONE: resident blob @0x800CEDF8 + location overlay @0x80128158 proven
  byte-identical (sha1-equal contiguous prefixes) vs live PCSX-Redux RAM; blobs
  imported into Ghidra (ImportOverlay.java); overlay-map table -> memory-map.md §4.3
- PCSX-Redux runtime oracle: Windows-native build, WSL reads RAM via the web API
  at 172.17.208.1:8081; ledger #4 resolved
- live-verified player/time state: gold(/10) HP BP day hour tiredness boss-HP;
  save-header template (Q#5) + debug-menu dispatch (Q#9: DEBUG.BIN path is dead)
- overlay map: 13 area-states across SC01/02/03, 2 duplicate pairs, location x
  chapter keying, free-roam vs menu-hub granularity
- resolves Open Q#1/#3/#4/#5/#6/#8/#9/#12; corrects SLUS-90029 (FF8 demo, not BFM)
- 2 US prototypes acquired + CRC-verified (Aug-31 1369DE07, Sep-8 5C24728E)
- rules R9 (verify persistence), R10 (>=3-datapoint live verification),
  R11 (runtime oracle Windows-native, bridged to WSL)
- bumps project version 1.2.0 -> 1.3.0
2026-06-14 02:04:28 -06:00

46 lines
1.9 KiB
Bash

#!/usr/bin/env bash
# tools/ghidra_mcp_verify.sh <addr> <expected-name>
#
# RULE R9: after a Ghidra save-shutdown, verify a recent edit actually persisted to disk.
# Read-only re-opens the SAVED project and checks the function/symbol name at <addr>.
# Run AFTER tools/ghidra_mcp_stop.sh (the server must be stopped — a read-only open needs
# the .rep lock free). Exit 0 = PASS (persisted), non-zero = FAIL / not verified.
#
# Example (after a phase's last edit was renaming 0x80018730 to LzssDecodeSector):
# tools/ghidra_mcp_stop.sh && tools/ghidra_mcp_verify.sh 0x80018730 LzssDecodeSector
set -uo pipefail
ADDR="${1:?usage: ghidra_mcp_verify.sh <addr e.g. 0x80018730> <expected-name>}"
EXPECT="${2:?usage: ghidra_mcp_verify.sh <addr> <expected-name>}"
GHIDRA="${GHIDRA_INSTALL_DIR:-$HOME/ghidra_12.1_PUBLIC}"
PROJ_DIR="$HOME/bfm-decomp/ghidra"
PROJ="bfm"
PROG="SLUS_007.26"
SCRIPTS="$HOME/bfm-decomp/tools/ghidra_scripts"
PORT="8080"
if ss -tln 2>/dev/null | grep -qE ":$PORT([^0-9]|$)"; then
echo "verify: ERROR — server still serving on :$PORT. Run ghidra_mcp_stop.sh first (read-only open needs the lock free)."
exit 2
fi
# A clean stop releases the lock; clear any leftover just in case (no analyzer running here).
rm -f "$PROJ_DIR/$PROJ.lock" "$PROJ_DIR/$PROJ.lock~" 2>/dev/null || true
out=$(timeout 220 "$GHIDRA/support/analyzeHeadless" "$PROJ_DIR" "$PROJ" \
-process "$PROG" -noanalysis -readOnly \
-scriptPath "$SCRIPTS" -postScript GetSymbolAt.java "$ADDR" 2>&1)
got=$(echo "$out" | sed -n 's/.*BFMVERIFY .* name=\[\(.*\)\].*/\1/p' | head -1)
echo "verify: read-only re-open of saved DB -> symbol@$ADDR = [${got:-<none>}]"
if [ "$got" = "$EXPECT" ]; then
echo "verify: ✅ PASS — '$EXPECT' persisted at $ADDR in the saved project DB"
exit 0
else
echo "verify: ❌ FAIL — expected '$EXPECT' at $ADDR, saved DB has '${got:-<none>}'"
echo "--- analyzeHeadless tail ---"; echo "$out" | tail -15
exit 1
fi