feed recovered iggy structs back into every decompile
This commit is contained in:
61
tools/ghidra/ExportFunctionSignatures.java
Normal file
61
tools/ghidra/ExportFunctionSignatures.java
Normal file
@@ -0,0 +1,61 @@
|
||||
// Export analyzed function prototypes as a machine-readable TSV file.
|
||||
// @category Iggy
|
||||
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import ghidra.program.model.listing.FunctionIterator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class ExportFunctionSignatures extends GhidraScript {
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
String[] args = getScriptArgs();
|
||||
if (args.length != 1) {
|
||||
throw new IllegalArgumentException("expected output directory");
|
||||
}
|
||||
|
||||
File outputDirectory = new File(args[0]);
|
||||
if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) {
|
||||
throw new IllegalStateException("could not create " + outputDirectory);
|
||||
}
|
||||
|
||||
String outputName = currentProgram.getName().replaceAll("(?i)\\.obj$", "") + ".tsv";
|
||||
File output = new File(outputDirectory, outputName);
|
||||
int exported = 0;
|
||||
try (PrintWriter writer = new PrintWriter(output, "UTF-8")) {
|
||||
writer.println("address\tname\tcalling_convention\treturn_type\tparameter_count\tvariadic\tprototype");
|
||||
FunctionIterator functions = currentProgram.getFunctionManager().getFunctions(true);
|
||||
for (Function function : functions) {
|
||||
if (function.isExternal()) {
|
||||
continue;
|
||||
}
|
||||
writer.print(function.getEntryPoint());
|
||||
writer.print('\t');
|
||||
writer.print(clean(function.getName(true)));
|
||||
writer.print('\t');
|
||||
writer.print(clean(function.getCallingConventionName()));
|
||||
writer.print('\t');
|
||||
writer.print(clean(function.getReturnType().getDisplayName()));
|
||||
writer.print('\t');
|
||||
writer.print(function.getParameterCount());
|
||||
writer.print('\t');
|
||||
writer.print(function.hasVarArgs() ? "1" : "0");
|
||||
writer.print('\t');
|
||||
writer.println(clean(function.getPrototypeString(true, true)));
|
||||
exported++;
|
||||
}
|
||||
}
|
||||
|
||||
println("Exported " + exported + " function signatures from " +
|
||||
currentProgram.getName() + " to " + output);
|
||||
}
|
||||
|
||||
private String clean(String value) {
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
return value.replace('\t', ' ').replace('\r', ' ').replace('\n', ' ');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user