Files
BFM-decomp/tools/ghidra_scripts/ImportPsyqGdt.java
T
Drew T 5b6ffc0664 chore(phase-1): headless .gdt attach + MCP type-resolution test (ledger #2)
- tools/ghidra_scripts/ImportPsyqGdt.java: opens psyq400.gdt and resolve()s
  all 2599 PsyQ 4.0 types into the program DTM (205 -> 2609), registering
  psyq400 as a SourceArchive; saved to ghidra/bfm.rep
- verified over MCP: types get DRAWENV -> full 92-byte struct (/LIBGPU.H),
  SVECTOR (/LIBGTE.H) -> the .gdt "attach" is doable headlessly, no GUI
- docs/SETUP.md: ledger #2 RESOLVED; §2.5 step 5 answered (import types into
  the program; MCP type tools then resolve them)
2026-06-13 16:46:03 -06:00

60 lines
2.7 KiB
Java

// ImportPsyqGdt.java — headless equivalent of the GUI ".gdt attach".
// Opens a PsyQ type archive (default psyq400.gdt) and resolves ALL its data
// types into the program's DataTypeManager. resolve() both copies the types in
// AND registers the .gdt as their SourceArchive, so the program shows psyq400
// as an attached source archive and the MCP types/struct tools can reference
// the PsyQ structs/typedefs. Run via: -process SLUS_007.26 -noanalysis
// -postScript ImportPsyqGdt.java [/abs/path/to/psyqXXX.gdt]
import ghidra.app.script.GhidraScript;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.DataTypeConflictHandler;
import ghidra.program.model.data.DataTypeManager;
import ghidra.program.model.data.FileDataTypeManager;
import ghidra.program.model.data.SourceArchive;
import java.io.File;
import java.util.Iterator;
public class ImportPsyqGdt extends GhidraScript {
@Override
public void run() throws Exception {
String gdt = "/home/musashi/ghidra_12.1_PUBLIC/Ghidra/Extensions/ghidra_psx_ldr/data/psyq400.gdt";
String[] a = getScriptArgs();
if (a.length > 0) gdt = a[0];
File f = new File(gdt);
println("=== IMPORT PSYQ GDT ===");
println("GDT: " + f.getAbsolutePath() + " exists=" + f.exists());
if (!f.exists()) { println("ERROR: gdt not found"); return; }
FileDataTypeManager fdtm = FileDataTypeManager.openFileArchive(f, false);
DataTypeManager dtm = currentProgram.getDataTypeManager();
int before = dtm.getDataTypeCount(true);
println("Program DTM types before: " + before);
println("Archive DTM types: " + fdtm.getDataTypeCount(true));
int n = 0;
java.util.List<String> sample = new java.util.ArrayList<>();
int tx = currentProgram.startTransaction("import " + f.getName());
try {
Iterator<DataType> it = fdtm.getAllDataTypes();
while (it.hasNext()) {
DataType dt = it.next();
dtm.resolve(dt, DataTypeConflictHandler.DEFAULT_HANDLER);
if (n < 15) sample.add(dt.getName());
n++;
}
} finally {
currentProgram.endTransaction(tx, true);
}
fdtm.close();
println("Resolved " + n + " types from " + f.getName());
println("Program DTM types after: " + dtm.getDataTypeCount(true));
println("Sample type names: " + sample);
println("Source archives now associated with the program:");
for (SourceArchive sa : dtm.getSourceArchives()) {
println(" - " + sa.getName());
}
println("=== END IMPORT PSYQ GDT ===");
}
}