Files
BFM-decomp/tools/ghidra_scripts/DefineFunctions.java
T
Drew T 03978ec4ba feat(phase-10): T4 — resident Ghidra program (2nd binary) + symbol seed + sig
- tools/ghidra_import_raw.sh (NEW): raw-blob importer (BinaryLoader + --loader-baseAddr +
  PSX:LE:32:default) — the Gen2 counterpart to ghidra_import.sh (PS-X-EXE only); reusable for
  Phase-13 location overlays. Imports the resident blob as program 'resident' @0x800CEDF8.
- tools/ghidra_scripts/DefineFunctions.java (NEW): seed splat's validated entry points
  (.run/<prog>_funcs.txt) — raw-binary auto-analysis finds only the reachable subset (23/143);
  this defines all 143 (created=120/existed=23/failed=0). R9-verified 143 funcs persisted.
- FINDING: DetectPsyQ reports the resident is PsyQ 4.7.0 (the EXE is 4.0.0); the lone in-range
  PsyQ-signature hit is DsMix (libsnd -> resident holds the sound driver). 4.7 .LIBs DEFERRED to
  Phase 11 start (Drew); carried to PhaseEnd Notes. Phase 10 needs nothing from 4.7.
- config/symbols.resident.txt: seed DsMix (R13 candidate, 4.0-sig vs 4.7 blob — confirm in Phase 11);
  stacked under symbols.us.txt, applied on re-extract -> resident still 8e17e02f BYTE-IDENTICAL (R22),
  main still 143dbb89 (no regression)
- Makefile: per-binary GHIDRA_PROG -> 'make sig-refresh BINARY=resident' (.run/sig.resident.jsonl)
- dup_report.resident now real (6 byte-identical intra-resident groups — Phase-11 dedup fodder)
- ghidra DB committed (R23, MCP stopped): new resident program 00000003.* (+ main db.15->16 no-op)
2026-06-15 23:25:00 -06:00

42 lines
2.2 KiB
Java

// DefineFunctions.java — headless: disassemble + create a function at each address listed in
// ~/bfm-decomp/.run/<prog>_funcs.txt (one 0xADDR per line). Raw-binary auto-analysis (no entry
// points) finds only the reachable subset of functions; splat's linear sweep finds them all, so
// this seeds the Ghidra program with splat's VALIDATED boundaries — mechanical, NOT manual RE.
// Used in Phase 10 to complete the `resident` program (23 auto-found -> all 143). analyzeHeadless
// commits + saves on a clean exit (run WITHOUT -readOnly).
//
// analyzeHeadless ~/bfm-decomp/ghidra bfm -process <prog> -noanalysis \
// -scriptPath ~/bfm-decomp/tools/ghidra_scripts -postScript DefineFunctions.java
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class DefineFunctions extends GhidraScript {
public void run() throws Exception {
String prog = currentProgram.getName();
Path in = Paths.get(System.getProperty("user.home"), "bfm-decomp", ".run", prog + "_funcs.txt");
if (!Files.exists(in)) { println("DefineFunctions: no list at " + in); return; }
List<String> lines = Files.readAllLines(in);
int created = 0, existed = 0, failed = 0;
for (String ln : lines) {
ln = ln.trim();
if (ln.isEmpty()) continue;
long off = Long.parseLong(ln.replaceFirst("(?i)^0x", ""), 16);
Address a = toAddr(off);
try {
if (getFunctionAt(a) != null) { existed++; continue; }
if (getInstructionAt(a) == null) disassemble(a);
Function f = createFunction(a, null);
if (f != null) created++; else { failed++; println(" no-func @ " + a); }
} catch (Exception e) { failed++; println(" fail @ " + a + ": " + e.getMessage()); }
}
println("BFMDEF created=" + created + " existed=" + existed + " failed=" + failed
+ " total_listed=" + lines.size()
+ " program_funcs_now=" + currentProgram.getFunctionManager().getFunctionCount());
}
}