Rename gh_structs.h to gh_types.h, split script
This commit is contained in:
@@ -61,4 +61,10 @@ public class RecompileConfig {
|
||||
decomp.openProgram(currentProgram);
|
||||
decompCache = new DecompileCache(decomp, script.getMonitor());
|
||||
}
|
||||
|
||||
public void createDirectories() {
|
||||
dirDecompAuto.mkdirs();
|
||||
dirDecompFix.mkdirs();
|
||||
dirDecompRef.mkdirs();
|
||||
}
|
||||
}
|
||||
|
72
scripts/re3lib/TypeDumper.java
Normal file
72
scripts/re3lib/TypeDumper.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package re3lib;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.data.DataType;
|
||||
import ghidra.program.model.data.EnumDataType;
|
||||
import ghidra.program.model.data.ProgramBasedDataTypeManager;
|
||||
import ghidra.program.model.data.Structure;
|
||||
import ghidra.program.model.data.TypedefDataType;
|
||||
import ghidra.program.model.listing.Program;
|
||||
|
||||
public class TypeDumper {
|
||||
Program currentProgram;
|
||||
GhidraScript script;
|
||||
|
||||
public TypeDumper(GhidraScript script) {
|
||||
this.script = script;
|
||||
currentProgram = script.getCurrentProgram();
|
||||
RecompileConfig.INSTANCE = new RecompileConfig(script);
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
ProgramBasedDataTypeManager dtm = currentProgram.getDataTypeManager();
|
||||
|
||||
HashSet<String> typeBlacklist = Utils.loadStructBlacklist(RecompileConfig.INSTANCE.typeBlacklistPath);
|
||||
|
||||
if (typeBlacklist == null) {
|
||||
script.println("Building struct blacklist from existing data types");
|
||||
typeBlacklist = new HashSet<>();
|
||||
Iterator<DataType> it = dtm.getAllDataTypes();
|
||||
while (it.hasNext()) {
|
||||
DataType dt = it.next();
|
||||
if (dt instanceof Structure || dt instanceof TypedefDataType) {
|
||||
typeBlacklist.add(dt.getDisplayName());
|
||||
}
|
||||
}
|
||||
Utils.saveStructBlacklist(typeBlacklist, RecompileConfig.INSTANCE.typeBlacklistPath);
|
||||
}
|
||||
|
||||
List<DataType> filteredTypes = new ArrayList<>();
|
||||
Iterator<DataType> it = dtm.getAllDataTypes();
|
||||
while (it.hasNext()) {
|
||||
DataType dt = it.next();
|
||||
if (dt instanceof Structure || dt instanceof TypedefDataType || dt instanceof EnumDataType) {
|
||||
if (typeBlacklist.contains(dt.getDisplayName()))
|
||||
continue;
|
||||
// println("Adding: " + dt.getDisplayName() + " - " +
|
||||
// dt.getClass().getSimpleName());
|
||||
filteredTypes.add(dt);
|
||||
}
|
||||
}
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(new File(RecompileConfig.INSTANCE.outputDir, "gh_types.h"),
|
||||
"UTF-8")) {
|
||||
Utils.headerGuardPre(writer, "STRUCTS");
|
||||
writer.println("// AUTO-GENERATED FILE ");
|
||||
writer.println("#include <gh_struct_binder.h>");
|
||||
|
||||
DataTypeWriter dtw = new DataTypeWriter(dtm, writer);
|
||||
dtw.blacklistedTypes = typeBlacklist;
|
||||
dtw.write(filteredTypes, script.getMonitor());
|
||||
|
||||
Utils.headerGuardPost(writer, "STRUCTS");
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,6 +11,16 @@ import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.address.Address;
|
||||
|
||||
public class Utils {
|
||||
public static void headerGuardPre(PrintWriter writer, String tag) {
|
||||
writer.println("#ifndef GH_GENERATED_" + tag + "_H");
|
||||
writer.println("#define GH_GENERATED_" + tag + "_H");
|
||||
writer.println();
|
||||
}
|
||||
|
||||
public static void headerGuardPost(PrintWriter writer, String tag) {
|
||||
writer.println("#endif // GH_GENERATED_" + tag + "_H");
|
||||
}
|
||||
|
||||
public static HashSet<String> loadStructBlacklist(String path) {
|
||||
File file = new File(path);
|
||||
HashSet<String> structBlacklist = new HashSet<>();
|
||||
|
Reference in New Issue
Block a user