Ghidra is a software reverse engineering (SRE) framework
GP-3752 added callfixup in x86win.cspec and updated GraphASTScript
James3a43696001ab
diff --git a/Ghidra/Features/Decompiler/ghidra_scripts/GraphASTScript.java b/Ghidra/Features/Decompiler/ghidra_scripts/GraphASTScript.javaindex fd426e462d..e1e04b59d6 100644--- a/Ghidra/Features/Decompiler/ghidra_scripts/GraphASTScript.java+++ b/Ghidra/Features/Decompiler/ghidra_scripts/GraphASTScript.java@@ -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";+@Overridepublic 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();}diff --git a/Ghidra/Processors/x86/data/languages/x86win.cspec b/Ghidra/Processors/x86/data/languages/x86win.cspecindex d9072fe238..e61b3ada4d 100644--- a/Ghidra/Processors/x86/data/languages/x86win.cspec+++ b/Ghidra/Processors/x86/data/languages/x86win.cspec@@ -377,4 +377,12 @@</pcode></callfixup>+<callfixup name="__RTC_CheckEsp">+ <target name="__RTC_CheckEsp"/>+ <pcode>+ <body><![CDATA[+ temp:4 = 0;+ ]]></body>+ </pcode>+</callfixup></compiler_spec>