Files
BFM-decomp/tools/ghidra_scripts/ExportSymbols.java
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
2.5 KiB
Java

// ExportSymbols.java — headless, read-only: export all USER_DEFINED symbols (our manual RE work) to
// a committable text file, so the annotations are version-controlled / re-importable independent of the
// gitignored Ghidra .rep. This is the durable, diffable record of the symbols (sotn model; Phase-5 splat
// will consume/refine config/symbols.us.txt).
//
// analyzeHeadless ~/bfm-decomp/ghidra bfm -process SLUS_007.26 -noanalysis -readOnly \
// -scriptPath ~/bfm-decomp/tools/ghidra_scripts -postScript ExportSymbols.java
import ghidra.app.script.GhidraScript;
import ghidra.program.model.symbol.Symbol;
import ghidra.program.model.symbol.SymbolTable;
import ghidra.program.model.symbol.SourceType;
import ghidra.program.model.symbol.SymbolType;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
public class ExportSymbols extends GhidraScript {
public void run() throws Exception {
SymbolTable st = currentProgram.getSymbolTable();
ArrayList<long[]> keys = new ArrayList<>(); // [addr]
ArrayList<String> lines = new ArrayList<>();
java.util.TreeMap<Long,String> rows = new java.util.TreeMap<>();
int n = 0;
for (Symbol s : st.getAllSymbols(true)) {
if (s.getSource() != SourceType.USER_DEFINED) continue;
if (s.isExternal()) continue;
long a = s.getAddress().getOffset();
// only KSEG0 program space (skip GTE/register-space user labels if any)
String kind = (s.getSymbolType() == SymbolType.FUNCTION) ? "func" : "data";
rows.put((a << 4) | (kind.equals("func") ? 0 : 1),
String.format("%-32s = 0x%08X; // %s", s.getName(), a, kind));
n++;
}
StringBuilder sb = new StringBuilder();
sb.append("// config/symbols.us.txt — USER_DEFINED symbols exported from the Ghidra project.\n");
sb.append("// Auto-generated by tools/ghidra_scripts/ExportSymbols.java; re-run to refresh.\n");
sb.append("// Durable text record of manual RE work (the .rep is gitignored). Phase-5 splat refines this.\n");
sb.append("// count=").append(n).append("\n\n");
for (String v : rows.values()) sb.append(v).append("\n");
java.nio.file.Path out = Paths.get(System.getProperty("user.home"), "bfm-decomp", "config", "symbols.us.txt");
Files.write(out, sb.toString().getBytes());
println("BFMSYM exported " + n + " USER_DEFINED symbols -> " + out);
}
}