GP-3752 added callfixup in x86win.cspec and updated GraphASTScript

This commit is contained in:
James 2023-08-17 20:56:53 +00:00
parent c9f281942a
commit 3a43696001
2 changed files with 36 additions and 12 deletions

View file

@ -16,6 +16,8 @@
//Decompile the function at the cursor, then build data-flow graph (AST)
//@category PCode
import java.util.List;
import ghidra.app.decompiler.*;
import ghidra.app.plugin.core.decompile.actions.PCodeDfgGraphTask;
import ghidra.app.script.GhidraScript;
@ -30,11 +32,19 @@ public class GraphASTScript extends GhidraScript {
private Function func;
protected HighFunction high;
private static final String DECOMPILE = "decompile";
private static final String NORMALIZE = "normalize";
private static final String PARAM_ID = "paramid";
private static final String REGISTER = "register";
private static final String FIRSTPASS = "firstpass";
private static final String JUMP_TABLE = "jumptable";
@Override
public void run() throws Exception {
PluginTool tool = state.getTool();
if (tool == null) {
println("Script is not running in GUI");
popup("Script is not running in GUI");
return;
}
GraphDisplayBroker graphDisplayBroker = tool.getService(GraphDisplayBroker.class);
if (graphDisplayBroker == null) {
@ -49,8 +59,9 @@ public class GraphASTScript extends GhidraScript {
"No Function at current location");
return;
}
buildAST();
String style = askChoice("Select Simplification Style", "Select Simplification Style",
List.of(DECOMPILE, FIRSTPASS, JUMP_TABLE, NORMALIZE, PARAM_ID, REGISTER), DECOMPILE);
buildAST(style);
PCodeDfgGraphTask astGraphTask = createTask(graphDisplayBroker);
astGraphTask.monitoredRun(monitor);
}
@ -59,18 +70,23 @@ public class GraphASTScript extends GhidraScript {
return new PCodeDfgGraphTask(state.getTool(), graphDisplayBroker, high);
}
private void buildAST() throws DecompileException {
private void buildAST(String style) throws DecompileException {
DecompileOptions options = new DecompileOptions();
DecompInterface ifc = new DecompInterface();
ifc.setOptions(options);
if (!ifc.openProgram(this.currentProgram)) {
throw new DecompileException("Decompiler",
"Unable to initialize: " + ifc.getLastMessage());
DecompInterface ifc = new DecompInterface();
try {
ifc.setOptions(options);
if (!ifc.openProgram(this.currentProgram)) {
throw new DecompileException("Decompiler",
"Unable to initialize: " + ifc.getLastMessage());
}
ifc.setSimplificationStyle(style);
DecompileResults res = ifc.decompileFunction(func, 30, null);
high = res.getHighFunction();
}
finally {
ifc.dispose();
}
ifc.setSimplificationStyle("normalize");
DecompileResults res = ifc.decompileFunction(func, 30, null);
high = res.getHighFunction();
}