mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-30 10:15:32 +08:00
GP-3752 added callfixup in x86win.cspec and updated GraphASTScript
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
//Decompile the function at the cursor, then build data-flow graph (AST)
|
//Decompile the function at the cursor, then build data-flow graph (AST)
|
||||||
//@category PCode
|
//@category PCode
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import ghidra.app.decompiler.*;
|
import ghidra.app.decompiler.*;
|
||||||
import ghidra.app.plugin.core.decompile.actions.PCodeDfgGraphTask;
|
import ghidra.app.plugin.core.decompile.actions.PCodeDfgGraphTask;
|
||||||
import ghidra.app.script.GhidraScript;
|
import ghidra.app.script.GhidraScript;
|
||||||
@@ -30,11 +32,19 @@ public class GraphASTScript extends GhidraScript {
|
|||||||
private Function func;
|
private Function func;
|
||||||
protected HighFunction high;
|
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
|
@Override
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
PluginTool tool = state.getTool();
|
PluginTool tool = state.getTool();
|
||||||
if (tool == null) {
|
if (tool == null) {
|
||||||
println("Script is not running in GUI");
|
popup("Script is not running in GUI");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
GraphDisplayBroker graphDisplayBroker = tool.getService(GraphDisplayBroker.class);
|
GraphDisplayBroker graphDisplayBroker = tool.getService(GraphDisplayBroker.class);
|
||||||
if (graphDisplayBroker == null) {
|
if (graphDisplayBroker == null) {
|
||||||
@@ -49,8 +59,9 @@ public class GraphASTScript extends GhidraScript {
|
|||||||
"No Function at current location");
|
"No Function at current location");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
String style = askChoice("Select Simplification Style", "Select Simplification Style",
|
||||||
buildAST();
|
List.of(DECOMPILE, FIRSTPASS, JUMP_TABLE, NORMALIZE, PARAM_ID, REGISTER), DECOMPILE);
|
||||||
|
buildAST(style);
|
||||||
PCodeDfgGraphTask astGraphTask = createTask(graphDisplayBroker);
|
PCodeDfgGraphTask astGraphTask = createTask(graphDisplayBroker);
|
||||||
astGraphTask.monitoredRun(monitor);
|
astGraphTask.monitoredRun(monitor);
|
||||||
}
|
}
|
||||||
@@ -59,18 +70,23 @@ public class GraphASTScript extends GhidraScript {
|
|||||||
return new PCodeDfgGraphTask(state.getTool(), graphDisplayBroker, high);
|
return new PCodeDfgGraphTask(state.getTool(), graphDisplayBroker, high);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildAST() throws DecompileException {
|
private void buildAST(String style) throws DecompileException {
|
||||||
DecompileOptions options = new DecompileOptions();
|
DecompileOptions options = new DecompileOptions();
|
||||||
DecompInterface ifc = new DecompInterface();
|
|
||||||
ifc.setOptions(options);
|
|
||||||
|
|
||||||
if (!ifc.openProgram(this.currentProgram)) {
|
DecompInterface ifc = new DecompInterface();
|
||||||
throw new DecompileException("Decompiler",
|
try {
|
||||||
"Unable to initialize: " + ifc.getLastMessage());
|
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();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -377,4 +377,12 @@
|
|||||||
</pcode>
|
</pcode>
|
||||||
</callfixup>
|
</callfixup>
|
||||||
|
|
||||||
|
<callfixup name="__RTC_CheckEsp">
|
||||||
|
<target name="__RTC_CheckEsp"/>
|
||||||
|
<pcode>
|
||||||
|
<body><![CDATA[
|
||||||
|
temp:4 = 0;
|
||||||
|
]]></body>
|
||||||
|
</pcode>
|
||||||
|
</callfixup>
|
||||||
</compiler_spec>
|
</compiler_spec>
|
||||||
|
|||||||
Reference in New Issue
Block a user