Ghidra is a software reverse engineering (SRE) framework
GT-3116 - Updated decompiler 'Edit Data Type' action to work on more fields; fixed a bug in Location References provider to enable data type selection when focused; fixed a NullPointerException in DockingAction
dragonmacher1a22f97bbe70
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditComponentAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditComponentAction.javaindex 878770de4d..8d70302f48 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditComponentAction.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditComponentAction.java@@ -29,8 +29,8 @@ public class EditComponentAction extends CompositeEditorTableAction {private final static String ACTION_NAME = "Edit Component";private final static String GROUP_NAME = BASIC_ACTION_GROUP;private final static String DESCRIPTION = "Edit the selected component";- private static String[] popupPath = new String[] { ACTION_NAME + "..." };- private static String[] menuPath = new String[] { ACTION_NAME + "..." };+ private static String[] popupPath = new String[] { ACTION_NAME };+ private static String[] menuPath = new String[] { ACTION_NAME };private DataTypeManagerService dtmService;public EditComponentAction(CompositeEditorProvider provider) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/locationreferences/LocationReferencesHighlighter.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/locationreferences/LocationReferencesHighlighter.javaindex 622ad18897..d7b0d4b90e 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/locationreferences/LocationReferencesHighlighter.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/locationreferences/LocationReferencesHighlighter.java@@ -183,7 +183,9 @@ class LocationReferencesHighlighter {DataType locationDataType = null;if (enable) {locationDataType = dataTypeDescriptor.getSourceDataType();+ locationDataType = ReferenceUtils.getBaseDataType(locationDataType);}+dataTypeManagerService.setDataTypeSelected(locationDataType);}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/locationreferences/ReferenceUtils.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/locationreferences/ReferenceUtils.javaindex 0380a9f043..a4a7944c89 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/locationreferences/ReferenceUtils.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/navigation/locationreferences/ReferenceUtils.java@@ -329,23 +329,7 @@ public final class ReferenceUtils {* @return The highest level data type for the given data type.*/public static DataType getBaseDataType(DataType dataType) {- if (dataType instanceof Array) {- return getBaseDataType(((Array) dataType).getDataType());- }- else if (dataType instanceof Pointer) {- DataType baseDataType = ((Pointer) dataType).getDataType();- if (baseDataType != null) {- return getBaseDataType(baseDataType);- }- }-- // NOTE: we do not unroll TypeDefs. This allows clients of this API to search for- // TypeDefs. If we get the base type, then the client cannot search for them.- //else if (dataType instanceof TypeDef) {- // DataType baseDataType = ((TypeDef) dataType).getBaseDataType();- // return getBaseDataType(baseDataType);- //}- return dataType;+ return getBaseDataType(dataType, false);}/**@@ -365,17 +349,17 @@ public final class ReferenceUtils {*/public static DataType getBaseDataType(DataType dataType, boolean includeTypedefs) {if (dataType instanceof Array) {- return getBaseDataType(((Array) dataType).getDataType());+ return getBaseDataType(((Array) dataType).getDataType(), includeTypedefs);}else if (dataType instanceof Pointer) {DataType baseDataType = ((Pointer) dataType).getDataType();if (baseDataType != null) {- return getBaseDataType(baseDataType);+ return getBaseDataType(baseDataType, includeTypedefs);}}- else if (dataType instanceof TypeDef) {+ else if (includeTypedefs && dataType instanceof TypeDef) {DataType baseDataType = ((TypeDef) dataType).getBaseDataType();- return getBaseDataType(baseDataType);+ return getBaseDataType(baseDataType, includeTypedefs);}return dataType;}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerUtils.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerUtils.javaindex 9d72f86a93..d22371046b 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerUtils.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerUtils.java@@ -20,7 +20,9 @@ import java.util.*;import docking.widgets.fieldpanel.field.Field;import docking.widgets.fieldpanel.support.*;import ghidra.app.decompiler.*;+import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.program.model.address.*;+import ghidra.program.model.data.DataType;import ghidra.program.model.listing.Function;import ghidra.program.model.listing.Program;import ghidra.program.model.pcode.*;@@ -671,4 +673,42 @@ public class DecompilerUtils {return lines;}+ /**+ * Returns the data type for the given context if the context pertains to a data type+ *+ * @param context the context+ * @return the data type or null+ */+ public static DataType getDataType(DecompilerActionContext context) {++ DecompilerPanel decompilerPanel = context.getDecompilerPanel();++ // prefer the selection over the current location+ ClangToken token = decompilerPanel.getSelectedToken();+ if (token == null) {+ token = decompilerPanel.getTokenAtCursor();+ }++ Varnode varnode = DecompilerUtils.getVarnodeRef(token);+ if (varnode != null) {+ HighVariable highVariable = varnode.getHigh();+ if (highVariable != null) {+ DataType dataType = highVariable.getDataType();+ return dataType;++ }+ }++ if (token instanceof ClangTypeToken) {+ DataType dataType = ((ClangTypeToken) token).getDataType();+ return dataType;+ }++ if (token instanceof ClangFieldToken) {+ DataType dataType = ((ClangFieldToken) token).getDataType();+ return dataType;+ }++ return null;+ }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerActionContext.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerActionContext.javaindex 9d396523ca..9d4b948ff3 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerActionContext.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerActionContext.java@@ -15,10 +15,16 @@*/package ghidra.app.plugin.core.decompile;+import java.util.function.Supplier;++import docking.ActionContext;+import docking.action.DockingActionIf;import ghidra.app.context.NavigatableActionContext;import ghidra.app.context.RestrictedAddressSetContext;import ghidra.app.decompiler.component.DecompilerPanel;import ghidra.program.model.address.Address;+import ghidra.util.Msg;+import utility.function.Callback;public class DecompilerActionContext extends NavigatableActionContextimplements RestrictedAddressSetContext {@@ -48,4 +54,54 @@ public class DecompilerActionContext extends NavigatableActionContextpublic DecompilerPanel getDecompilerPanel() {return getComponentProvider().getDecompilerPanel();}++ /**+ * The companion method of {@link #checkActionEnablement(Supplier)}. Decompiler actions+ * must call this method from their {@link DockingActionIf#actionPerformed(ActionContext)}+ * if they require state from the Decompiler.+ *+ * @param actionCallback the action's code to execute+ */+ public void performAction(Callback actionCallback) {++ if (isDecompiling) {+ Msg.showInfo(getClass(), getComponentProvider().getComponent(),+ "Decompiler Action Blocked",+ "You cannot perform Decompiler actions while the Decompiler is busy");+ return;+ }++ actionCallback.call();+ }++ /**+ * The companion method of {@link #performAction(Callback)}. Decompiler actions must call+ * this method from their {@link DockingActionIf#isEnabledForContext(ActionContext)} if they+ * require state from the Decompiler.+ *+ * @param actionBooleanSupplier the action's code to verify its enablement+ * @return true if the action should be considered enabled+ */+ public boolean checkActionEnablement(Supplier<Boolean> actionBooleanSupplier) {++ //+ // Unusual Code: actions will call this method when their 'isEnabledForContext()' is+ // called. If the decompiler is still working, we return true here so+ // the action is considered enabled. This allows any key bindings registered+ // for the action to get consumed. If we did not returned false when+ // the decompiler was still working, then the key binding would not match and+ // the system would pass the key binding up to the global action system,+ // which we do not want.+ //+ // Each action that needs state from the decompiler must call this method+ // from 'isEnabledForContext()'. Also, each action must call+ // 'performAction()' on this class, which will skip the action's work and+ // show an message if the decompiler is busy.+ //+ if (isDecompiling()) {+ return true;+ }++ return actionBooleanSupplier.get();+ }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.javaindex 1f2950e919..e0bbe39cdf 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/DecompilerProvider.java@@ -705,16 +705,16 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapterString functionGroup = "1 - Function Group";int subGroupPosition = 0;- specifyCProtoAction = new SpecifyCPrototypeAction(owner, tool, controller);+ specifyCProtoAction = new SpecifyCPrototypeAction(tool, controller);setGroupInfo(specifyCProtoAction, functionGroup, subGroupPosition++);- overrideSigAction = new OverridePrototypeAction(owner, tool, controller);+ overrideSigAction = new OverridePrototypeAction(tool, controller);setGroupInfo(overrideSigAction, functionGroup, subGroupPosition++);- deleteSigAction = new DeletePrototypeOverrideAction(owner, tool, controller);+ deleteSigAction = new DeletePrototypeOverrideAction(tool, controller);setGroupInfo(deleteSigAction, functionGroup, subGroupPosition++);- renameFunctionAction = new RenameFunctionAction(owner, tool, controller);+ renameFunctionAction = new RenameFunctionAction(tool, controller);setGroupInfo(renameFunctionAction, functionGroup, subGroupPosition++);//@@ -723,32 +723,32 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapterString variableGroup = "2 - Variable Group";subGroupPosition = 0; // reset for the next group- renameVarAction = new RenameVariableAction(owner, tool, controller);+ renameVarAction = new RenameVariableAction(tool, controller);setGroupInfo(renameVarAction, variableGroup, subGroupPosition++);- retypeVarAction = new RetypeVariableAction(owner, tool, controller);+ retypeVarAction = new RetypeVariableAction(tool, controller);setGroupInfo(retypeVarAction, variableGroup, subGroupPosition++);decompilerCreateStructureAction =new DecompilerStructureVariableAction(owner, tool, controller);setGroupInfo(decompilerCreateStructureAction, variableGroup, subGroupPosition++);- editDataTypeAction = new EditDataTypeAction(owner, tool, controller);+ editDataTypeAction = new EditDataTypeAction(tool, controller);setGroupInfo(editDataTypeAction, variableGroup, subGroupPosition++);- defUseHighlightAction = new HighlightDefinedUseAction(owner, controller);+ defUseHighlightAction = new HighlightDefinedUseAction(controller);setGroupInfo(defUseHighlightAction, variableGroup, subGroupPosition++);- forwardSliceAction = new ForwardSliceAction(owner, controller);+ forwardSliceAction = new ForwardSliceAction(controller);setGroupInfo(forwardSliceAction, variableGroup, subGroupPosition++);- backwardSliceAction = new BackwardsSliceAction(owner, controller);+ backwardSliceAction = new BackwardsSliceAction(controller);setGroupInfo(backwardSliceAction, variableGroup, subGroupPosition++);- forwardSliceToOpsAction = new ForwardSliceToPCodeOpsAction(owner, controller);+ forwardSliceToOpsAction = new ForwardSliceToPCodeOpsAction(controller);setGroupInfo(forwardSliceToOpsAction, variableGroup, subGroupPosition++);- backwardSliceToOpsAction = new BackwardsSliceToPCodeOpsAction(owner, controller);+ backwardSliceToOpsAction = new BackwardsSliceToPCodeOpsAction(controller);setGroupInfo(backwardSliceToOpsAction, variableGroup, subGroupPosition++);//@@ -762,10 +762,10 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapterString commitGroup = "3 - Commit Group";subGroupPosition = 0; // reset for the next group- lockProtoAction = new CommitParamsAction(owner, tool, controller);+ lockProtoAction = new CommitParamsAction(tool, controller);setGroupInfo(lockProtoAction, commitGroup, subGroupPosition++);- lockLocalAction = new CommitLocalsAction(owner, tool, controller);+ lockLocalAction = new CommitLocalsAction(tool, controller);setGroupInfo(lockLocalAction, commitGroup, subGroupPosition++);//@@ -783,7 +783,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapterString searchGroup = "comment2 - Search Group";subGroupPosition = 0; // reset for the next group- findAction = new FindAction(tool, controller, owner);+ findAction = new FindAction(tool, controller);setGroupInfo(findAction, searchGroup, subGroupPosition++);//@@ -798,7 +798,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapterfindReferencesAction.getPopupMenuData().setParentMenuGroup(referencesParentGroup);FindReferencesToSymbolAction findReferencesToSymbolAction =- new FindReferencesToSymbolAction(tool, owner);+ new FindReferencesToSymbolAction(tool);setGroupInfo(findReferencesToSymbolAction, searchGroup, subGroupPosition++);findReferencesToSymbolAction.getPopupMenuData().setParentMenuGroup(referencesParentGroup);addLocalAction(findReferencesToSymbolAction);@@ -821,9 +821,9 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter//// These actions are not in the popup menu//- debugFunctionAction = new DebugDecompilerAction(owner, controller);- convertAction = new ExportToCAction(owner, controller);- cloneDecompilerAction = new CloneDecompilerAction(owner, this, controller);+ debugFunctionAction = new DebugDecompilerAction(controller);+ convertAction = new ExportToCAction(controller);+ cloneDecompilerAction = new CloneDecompilerAction(this, controller);addLocalAction(refreshAction);addLocalAction(selectAllAction);@@ -872,8 +872,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapterprivate void graphServiceAdded() {if (graphASTControlFlowAction == null && tool.getService(GraphService.class) != null) {- graphASTControlFlowAction =- new GraphASTControlFlowAction(plugin.getName(), plugin, controller);+ graphASTControlFlowAction = new GraphASTControlFlowAction(plugin, controller);addLocalAction(graphASTControlFlowAction);}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/AbstractDecompilerAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/AbstractDecompilerAction.javanew file mode 100644index 0000000000..81f550e14d--- /dev/null+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/AbstractDecompilerAction.java@@ -0,0 +1,75 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.app.plugin.core.decompile.actions;++import docking.ActionContext;+import docking.action.DockingAction;+import ghidra.app.plugin.core.decompile.DecompilePlugin;+import ghidra.app.plugin.core.decompile.DecompilerActionContext;++/**+ * A base class for {@link DecompilePlugin} actions that handles checking whether the+ * decompiler is busy. Each action is responsible for deciding its enablement via+ * {@link #isEnabledForDecompilerContext(DecompilerActionContext)}. Each action must implement+ * {@link #decompilerActionPerformed(DecompilerActionContext)} to complete its work.+ *+ * <p>This parent class uses the {@link DecompilerActionContext} to check for the decompiler's+ * busy status. If the decompiler is busy, then the action will report that it is enabled. We+ * do this so that any keybindings registered for this action will get consumed and not passed up+ * to the global context. Then, if the action is executed, this class does not call the child+ * class, but will instead show an information message indicating that the decompiler is busy.+ */+public abstract class AbstractDecompilerAction extends DockingAction {++ AbstractDecompilerAction(String name) {+ super(name, DecompilePlugin.class.getSimpleName());+ }++ @Override+ public boolean isValidContext(ActionContext context) {+ return context instanceof DecompilerActionContext;+ }++ @Override+ public boolean isEnabledForContext(ActionContext context) {+ DecompilerActionContext decompilerContext = (DecompilerActionContext) context;+ return decompilerContext.checkActionEnablement(() -> {+ return isEnabledForDecompilerContext(decompilerContext);+ });+ }++ @Override+ public void actionPerformed(ActionContext context) {+ DecompilerActionContext decompilerContext = (DecompilerActionContext) context;+ decompilerContext.performAction(() -> {+ decompilerActionPerformed(decompilerContext);+ });+ }++ /**+ * Subclasses return true if they are enabled for the given context+ *+ * @param context the context+ * @return true if enabled+ */+ protected abstract boolean isEnabledForDecompilerContext(DecompilerActionContext context);++ /**+ * Subclasses will perform their work in this method+ * @param context the context+ */+ protected abstract void decompilerActionPerformed(DecompilerActionContext context);+}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceAction.javaindex b3f338c8d0..21e97161a6 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceAction.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,43 +15,26 @@*/package ghidra.app.plugin.core.decompile.actions;+import java.util.Set;++import docking.action.MenuData;import ghidra.app.decompiler.ClangToken;import ghidra.app.decompiler.component.*;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.program.model.pcode.PcodeOp;import ghidra.program.model.pcode.Varnode;-import ghidra.util.Msg;--import java.util.Set;--import docking.ActionContext;-import docking.action.DockingAction;-import docking.action.MenuData;-public class BackwardsSliceAction extends DockingAction {+public class BackwardsSliceAction extends AbstractDecompilerAction {private final DecompilerController controller;- public BackwardsSliceAction(String owner, DecompilerController controller) {- super("Highlight Backward Slice", owner);+ public BackwardsSliceAction(DecompilerController controller) {+ super("Highlight Backward Slice");this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Highlight Backward Slice" }, "Decompile"));}@Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -60,17 +42,7 @@ public class BackwardsSliceAction extends DockingAction {}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -78,7 +50,9 @@ public class BackwardsSliceAction extends DockingAction {PcodeOp op = tokenAtCursor.getPcodeOp();Set<Varnode> backwardSlice = DecompilerUtils.getBackwardSlice(varnode);decompilerPanel.clearHighlights();- decompilerPanel.addVarnodeHighlights(backwardSlice, decompilerPanel.getDefaultHighlightColor(),varnode,op,decompilerPanel.getDefaultSpecialColor());+ decompilerPanel.addVarnodeHighlights(backwardSlice,+ decompilerPanel.getDefaultHighlightColor(), varnode, op,+ decompilerPanel.getDefaultSpecialColor());decompilerPanel.repaint();}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceToPCodeOpsAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceToPCodeOpsAction.javaindex 40c992c623..ae3a4c126a 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceToPCodeOpsAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/BackwardsSliceToPCodeOpsAction.java@@ -15,43 +15,27 @@*/package ghidra.app.plugin.core.decompile.actions;+import java.util.Set;++import docking.action.MenuData;import ghidra.app.decompiler.ClangToken;import ghidra.app.decompiler.component.*;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.program.model.pcode.PcodeOp;import ghidra.program.model.pcode.Varnode;-import ghidra.util.Msg;--import java.util.Set;--import docking.ActionContext;-import docking.action.DockingAction;-import docking.action.MenuData;-public class BackwardsSliceToPCodeOpsAction extends DockingAction {+public class BackwardsSliceToPCodeOpsAction extends AbstractDecompilerAction {private final DecompilerController controller;- public BackwardsSliceToPCodeOpsAction(String owner, DecompilerController controller) {- super("Highlight Backward Inst Slice", owner);+ public BackwardsSliceToPCodeOpsAction(DecompilerController controller) {+ super("Highlight Backward Inst Slice");this.controller = controller;- setPopupMenuData(new MenuData(new String[] { "Highlight Backward Inst Slice" }, "Decompile"));+ setPopupMenuData(+ new MenuData(new String[] { "Highlight Backward Inst Slice" }, "Decompile"));}@Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -59,17 +43,7 @@ public class BackwardsSliceToPCodeOpsAction extends DockingAction {}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -78,7 +52,8 @@ public class BackwardsSliceToPCodeOpsAction extends DockingAction {Set<PcodeOp> backwardSlice = DecompilerUtils.getBackwardSliceToPCodeOps(varnode);backwardSlice.add(op);decompilerPanel.clearHighlights();- decompilerPanel.addPcodeOpHighlights(backwardSlice, decompilerPanel.getDefaultHighlightColor());+ decompilerPanel.addPcodeOpHighlights(backwardSlice,+ decompilerPanel.getDefaultHighlightColor());decompilerPanel.repaint();}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CloneDecompilerAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CloneDecompilerAction.javaindex a597ac277c..6c12f97f38 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CloneDecompilerAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CloneDecompilerAction.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,69 +15,43 @@*/package ghidra.app.plugin.core.decompile.actions;-import ghidra.app.decompiler.component.DecompilerController;-import ghidra.app.plugin.core.decompile.DecompilerActionContext;-import ghidra.app.plugin.core.decompile.DecompilerProvider;-import ghidra.util.HelpLocation;-import ghidra.util.Msg;-import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import javax.swing.ImageIcon;+import docking.action.KeyBindingData;+import docking.action.ToolBarData;+import ghidra.app.decompiler.component.DecompilerController;+import ghidra.app.plugin.core.decompile.DecompilerActionContext;+import ghidra.app.plugin.core.decompile.DecompilerProvider;+import ghidra.util.HelpLocation;import resources.ResourceManager;-import docking.ActionContext;-import docking.action.*;-public class CloneDecompilerAction extends DockingAction {+public class CloneDecompilerAction extends AbstractDecompilerAction {private final DecompilerProvider provider;private DecompilerController controller;- public CloneDecompilerAction(String owner, DecompilerProvider provider,- DecompilerController controller) {- super("Decompile Clone", owner);+ public CloneDecompilerAction(DecompilerProvider provider, DecompilerController controller) {+ super("Decompile Clone");this.provider = provider;this.controller = controller;ImageIcon image = ResourceManager.loadImage("images/camera-photo.png");setToolBarData(new ToolBarData(image, "ZZZ"));setDescription("Create a snapshot (disconnected) copy of this Decompiler window ");setHelpLocation(new HelpLocation("Snapshots", "Snapshots_Start"));- setKeyBindingData(new KeyBindingData(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK |- InputEvent.SHIFT_DOWN_MASK));+ setKeyBindingData(new KeyBindingData(KeyEvent.VK_T,+ InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));}@Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {return controller.getFunction() != null;}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {provider.cloneWindow();}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CommitLocalsAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CommitLocalsAction.javaindex 462a341558..06c91889e8 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CommitLocalsAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CommitLocalsAction.java@@ -15,8 +15,6 @@*/package ghidra.app.plugin.core.decompile.actions;-import docking.ActionContext;-import docking.action.DockingAction;import docking.action.MenuData;import ghidra.app.decompiler.ClangFunction;import ghidra.app.decompiler.ClangToken;@@ -29,35 +27,34 @@ import ghidra.program.model.listing.Program;import ghidra.program.model.pcode.HighFunction;import ghidra.program.model.pcode.HighFunctionDBUtil;import ghidra.program.model.symbol.SourceType;-import ghidra.util.Msg;import ghidra.util.UndefinedFunction;-public class CommitLocalsAction extends DockingAction {+public class CommitLocalsAction extends AbstractDecompilerAction {private final DecompilerController controller;- public CommitLocalsAction(String owner, PluginTool tool, DecompilerController controller) {- super("Commit Locals", owner);+ public CommitLocalsAction(PluginTool tool, DecompilerController controller) {+ super("Commit Locals");this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Commit Locals" }, "Commit"));setDescription("Save Local variable definitions to Program, locking them into their current type definitions");}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;+ private HighFunction getHighFunction() {+ DecompilerPanel decompilerPanel = controller.getDecompilerPanel();+ ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();+ if (tokenAtCursor == null) {+ return null;}-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;+ ClangFunction clfunc = tokenAtCursor.getClangFunction();+ if (clfunc == null) {+ return null;}+ return clfunc.getHighFunction();+ }+ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {Function function = controller.getFunction();if (function == null || function instanceof UndefinedFunction) {return false;@@ -66,17 +63,7 @@ public class CommitLocalsAction extends DockingAction {}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {Program program = controller.getProgram();int transaction = program.startTransaction("Commit Params/Return");try {@@ -87,17 +74,4 @@ public class CommitLocalsAction extends DockingAction {program.endTransaction(transaction, true);}}-- private HighFunction getHighFunction() {- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();- ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();- if (tokenAtCursor == null) {- return null;- }- ClangFunction clfunc = tokenAtCursor.getClangFunction();- if (clfunc == null) {- return null;- }- return clfunc.getHighFunction();- }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CommitParamsAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CommitParamsAction.javaindex 308f71aa74..5bb5d6e7b1 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CommitParamsAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CommitParamsAction.java@@ -17,8 +17,8 @@ package ghidra.app.plugin.core.decompile.actions;import java.awt.event.KeyEvent;-import docking.ActionContext;-import docking.action.*;+import docking.action.KeyBindingData;+import docking.action.MenuData;import ghidra.app.decompiler.ClangFunction;import ghidra.app.decompiler.ClangToken;import ghidra.app.decompiler.component.DecompilerController;@@ -34,13 +34,11 @@ import ghidra.util.Msg;import ghidra.util.UndefinedFunction;import ghidra.util.exception.*;-public class CommitParamsAction extends DockingAction {+public class CommitParamsAction extends AbstractDecompilerAction {private final DecompilerController controller;- private final PluginTool tool;- public CommitParamsAction(String owner, PluginTool tool, DecompilerController controller) {- super("Commit Params/Return", owner);- this.tool = tool;+ public CommitParamsAction(PluginTool tool, DecompilerController controller) {+ super("Commit Params/Return");this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Commit Params/Return" }, "Commit"));setKeyBindingData(new KeyBindingData(KeyEvent.VK_P, 0));@@ -48,20 +46,25 @@ public class CommitParamsAction extends DockingAction {"Save Parameters/Return definitions to Program, locking them into their current type definitions");}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;+ private HighFunction getHighFunction() {+ DecompilerPanel decompilerPanel = controller.getDecompilerPanel();+ ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();++ // getTokenAtCursor can explicitly return null, so we must check here+ // before dereferencing it.+ if (tokenAtCursor == null) {+ return null;}- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;+ ClangFunction clfunc = tokenAtCursor.getClangFunction();+ if (clfunc == null) {+ return null;}+ return clfunc.getHighFunction();+ }++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {Function function = controller.getFunction();if (function == null || function instanceof UndefinedFunction) {@@ -71,17 +74,7 @@ public class CommitParamsAction extends DockingAction {}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {Program program = controller.getProgram();int transaction = program.startTransaction("Commit Params/Return");try {@@ -102,22 +95,6 @@ public class CommitParamsAction extends DockingAction {finally {program.endTransaction(transaction, true);}- }- private HighFunction getHighFunction() {- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();- ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();-- // getTokenAtCursor can explicitly return null, so we must check here- // before dereferencing it.- if (tokenAtCursor == null) {- return null;- }-- ClangFunction clfunc = tokenAtCursor.getClangFunction();- if (clfunc == null) {- return null;- }- return clfunc.getHighFunction();}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CreateStructureVariableAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CreateStructureVariableAction.javaindex 72f3e35335..41d8e606b2 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CreateStructureVariableAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/CreateStructureVariableAction.java@@ -120,13 +120,5 @@ public abstract class CreateStructureVariableAction extends DockingAction {FillOutStructureCmd task = new FillOutStructureCmd(program, location, tool);task.applyTo(program);--// if (commitRequired) {-// int resp = OptionDialog.showOptionDialog(tool.getToolFrame(), "Parameter Commit Required",-// "Retyping a parameter requires all other parameters to be committed!\nContinue with retype?", "Continue");-// if (resp != OptionDialog.OPTION_ONE) {-// return;-// }-// }}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DebugDecompilerAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DebugDecompilerAction.javaindex 39608c6984..0ad5057dd4 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DebugDecompilerAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DebugDecompilerAction.java@@ -15,60 +15,33 @@*/package ghidra.app.plugin.core.decompile.actions;-import ghidra.app.decompiler.component.DecompilerController;-import ghidra.app.plugin.core.decompile.DecompilerActionContext;-import ghidra.util.Msg;-import ghidra.util.filechooser.ExtensionFileFilter;-import java.io.File;import javax.swing.JComponent;-import docking.ActionContext;-import docking.action.DockingAction;import docking.action.MenuData;import docking.widgets.OptionDialog;import docking.widgets.filechooser.GhidraFileChooser;+import ghidra.app.decompiler.component.DecompilerController;+import ghidra.app.plugin.core.decompile.DecompilerActionContext;+import ghidra.util.filechooser.ExtensionFileFilter;-public class DebugDecompilerAction extends DockingAction {+public class DebugDecompilerAction extends AbstractDecompilerAction {private final DecompilerController controller;- public DebugDecompilerAction(String owner, DecompilerController controller) {- super("Debug Function Decompilation", owner);+ public DebugDecompilerAction(DecompilerController controller) {+ super("Debug Function Decompilation");this.controller = controller;setMenuBarData(new MenuData(new String[] { "Debug Function Decompilation" }, "xDebug"));}@Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {return controller.getFunction() != null;}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {JComponent parentComponent = controller.getDecompilerPanel();GhidraFileChooser fileChooser = new GhidraFileChooser(parentComponent);fileChooser.setTitle("Please Choose Output File");diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DecompilerStructureVariableAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DecompilerStructureVariableAction.javaindex 79dee34bb2..8a1fc7baa1 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DecompilerStructureVariableAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DecompilerStructureVariableAction.java@@ -36,44 +36,41 @@ public class DecompilerStructureVariableAction extends CreateStructureVariableAc@Overridepublic boolean isEnabledForContext(ActionContext context) {- DataType dt = null;- boolean isThisParam = false;if (!(context instanceof DecompilerActionContext)) {return false;}- Function function = controller.getFunction();- if (function instanceof UndefinedFunction) {- return false;- }+ DecompilerActionContext decompilerContext = (DecompilerActionContext) context;+ return decompilerContext.checkActionEnablement(() -> {- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }+ Function function = controller.getFunction();+ if (function instanceof UndefinedFunction) {+ return false;+ }- // get the data type at the location and see if it is OK- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();- ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();- if (tokenAtCursor == null) {- return false;- }- HighVariable var = tokenAtCursor.getHighVariable();- if (var != null && !(var instanceof HighConstant)) {- dt = var.getDataType();- isThisParam = testForAutoParameterThis(var, function);- }+ DataType dt = null;+ boolean isThisParam = false;- if (dt == null) {- return false;- }+ // get the data type at the location and see if it is OK+ DecompilerPanel decompilerPanel = controller.getDecompilerPanel();+ ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();+ if (tokenAtCursor == null) {+ return false;+ }+ HighVariable var = tokenAtCursor.getHighVariable();+ if (var != null && !(var instanceof HighConstant)) {+ dt = var.getDataType();+ isThisParam = testForAutoParameterThis(var, function);+ }++ if (dt == null) {+ return false;+ }++ adjustCreateStructureMenuText(dt, isThisParam);+ return true;- adjustCreateStructureMenuText(dt, isThisParam);- return true;+ });}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DeletePrototypeOverrideAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DeletePrototypeOverrideAction.javaindex 5815feef91..f21dbecc45 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DeletePrototypeOverrideAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/DeletePrototypeOverrideAction.java@@ -15,6 +15,7 @@*/package ghidra.app.plugin.core.decompile.actions;+import docking.action.MenuData;import ghidra.app.decompiler.ClangToken;import ghidra.app.decompiler.component.DecompilerController;import ghidra.app.decompiler.component.DecompilerPanel;@@ -28,69 +29,16 @@ import ghidra.program.model.pcode.HighFunction;import ghidra.program.model.symbol.*;import ghidra.util.Msg;import ghidra.util.UndefinedFunction;-import docking.ActionContext;-import docking.action.DockingAction;-import docking.action.MenuData;-public class DeletePrototypeOverrideAction extends DockingAction {+public class DeletePrototypeOverrideAction extends AbstractDecompilerAction {private final DecompilerController controller;- public DeletePrototypeOverrideAction(String owner, PluginTool tool,- DecompilerController controller) {- super("Remove Signature Override", owner);+ public DeletePrototypeOverrideAction(PluginTool tool, DecompilerController controller) {+ super("Remove Signature Override");this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Remove Signature Override" }, "Decompile"));}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- Function function = controller.getFunction();- if (function == null || function instanceof UndefinedFunction) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-- return getSymbol(controller) != null;- }-- @Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-- CodeSymbol sym = getSymbol(controller);- Function func = controller.getFunction();- Program program = func.getProgram();- SymbolTable symtab = program.getSymbolTable();- int transaction = program.startTransaction("Remove Override Signature");- boolean commit = true;- if (!symtab.removeSymbolSpecial(sym)) {- commit = false;- Msg.showError(getClass(),- controller.getDecompilerPanel(), "Removing Override Signature Failed", "Error removing override signature");- }- program.endTransaction(transaction, commit);- }-public static CodeSymbol getSymbol(DecompilerController controller) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();@@ -98,25 +46,58 @@ public class DeletePrototypeOverrideAction extends DockingAction {return null;}Address addr = tokenAtCursor.getMinAddress();- if (addr == null)+ if (addr == null) {return null;+ }Function func = controller.getFunction();Namespace overspace = HighFunction.findOverrideSpace(func);- if (overspace == null)+ if (overspace == null) {return null;+ }SymbolTable symtab = func.getProgram().getSymbolTable();SymbolIterator iter = symtab.getSymbols(overspace);while (iter.hasNext()) {Symbol sym = iter.next();- if (!sym.getName().startsWith("prt"))+ if (!sym.getName().startsWith("prt")) {continue;- if (!(sym instanceof CodeSymbol))+ }+ if (!(sym instanceof CodeSymbol)) {continue;- if (!sym.getAddress().equals(addr))+ }+ if (!sym.getAddress().equals(addr)) {continue;+ }return (CodeSymbol) sym;}return null;}++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {++ Function function = controller.getFunction();+ if (function == null || function instanceof UndefinedFunction) {+ return false;+ }++ return getSymbol(controller) != null;+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {+ CodeSymbol sym = getSymbol(controller);+ Function func = controller.getFunction();+ Program program = func.getProgram();+ SymbolTable symtab = program.getSymbolTable();+ int transaction = program.startTransaction("Remove Override Signature");+ boolean commit = true;+ if (!symtab.removeSymbolSpecial(sym)) {+ commit = false;+ Msg.showError(getClass(), controller.getDecompilerPanel(),+ "Removing Override Signature Failed", "Error removing override signature");+ }+ program.endTransaction(transaction, commit);++ }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/EditDataTypeAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/EditDataTypeAction.javaindex c9a8e8ad4a..527ca34401 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/EditDataTypeAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/EditDataTypeAction.java@@ -15,9 +15,10 @@*/package ghidra.app.plugin.core.decompile.actions;-import ghidra.app.decompiler.ClangToken;+import docking.ActionContext;+import docking.action.MenuData;import ghidra.app.decompiler.component.DecompilerController;-import ghidra.app.decompiler.component.DecompilerPanel;+import ghidra.app.decompiler.component.DecompilerUtils;import ghidra.app.plugin.core.datamgr.util.DataTypeUtils;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.app.services.DataTypeManagerService;@@ -25,22 +26,17 @@ import ghidra.framework.plugintool.PluginTool;import ghidra.program.model.data.DataType;import ghidra.program.model.data.DataTypeManager;import ghidra.program.model.listing.Function;-import ghidra.program.model.pcode.HighVariable;-import ghidra.util.Msg;import ghidra.util.UndefinedFunction;-import docking.ActionContext;-import docking.action.DockingAction;-import docking.action.MenuData;-public class EditDataTypeAction extends DockingAction {+public class EditDataTypeAction extends AbstractDecompilerAction {private final DecompilerController controller;private final PluginTool tool;- public EditDataTypeAction(String owner, PluginTool tool, DecompilerController controller) {- super("EditDataType", owner);+ public EditDataTypeAction(PluginTool tool, DecompilerController controller) {+ super("EditDataType");this.tool = tool;this.controller = controller;- setPopupMenuData(new MenuData(new String[] { "Edit Data Type..." }, "Decompile"));+ setPopupMenuData(new MenuData(new String[] { "Edit Data Type" }, "Decompile"));// setKeyBindingData( new KeyBindingData( KeyEvent.VK_L, InputEvent.CTRL_DOWN_MASK ) );}@@ -50,89 +46,34 @@ public class EditDataTypeAction extends DockingAction {return (context instanceof DecompilerActionContext);}+ private boolean hasCustomEditorForBaseDataType(DataType dataType) {+ DataType baseDataType = DataTypeUtils.getBaseDataType(dataType);+ final DataTypeManagerService service = tool.getService(DataTypeManagerService.class);+ return baseDataType != null && service.isEditable(baseDataType);+ }+@Override- public boolean isAddToPopup(ActionContext context) {- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- return false;- }+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {Function function = controller.getFunction();if (function instanceof UndefinedFunction) {return false;}- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();- ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();- if (tokenAtCursor == null) {- return false;- }- if (!tokenAtCursor.isVariableRef()) {- return false;- }- HighVariable variable = tokenAtCursor.getHighVariable();- if (variable == null) {- return false;- }- DataType dataType = variable.getDataType();+ DataType dataType = DecompilerUtils.getDataType(context);if (dataType == null) {return false;}- return hasCustomEditorForBaseDataType(dataType);- }- @Override- public boolean isEnabledForContext(ActionContext context) {- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();- ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();- if (tokenAtCursor == null) {- return false;- }- if (!tokenAtCursor.isVariableRef()) {- return false;- }- HighVariable variable = tokenAtCursor.getHighVariable();- if (variable == null) {- return false;- }- DataType dataType = variable.getDataType();return hasCustomEditorForBaseDataType(dataType);}- private boolean hasCustomEditorForBaseDataType(DataType dataType) {- DataType baseDataType = DataTypeUtils.getBaseDataType(dataType);- final DataTypeManagerService service = tool.getService(DataTypeManagerService.class);- return baseDataType != null && service.isEditable(baseDataType);- }-@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();- ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();- HighVariable variable = tokenAtCursor.getHighVariable();+ protected void decompilerActionPerformed(DecompilerActionContext context) {- DataType dataType = variable.getDataType();+ DataType dataType = DecompilerUtils.getDataType(context);DataType baseDataType = DataTypeUtils.getBaseDataType(dataType);- DataTypeManager dataTypeManager = decompilerActionContext.getProgram().getDataTypeManager();+ DataTypeManager dataTypeManager = context.getProgram().getDataTypeManager();DataTypeManager baseDtDTM = baseDataType.getDataTypeManager();if (baseDtDTM != dataTypeManager) {baseDataType = baseDataType.clone(dataTypeManager);diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ExportToCAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ExportToCAction.javaindex d4ab8306bf..6873bbc857 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ExportToCAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ExportToCAction.java@@ -15,53 +15,33 @@*/package ghidra.app.plugin.core.decompile.actions;-import ghidra.app.decompiler.*;-import ghidra.app.decompiler.component.DecompilerController;-import ghidra.app.plugin.core.decompile.DecompilerActionContext;-import ghidra.framework.preferences.Preferences;-import ghidra.util.Msg;-import ghidra.util.filechooser.ExtensionFileFilter;-import java.io.*;import javax.swing.ImageIcon;-import resources.ResourceManager;-import docking.ActionContext;-import docking.action.DockingAction;import docking.action.ToolBarData;import docking.widgets.OptionDialog;import docking.widgets.filechooser.GhidraFileChooser;+import ghidra.app.decompiler.*;+import ghidra.app.decompiler.component.DecompilerController;+import ghidra.app.plugin.core.decompile.DecompilerActionContext;+import ghidra.framework.preferences.Preferences;+import ghidra.util.Msg;+import ghidra.util.filechooser.ExtensionFileFilter;+import resources.ResourceManager;-public class ExportToCAction extends DockingAction {+public class ExportToCAction extends AbstractDecompilerAction {private static final ImageIcon EXPORT_ICON = ResourceManager.loadImage("images/page_edit.png");private static final String LAST_USED_C_FILE = "last.used.decompiler.c.export.file";private final DecompilerController controller;- public ExportToCAction(String owner, DecompilerController controller) {- super("Export to C", owner);+ public ExportToCAction(DecompilerController controller) {+ super("Export to C");this.controller = controller;setToolBarData(new ToolBarData(EXPORT_ICON, "Local"));setDescription("Export the current function to C");}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-- return controller.getFunction() != null && controller.getCCodeModel() != null;- }-private File readLastUsedFile() {String filename = Preferences.getProperty(LAST_USED_C_FILE);if (filename == null) {@@ -75,18 +55,7 @@ public class ExportToCAction extends DockingAction {Preferences.store();}- @Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ private File getFile() {File lastUsedFile = readLastUsedFile();String[] extensions = new String[] { "h", "c", "cpp" };@@ -97,7 +66,7 @@ public class ExportToCAction extends DockingAction {}File file = fileChooser.getSelectedFile();if (file == null) {- return;+ return null;}saveLastUsedFileFile(file);@@ -113,10 +82,26 @@ public class ExportToCAction extends DockingAction {if (!hasExtension) {file = new File(path + ".c");}+ return file;+ }++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {+ return controller.getFunction() != null && controller.getCCodeModel() != null;+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {++ File file = getFile();+ if (file == null) {+ return;+ }if (file.exists()) {if (OptionDialog.showYesNoDialog(controller.getDecompilerPanel(),- "Overwrite Existing File?", "Do you want to overwrite the existing file?") == OptionDialog.OPTION_TWO) {+ "Overwrite Existing File?",+ "Do you want to overwrite the existing file?") == OptionDialog.OPTION_TWO) {return;}}@@ -128,13 +113,12 @@ public class ExportToCAction extends DockingAction {DecompiledFunction decompFunc = printer.print(true);writer.write(decompFunc.getC());writer.close();- controller.setStatusMessage("Successfully exported function(s) to " +- file.getAbsolutePath());+ controller.setStatusMessage(+ "Successfully exported function(s) to " + file.getAbsolutePath());}catch (IOException e) {Msg.showError(getClass(), controller.getDecompilerPanel(), "Export to C Failed","Error exporting to C: " + e);}}-}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindAction.javaindex 70b23623e0..4a8bc9e5de 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindAction.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -20,8 +19,8 @@ import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import java.util.List;-import docking.ActionContext;-import docking.action.*;+import docking.action.KeyBindingData;+import docking.action.MenuData;import docking.widgets.*;import docking.widgets.fieldpanel.field.Field;import docking.widgets.fieldpanel.support.FieldLocation;@@ -29,15 +28,14 @@ import ghidra.app.decompiler.component.*;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.framework.plugintool.PluginTool;import ghidra.util.HelpLocation;-import ghidra.util.Msg;-public class FindAction extends DockingAction {+public class FindAction extends AbstractDecompilerAction {private FindDialog findDialog;private final DecompilerPanel decompilerPanel;private final PluginTool tool;- public FindAction(PluginTool tool, DecompilerController controller, String owner) {- super("Find", owner);+ public FindAction(PluginTool tool, DecompilerController controller) {+ super("Find");this.tool = tool;this.decompilerPanel = controller.getDecompilerPanel();setPopupMenuData(new MenuData(new String[] { "Find..." }, "Decompile"));@@ -45,44 +43,6 @@ public class FindAction extends DockingAction {setEnabled(true);}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }- return true;- }-- @Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-- FindDialog dialog = getFindDialog();- String text = decompilerPanel.getHighlightedText();- if (text != null) {- dialog.setSearchText(text);- }-- // show over the root frame, so the user can still see the Decompiler window- tool.showDialog(dialog);- }-protected FindDialog getFindDialog() {if (findDialog == null) {findDialog = new FindDialog("Decompiler Find Text", new DecompilerSearcher()) {@@ -151,4 +111,21 @@ public class FindAction extends DockingAction {}}++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {+ return true;+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {+ FindDialog dialog = getFindDialog();+ String text = decompilerPanel.getHighlightedText();+ if (text != null) {+ dialog.setSearchText(text);+ }++ // show over the root frame, so the user can still see the Decompiler window+ tool.showDialog(dialog);+ }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToAddressAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToAddressAction.javaindex 0155268223..33ee4284b4 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToAddressAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToAddressAction.java@@ -15,6 +15,7 @@*/package ghidra.app.plugin.core.decompile.actions;+import docking.ActionContext;import docking.action.MenuData;import ghidra.app.actions.AbstractFindReferencesToAddressAction;import ghidra.app.context.NavigatableActionContext;@@ -41,4 +42,24 @@ public class FindReferencesToAddressAction extends AbstractFindReferencesToAddre}return context.getLocation();}++ @Override+ public boolean isEnabledForContext(ActionContext context) {+ if (!(context instanceof DecompilerActionContext)) {+ return false;+ }++ DecompilerActionContext decompilerContext = (DecompilerActionContext) context;+ return decompilerContext.checkActionEnablement(() -> {+ return super.isEnabledForContext(context);+ });+ }++ @Override+ public void actionPerformed(ActionContext context) {+ DecompilerActionContext decompilerContext = (DecompilerActionContext) context;+ decompilerContext.performAction(() -> {+ super.actionPerformed(context);+ });+ }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToDataTypeAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToDataTypeAction.javaindex e49dc3ae2b..3591fbf78a 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToDataTypeAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToDataTypeAction.java@@ -18,15 +18,13 @@ package ghidra.app.plugin.core.decompile.actions;import docking.ActionContext;import docking.action.MenuData;import ghidra.app.actions.AbstractFindReferencesDataTypeAction;-import ghidra.app.decompiler.*;+import ghidra.app.decompiler.ClangFieldToken;+import ghidra.app.decompiler.ClangToken;import ghidra.app.decompiler.component.*;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.app.plugin.core.navigation.locationreferences.LocationReferencesService;import ghidra.framework.plugintool.PluginTool;import ghidra.program.model.data.DataType;-import ghidra.program.model.pcode.HighVariable;-import ghidra.program.model.pcode.Varnode;-import ghidra.util.Msg;public class FindReferencesToDataTypeAction extends AbstractFindReferencesDataTypeAction {@@ -44,35 +42,7 @@ public class FindReferencesToDataTypeAction extends AbstractFindReferencesDataTy@Overridepublic DataType getDataType(ActionContext context) {- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();-- // prefer the selection over the current location- ClangToken token = decompilerPanel.getSelectedToken();- if (token == null) {- token = decompilerPanel.getTokenAtCursor();- }-- Varnode varnode = DecompilerUtils.getVarnodeRef(token);- if (varnode != null) {- HighVariable highVariable = varnode.getHigh();- if (highVariable != null) {- DataType dataType = highVariable.getDataType();- return dataType;-- }- }-- if (token instanceof ClangTypeToken) {- DataType dataType = ((ClangTypeToken) token).getDataType();- return dataType;- }-- if (token instanceof ClangFieldToken) {- DataType dataType = ((ClangFieldToken) token).getDataType();- return dataType;- }-- return null;+ return DecompilerUtils.getDataType((DecompilerActionContext) context);}@Override@@ -93,34 +63,23 @@ public class FindReferencesToDataTypeAction extends AbstractFindReferencesDataTyreturn false;}- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }+ DecompilerActionContext decompilerContext = (DecompilerActionContext) context;+ return decompilerContext.checkActionEnablement(() -> {- DataType dataType = getDataType(context);- updateMenuName(dataType);+ DataType dataType = getDataType(context);+ updateMenuName(dataType);- return super.isEnabledForContext(context);+ return super.isEnabledForContext(context);+ });}@Overridepublic void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }- super.actionPerformed(context);+ DecompilerActionContext decompilerContext = (DecompilerActionContext) context;+ decompilerContext.performAction(() -> {+ super.actionPerformed(context);+ });}private void updateMenuName(DataType type) {diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToSymbolAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToSymbolAction.javaindex 4eaf7aeabb..63bf434793 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToSymbolAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/FindReferencesToSymbolAction.java@@ -15,8 +15,6 @@*/package ghidra.app.plugin.core.decompile.actions;-import docking.ActionContext;-import docking.action.DockingAction;import docking.action.MenuData;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.app.plugin.core.decompile.DecompilerProvider;@@ -35,14 +33,14 @@ import ghidra.util.Msg;/*** An action to show all references to the symbol under the cursor in the Decompiler*/-public class FindReferencesToSymbolAction extends DockingAction {+public class FindReferencesToSymbolAction extends AbstractDecompilerAction {private static final String MENU_ITEM_TEXT = "Find References to";public static final String NAME = "Find References to Symbol";private PluginTool tool;- public FindReferencesToSymbolAction(PluginTool tool, String owner) {- super(NAME, owner);+ public FindReferencesToSymbolAction(PluginTool tool) {+ super(NAME);this.tool = tool;setPopupMenuData(@@ -50,57 +48,6 @@ public class FindReferencesToSymbolAction extends DockingAction {setHelpLocation(new HelpLocation(HelpTopics.FIND_REFERENCES, HelpTopics.FIND_REFERENCES));}- @Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerContext = (DecompilerActionContext) context;- if (decompilerContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-- LocationReferencesService service = tool.getService(LocationReferencesService.class);- if (service == null) {- Msg.showError(this, null, "Missing Plugin",- "The " + LocationReferencesService.class.getSimpleName() + " is not installed.\n" +- "Please add the plugin implementing this service.");- return;- }-- Symbol symbol = getSymbol(decompilerContext);- LabelFieldLocation location = new LabelFieldLocation(symbol);- DecompilerProvider provider = decompilerContext.getComponentProvider();- service.showReferencesToLocation(location, provider);- }-- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-- Symbol symbol = getSymbol((DecompilerActionContext) context);- if (symbol == null) {- return false;- }-- updateMenuName(symbol);-- return true;- }-private Symbol getSymbol(DecompilerActionContext context) {ProgramLocation location = context.getLocation();@@ -128,4 +75,32 @@ public class FindReferencesToSymbolAction extends DockingAction {data.setMenuPath(new String[] { LocationReferencesService.MENU_GROUP, menuName });setPopupMenuData(data);}++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {+ Symbol symbol = getSymbol(context);+ if (symbol == null) {+ return false;+ }++ updateMenuName(symbol);++ return true;+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {+ LocationReferencesService service = tool.getService(LocationReferencesService.class);+ if (service == null) {+ Msg.showError(this, null, "Missing Plugin",+ "The " + LocationReferencesService.class.getSimpleName() + " is not installed.\n" ++ "Please add the plugin implementing this service.");+ return;+ }++ Symbol symbol = getSymbol(context);+ LabelFieldLocation location = new LabelFieldLocation(symbol);+ DecompilerProvider provider = context.getComponentProvider();+ service.showReferencesToLocation(location, provider);+ }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceAction.javaindex 99f80d0bc2..8ba4a8a8ee 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceAction.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,42 +15,26 @@*/package ghidra.app.plugin.core.decompile.actions;+import java.util.Set;++import docking.action.MenuData;import ghidra.app.decompiler.ClangToken;import ghidra.app.decompiler.component.*;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.program.model.pcode.PcodeOp;import ghidra.program.model.pcode.Varnode;-import ghidra.util.Msg;--import java.util.Set;--import docking.ActionContext;-import docking.action.DockingAction;-import docking.action.MenuData;-public class ForwardSliceAction extends DockingAction {+public class ForwardSliceAction extends AbstractDecompilerAction {private final DecompilerController controller;- public ForwardSliceAction(String owner, DecompilerController controller) {- super("Highlight Forward Slice", owner);+ public ForwardSliceAction(DecompilerController controller) {+ super("Highlight Forward Slice");this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Highlight Forward Slice" }, "Decompile"));}@Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -59,17 +42,7 @@ public class ForwardSliceAction extends DockingAction {}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -77,7 +50,9 @@ public class ForwardSliceAction extends DockingAction {PcodeOp op = tokenAtCursor.getPcodeOp();Set<Varnode> forwardSlice = DecompilerUtils.getForwardSlice(varnode);decompilerPanel.clearHighlights();- decompilerPanel.addVarnodeHighlights(forwardSlice, decompilerPanel.getDefaultHighlightColor(),varnode,op,decompilerPanel.getDefaultSpecialColor());+ decompilerPanel.addVarnodeHighlights(forwardSlice,+ decompilerPanel.getDefaultHighlightColor(), varnode, op,+ decompilerPanel.getDefaultSpecialColor());decompilerPanel.repaint();}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceToPCodeOpsAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceToPCodeOpsAction.javaindex 0bf06299c1..aaab730b1f 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceToPCodeOpsAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ForwardSliceToPCodeOpsAction.java@@ -15,42 +15,27 @@*/package ghidra.app.plugin.core.decompile.actions;+import java.util.Set;++import docking.action.MenuData;import ghidra.app.decompiler.ClangToken;import ghidra.app.decompiler.component.*;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.program.model.pcode.PcodeOp;import ghidra.program.model.pcode.Varnode;-import ghidra.util.Msg;--import java.util.Set;--import docking.ActionContext;-import docking.action.DockingAction;-import docking.action.MenuData;-public class ForwardSliceToPCodeOpsAction extends DockingAction {+public class ForwardSliceToPCodeOpsAction extends AbstractDecompilerAction {private final DecompilerController controller;- public ForwardSliceToPCodeOpsAction(String owner, DecompilerController controller) {- super("Highlight Forward Inst Slice", owner);+ public ForwardSliceToPCodeOpsAction(DecompilerController controller) {+ super("Highlight Forward Inst Slice");this.controller = controller;- setPopupMenuData(new MenuData(new String[] { "Highlight Forward Inst Slice" }, "Decompile"));+ setPopupMenuData(+ new MenuData(new String[] { "Highlight Forward Inst Slice" }, "Decompile"));}@Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -58,17 +43,7 @@ public class ForwardSliceToPCodeOpsAction extends DockingAction {}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -77,9 +52,11 @@ public class ForwardSliceToPCodeOpsAction extends DockingAction {Set<PcodeOp> forwardSlice = DecompilerUtils.getForwardSliceToPCodeOps(varnode);forwardSlice.add(op);decompilerPanel.clearHighlights();- decompilerPanel.addPcodeOpHighlights(forwardSlice, decompilerPanel.getDefaultHighlightColor());+ decompilerPanel.addPcodeOpHighlights(forwardSlice,+ decompilerPanel.getDefaultHighlightColor());decompilerPanel.repaint();}+}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/GraphASTControlFlowAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/GraphASTControlFlowAction.javaindex 33d38abe45..6e23e61353 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/GraphASTControlFlowAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/GraphASTControlFlowAction.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,6 +15,7 @@*/package ghidra.app.plugin.core.decompile.actions;+import docking.action.MenuData;import ghidra.app.decompiler.component.DecompilerController;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.app.services.GraphService;@@ -26,53 +26,25 @@ import ghidra.program.model.address.Address;import ghidra.program.model.pcode.HighFunction;import ghidra.util.Msg;import ghidra.util.task.TaskLauncher;-import docking.ActionContext;-import docking.action.DockingAction;-import docking.action.MenuData;-public class GraphASTControlFlowAction extends DockingAction {+public class GraphASTControlFlowAction extends AbstractDecompilerAction {private final DecompilerController controller;private final PluginTool tool;- private final Plugin plugin;- public GraphASTControlFlowAction(String owner, Plugin plugin, DecompilerController controller) {- super("Graph AST Control Flow", owner);- this.plugin = plugin;+ public GraphASTControlFlowAction(Plugin plugin, DecompilerController controller) {+ super("Graph AST Control Flow");this.tool = plugin.getTool();this.controller = controller;setMenuBarData(new MenuData(new String[] { "Graph AST Control Flow" }, "graph"));-}@Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {return controller.getFunction() != null;}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {GraphService graphService = tool.getService(GraphService.class);if (graphService == null) {Msg.showError(this, tool.getToolFrame(), "AST Graph Failed",@@ -86,9 +58,8 @@ public class GraphASTControlFlowAction extends DockingAction {int codeLimitPerBlock = options.getInt("Max Code Lines Displayed", 10);HighFunction highFunction = controller.getHighFunction();Address locationAddr = controller.getLocation().getAddress();- ASTGraphTask task =- new ASTGraphTask(graphService, !reuseGraph, codeLimitPerBlock, locationAddr,- highFunction, ASTGraphTask.CONTROL_FLOW_GRAPH);+ ASTGraphTask task = new ASTGraphTask(graphService, !reuseGraph, codeLimitPerBlock,+ locationAddr, highFunction, ASTGraphTask.CONTROL_FLOW_GRAPH);new TaskLauncher(task, tool.getToolFrame());}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/HighlightDefinedUseAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/HighlightDefinedUseAction.javaindex 9980dfc0b4..231ee51afa 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/HighlightDefinedUseAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/HighlightDefinedUseAction.java@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,44 +15,25 @@*/package ghidra.app.plugin.core.decompile.actions;-import ghidra.app.decompiler.ClangToken;-import ghidra.app.decompiler.component.DecompilerController;-import ghidra.app.decompiler.component.DecompilerPanel;-import ghidra.app.decompiler.component.DecompilerUtils;-import ghidra.app.plugin.core.decompile.DecompilerActionContext;-import ghidra.program.model.pcode.Varnode;-import ghidra.util.Msg;-import java.util.HashSet;-import docking.ActionContext;-import docking.action.DockingAction;import docking.action.MenuData;+import ghidra.app.decompiler.ClangToken;+import ghidra.app.decompiler.component.*;+import ghidra.app.plugin.core.decompile.DecompilerActionContext;+import ghidra.program.model.pcode.Varnode;-public class HighlightDefinedUseAction extends DockingAction {+public class HighlightDefinedUseAction extends AbstractDecompilerAction {private final DecompilerController controller;- public HighlightDefinedUseAction(String owner, DecompilerController controller) {- super("Highlight Defined Use", owner);+ public HighlightDefinedUseAction(DecompilerController controller) {+ super("Highlight Defined Use");this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Highlight Def-use" }, "Decompile"));}@Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -61,17 +41,7 @@ public class HighlightDefinedUseAction extends DockingAction {}@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-+ protected void decompilerActionPerformed(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();Varnode varnode = DecompilerUtils.getVarnodeRef(tokenAtCursor);@@ -79,7 +49,9 @@ public class HighlightDefinedUseAction extends DockingAction {HashSet<Varnode> varnodes = new HashSet<Varnode>();varnodes.add(varnode);decompilerPanel.clearHighlights();- decompilerPanel.addVarnodeHighlights(varnodes, decompilerPanel.getDefaultHighlightColor(),varnode,varnode.getDef(),decompilerPanel.getDefaultSpecialColor());+ decompilerPanel.addVarnodeHighlights(varnodes,+ decompilerPanel.getDefaultHighlightColor(), varnode, varnode.getDef(),+ decompilerPanel.getDefaultSpecialColor());decompilerPanel.repaint();}}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/OverridePrototypeAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/OverridePrototypeAction.javaindex fd8c12f395..240fbbcca2 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/OverridePrototypeAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/OverridePrototypeAction.java@@ -15,6 +15,10 @@*/package ghidra.app.plugin.core.decompile.actions;+import java.util.Iterator;++import docking.action.MenuData;+import docking.widgets.OptionDialog;import ghidra.app.decompiler.*;import ghidra.app.decompiler.component.DecompilerController;import ghidra.app.decompiler.component.DecompilerPanel;@@ -28,14 +32,7 @@ import ghidra.program.model.pcode.*;import ghidra.util.Msg;import ghidra.util.UndefinedFunction;-import java.util.Iterator;--import docking.ActionContext;-import docking.action.DockingAction;-import docking.action.MenuData;-import docking.widgets.OptionDialog;--public class OverridePrototypeAction extends DockingAction {+public class OverridePrototypeAction extends AbstractDecompilerAction {private final DecompilerController controller;private final PluginTool tool;@@ -60,8 +57,9 @@ public class OverridePrototypeAction extends DockingAction {@Overrideprotected void okCallback() {// only close the dialog if the user made valid changes- if (testResult())+ if (testResult()) {close();+ }}protected boolean testResult() {@@ -79,96 +77,16 @@ public class OverridePrototypeAction extends DockingAction {}}- public OverridePrototypeAction(String owner, PluginTool tool, DecompilerController controller) {- super("Override Signature", owner);+ public OverridePrototypeAction(PluginTool tool, DecompilerController controller) {+ super("Override Signature");this.tool = tool;this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Override Signature" }, "Decompile"));}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- Function function = controller.getFunction();- if (function == null || function instanceof UndefinedFunction) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-- return getCallOp(controller) != null;- }-- @Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-- Function func = controller.getFunction();- Program program = func.getProgram();- PcodeOp op = getCallOp(controller);- Function calledfunc = getCalledFunction(op);- boolean varargs = false;- if (calledfunc != null)- varargs = calledfunc.hasVarArgs();- if ((op.getOpcode() == PcodeOp.CALL) && !varargs) {- if (OptionDialog.showOptionDialog(- controller.getDecompilerPanel(),- "Warning : Localized Override",- "Incorrect information entered here may hide other good information.\n"- + "For direct calls, it is usually better to alter the prototype on the function\n"- + "itself, rather than overriding the local call. Proceed anyway?", "Proceed") != 1)- return;- }- Address addr = op.getSeqnum().getTarget();- String name = "func"; // Default if we don't have a real name- String conv = program.getCompilerSpec().getDefaultCallingConvention().getName();- if (calledfunc != null) {- name = calledfunc.getName();- conv = calledfunc.getCallingConventionName();- }-- String signature = generateSignature(op, name);- ProtoOverrideDialog dialog = new ProtoOverrideDialog(tool, func, signature, conv);- // dialog.setHelpLocation( new HelpLocation( getOwner(), "Edit_Function_Signature" ) );- tool.showDialog(dialog);- FunctionDefinition fdef = dialog.getFunctionDefinition();- if (fdef == null)- return;- int transaction = program.startTransaction("Override Signature");- boolean commit = false;- try {- HighFunctionDBUtil.writeOverride(func, addr, fdef);- commit = true;- }- catch (Exception e) {- Msg.showError(getClass(), controller.getDecompilerPanel(), "Override Signature Failed",- "Error overriding signature: " + e);- }- finally {- program.endTransaction(transaction, commit);- }- }-/*** Try to find the PcodeOp representing the call the user has selected+ * @param controller the decompiler controller* @return the PcodeOp or null*/public static PcodeOp getCallOp(DecompilerController controller) {@@ -182,30 +100,36 @@ public class OverridePrototypeAction extends DockingAction {}Address addr = tokenAtCursor.getMinAddress();- if (addr == null)+ if (addr == null) {return null;+ }Instruction instr = controller.getProgram().getListing().getInstructionAt(addr);- if (instr == null)+ if (instr == null) {return null;- if (!instr.getFlowType().isCall())+ }+ if (!instr.getFlowType().isCall()) {return null;+ }ClangFunction cfunc = tokenAtCursor.getClangFunction();- if (cfunc == null)+ if (cfunc == null) {return null;+ }HighFunction hfunc = cfunc.getHighFunction();Iterator<PcodeOpAST> iter = hfunc.getPcodeOps(addr);while (iter.hasNext()) {PcodeOpAST op = iter.next();- if ((op.getOpcode() == PcodeOp.CALL) || (op.getOpcode() == PcodeOp.CALLIND))+ if ((op.getOpcode() == PcodeOp.CALL) || (op.getOpcode() == PcodeOp.CALLIND)) {return op;+ }}return null;}private Function getCalledFunction(PcodeOp op) {- if (op.getOpcode() != PcodeOp.CALL)+ if (op.getOpcode() != PcodeOp.CALL) {return null;+ }Address addr = op.getInput(0).getAddress();Program program = controller.getProgram();return program.getFunctionManager().getFunctionAt(addr);@@ -218,25 +142,92 @@ public class OverridePrototypeAction extends DockingAction {if (vn != null) {dt = vn.getHigh().getDataType();}- if (dt != null)+ if (dt != null) {buf.append(dt.getDisplayName());- else+ }+ else {buf.append(DataType.VOID.getDisplayName());+ }buf.append(' ').append(name).append('(');for (int i = 1; i < op.getNumInputs(); ++i) {vn = op.getInput(i);dt = null;- if (vn != null)+ if (vn != null) {dt = vn.getHigh().getDataType();- if (dt != null)+ }+ if (dt != null) {buf.append(dt.getDisplayName());- else+ }+ else {buf.append("BAD");- if (i != op.getNumInputs() - 1)+ }+ if (i != op.getNumInputs() - 1) {buf.append(',');+ }}buf.append(')');return buf.toString();}++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {+ Function function = controller.getFunction();+ if (function == null || function instanceof UndefinedFunction) {+ return false;+ }++ return getCallOp(controller) != null;+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {+ Function func = controller.getFunction();+ Program program = func.getProgram();+ PcodeOp op = getCallOp(controller);+ Function calledfunc = getCalledFunction(op);+ boolean varargs = false;+ if (calledfunc != null) {+ varargs = calledfunc.hasVarArgs();+ }+ if ((op.getOpcode() == PcodeOp.CALL) && !varargs) {+ if (OptionDialog.showOptionDialog(controller.getDecompilerPanel(),+ "Warning : Localized Override",+ "Incorrect information entered here may hide other good information.\n" ++ "For direct calls, it is usually better to alter the prototype on the function\n" ++ "itself, rather than overriding the local call. Proceed anyway?",+ "Proceed") != 1) {+ return;+ }+ }+ Address addr = op.getSeqnum().getTarget();+ String name = "func"; // Default if we don't have a real name+ String conv = program.getCompilerSpec().getDefaultCallingConvention().getName();+ if (calledfunc != null) {+ name = calledfunc.getName();+ conv = calledfunc.getCallingConventionName();+ }++ String signature = generateSignature(op, name);+ ProtoOverrideDialog dialog = new ProtoOverrideDialog(tool, func, signature, conv);+ // dialog.setHelpLocation( new HelpLocation( getOwner(), "Edit_Function_Signature" ) );+ tool.showDialog(dialog);+ FunctionDefinition fdef = dialog.getFunctionDefinition();+ if (fdef == null) {+ return;+ }+ int transaction = program.startTransaction("Override Signature");+ boolean commit = false;+ try {+ HighFunctionDBUtil.writeOverride(func, addr, fdef);+ commit = true;+ }+ catch (Exception e) {+ Msg.showError(getClass(), controller.getDecompilerPanel(), "Override Signature Failed",+ "Error overriding signature: " + e);+ }+ finally {+ program.endTransaction(transaction, commit);+ }+ }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameFunctionAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameFunctionAction.javaindex 48e1e513c9..acbd928770 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameFunctionAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameFunctionAction.java@@ -17,8 +17,8 @@ package ghidra.app.plugin.core.decompile.actions;import java.awt.event.KeyEvent;-import docking.ActionContext;-import docking.action.*;+import docking.action.KeyBindingData;+import docking.action.MenuData;import ghidra.app.decompiler.ClangFuncNameToken;import ghidra.app.decompiler.ClangToken;import ghidra.app.decompiler.component.*;@@ -26,16 +26,15 @@ import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.app.util.AddEditDialog;import ghidra.framework.plugintool.PluginTool;import ghidra.program.model.listing.Function;-import ghidra.util.Msg;import ghidra.util.UndefinedFunction;-public class RenameFunctionAction extends DockingAction {+public class RenameFunctionAction extends AbstractDecompilerAction {private final DecompilerController controller;private final PluginTool tool;- public RenameFunctionAction(String owner, PluginTool tool, DecompilerController controller) {- super("Rename Function", owner);+ public RenameFunctionAction(PluginTool tool, DecompilerController controller) {+ super("Rename Function");this.tool = tool;this.controller = controller;@@ -43,42 +42,6 @@ public class RenameFunctionAction extends DockingAction {setPopupMenuData(new MenuData(new String[] { "Rename Function" }, "Decompile"));}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-- Function func = getFunction();- return func != null && !(func instanceof UndefinedFunction);- }-- @Override- public void actionPerformed(ActionContext context) {-- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(),- context.getComponentProvider().getComponent(),- "Decompiler Action Blocked", "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-- Function function = getFunction();- AddEditDialog dialog = new AddEditDialog("Edit Function Name", tool);- dialog.editLabel(function.getSymbol(), controller.getProgram());- }-private Function getFunction() {// try to look up the function that is at the current cursor location// If there isn't one, just use the function we are in.@@ -90,4 +53,17 @@ public class RenameFunctionAction extends DockingAction {}return null;}++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {+ Function func = getFunction();+ return func != null && !(func instanceof UndefinedFunction);+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {+ Function function = getFunction();+ AddEditDialog dialog = new AddEditDialog("Edit Function Name", tool);+ dialog.editLabel(function.getSymbol(), controller.getProgram());+ }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameVariableAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameVariableAction.javaindex 0168c6074e..f23e48f8bd 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameVariableAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RenameVariableAction.java@@ -15,6 +15,10 @@*/package ghidra.app.plugin.core.decompile.actions;+import java.awt.event.KeyEvent;++import docking.action.KeyBindingData;+import docking.action.MenuData;import ghidra.app.decompiler.*;import ghidra.app.decompiler.component.DecompilerController;import ghidra.app.decompiler.component.DecompilerPanel;@@ -31,84 +35,19 @@ import ghidra.util.UndefinedFunction;import ghidra.util.exception.DuplicateNameException;import ghidra.util.exception.InvalidInputException;-import java.awt.event.KeyEvent;--import docking.ActionContext;-import docking.action.*;--public class RenameVariableAction extends DockingAction {+public class RenameVariableAction extends AbstractDecompilerAction {private final DecompilerController controller;private final PluginTool tool;private RenameTask nameTask = null;- public RenameVariableAction(String owner, PluginTool tool, DecompilerController controller) {- super("Rename Variable", owner);+ public RenameVariableAction(PluginTool tool, DecompilerController controller) {+ super("Rename Variable");this.tool = tool;this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Rename Variable" }, "Decompile"));setKeyBindingData(new KeyBindingData(KeyEvent.VK_L, 0));}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- Function function = controller.getFunction();- if (function instanceof UndefinedFunction) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();- ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();- if (tokenAtCursor == null) {- return false;- }- if (tokenAtCursor instanceof ClangFieldToken) {- DataType dt = getStructDataType(tokenAtCursor);- if (dt == null) {- return false;- }- getPopupMenuData().setMenuItemName("Rename Field");- return true;- }- HighVariable variable = tokenAtCursor.getHighVariable();- if (variable == null) {- // not sure why variables with an & in front of them have no highVariable- Address storageAddress = getStorageAddress(tokenAtCursor, controller);- if (storageAddress == null) {- return false;- }- variable = forgeHighVariable(storageAddress, controller);- if (variable == null)- return false;- }- if (variable instanceof HighLocal) {- getPopupMenuData().setMenuItemName("Rename Variable");- return true;- }- else if (variable instanceof HighGlobal) {- getPopupMenuData().setMenuItemName("Rename Global");- return true;- }-// TODO: Constant equates do not work properly with decompiler-// else if (variable instanceof HighConstant) {-// getPopupMenuData().setMenuItemName("Rename Constant");-// return true;-// }- return false;- }-public static Address getStorageAddress(ClangToken tokenAtCursor,DecompilerController controller) {Varnode vnode = tokenAtCursor.getVarnode();@@ -149,17 +88,17 @@ public class RenameVariableAction extends DockingAction {if (addr.isStackAddress()) {LocalSymbolMap lsym = hfunc.getLocalSymbolMap();HighSymbol hsym = lsym.findLocal(addr, null);- if (hsym != null)+ if (hsym != null) {res = hsym.getHighVariable();+ }}else {Data data = program.getListing().getDataAt(addr);if (data != null) {DataType dt = data.getDataType();try {- res =- new HighGlobal(data.getLabel(), dt, new Varnode(addr, dt.getLength()),- null, hfunc);+ res = new HighGlobal(data.getLabel(), dt, new Varnode(addr, dt.getLength()),+ null, hfunc);}catch (InvalidInputException e) {Msg.error(RenameVariableAction.class, e.getMessage());@@ -169,18 +108,87 @@ public class RenameVariableAction extends DockingAction {return res;}+ /**+ * Get the structure associated with a field token+ * @param tok is the token representing a field+ * @return the structure which contains this field+ */+ public static Structure getStructDataType(ClangToken tok) {+ // We already know tok is a ClangFieldToken+ ClangFieldToken fieldtok = (ClangFieldToken) tok;+ DataType dt = fieldtok.getDataType();+ if (dt == null) {+ return null;+ }+ if (dt instanceof TypeDef) {+ dt = ((TypeDef) dt).getBaseDataType();+ }+ if (dt instanceof Structure) {+ return (Structure) dt;+ }+ return null;+ }++ /**+ * Get the offset of the field within its structure+ * @param tok is the display token associated with the field+ * @return the offset, in bytes, of that field within its structure+ */+ public static int getDataTypeOffset(ClangToken tok) {+ // Assume tok is already vetted as a structure carrying ClangFieldToken+ return ((ClangFieldToken) tok).getOffset();+ }+@Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {+ Function function = controller.getFunction();+ if (function instanceof UndefinedFunction) {+ return false;}+ DecompilerPanel decompilerPanel = controller.getDecompilerPanel();+ ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();+ if (tokenAtCursor == null) {+ return false;+ }+ if (tokenAtCursor instanceof ClangFieldToken) {+ DataType dt = getStructDataType(tokenAtCursor);+ if (dt == null) {+ return false;+ }+ getPopupMenuData().setMenuItemName("Rename Field");+ return true;+ }+ HighVariable variable = tokenAtCursor.getHighVariable();+ if (variable == null) {+ // not sure why variables with an & in front of them have no highVariable+ Address storageAddress = getStorageAddress(tokenAtCursor, controller);+ if (storageAddress == null) {+ return false;+ }+ variable = forgeHighVariable(storageAddress, controller);+ if (variable == null) {+ return false;+ }+ }+ if (variable instanceof HighLocal) {+ getPopupMenuData().setMenuItemName("Rename Variable");+ return true;+ }+ else if (variable instanceof HighGlobal) {+ getPopupMenuData().setMenuItemName("Rename Global");+ return true;+ }+//TODO: Constant equates do not work properly with decompiler+// else if (variable instanceof HighConstant) {+// getPopupMenuData().setMenuItemName("Rename Constant");+// return true;+// }+ return false;+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {DecompilerPanel decompilerPanel = controller.getDecompilerPanel();final ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();HighVariable variable = tokenAtCursor.getHighVariable();@@ -191,13 +199,13 @@ public class RenameVariableAction extends DockingAction {variable = forgeHighVariable(addr, controller);}}-// TODO: Constant equates do not work properly with decompiler-// if (variable instanceof HighConstant) {-// nameTask =-// new RenameConstantTask(tool, tokenAtCursor.getText(), (HighConstant) variable,-// controller.getProgram());-// }-// else+//TODO: Constant equates do not work properly with decompiler+// if (variable instanceof HighConstant) {+// nameTask =+// new RenameConstantTask(tool, tokenAtCursor.getText(), (HighConstant) variable,+// controller.getProgram());+// }+// elseif (variable instanceof HighLocal) {nameTask =new RenameVariableTask(tool, variable.getName(), controller.getHighFunction(),@@ -210,9 +218,8 @@ public class RenameVariableAction extends DockingAction {"Memory storage not found for global variable");return;}- nameTask =- new RenameGlobalVariableTask(tool, tokenAtCursor.getText(), addr,- controller.getProgram());+ nameTask = new RenameGlobalVariableTask(tool, tokenAtCursor.getText(), addr,+ controller.getProgram());}else if (tokenAtCursor instanceof ClangFieldToken) {Structure dt = getStructDataType(tokenAtCursor);@@ -255,32 +262,4 @@ public class RenameVariableAction extends DockingAction {}}}-- /**- * Get the structure associated with a field token- * @param tok is the token representing a field- * @return the structure which contains this field- */- public static Structure getStructDataType(ClangToken tok) {- // We already know tok is a ClangFieldToken- ClangFieldToken fieldtok = (ClangFieldToken) tok;- DataType dt = fieldtok.getDataType();- if (dt == null)- return null;- if (dt instanceof TypeDef)- dt = ((TypeDef) dt).getBaseDataType();- if (dt instanceof Structure)- return (Structure) dt;- return null;- }-- /**- * Get the offset of the field within its structure- * @param tok is the display token associated with the field- * @return the offset, in bytes, of that field within its structure- */- public static int getDataTypeOffset(ClangToken tok) {- // Assume tok is already vetted as a structure carrying ClangFieldToken- return ((ClangFieldToken) tok).getOffset();- }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RetypeVariableAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RetypeVariableAction.javaindex 12b42dd2e7..74f6ee2ef8 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RetypeVariableAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RetypeVariableAction.java@@ -18,8 +18,8 @@ package ghidra.app.plugin.core.decompile.actions;import java.awt.event.InputEvent;import java.awt.event.KeyEvent;-import docking.ActionContext;-import docking.action.*;+import docking.action.KeyBindingData;+import docking.action.MenuData;import docking.widgets.OptionDialog;import ghidra.app.decompiler.*;import ghidra.app.decompiler.component.DecompilerController;@@ -37,12 +37,12 @@ import ghidra.util.UndefinedFunction;import ghidra.util.data.DataTypeParser.AllowedDataTypes;import ghidra.util.exception.*;-public class RetypeVariableAction extends DockingAction {+public class RetypeVariableAction extends AbstractDecompilerAction {private final DecompilerController controller;private final PluginTool tool;- public RetypeVariableAction(String owner, PluginTool tool, DecompilerController controller) {- super("Retype Variable", owner);+ public RetypeVariableAction(PluginTool tool, DecompilerController controller) {+ super("Retype Variable");this.tool = tool;this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Retype Variable" }, "Decompile"));@@ -50,146 +50,6 @@ public class RetypeVariableAction extends DockingAction {}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- Function function = controller.getFunction();- if (function instanceof UndefinedFunction) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();- ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();- if (tokenAtCursor == null) {- return false;- }- if (tokenAtCursor instanceof ClangFieldToken) {- DataType dt = RenameVariableAction.getStructDataType(tokenAtCursor);- if (dt == null) {- return false;- }- getPopupMenuData().setMenuItemName("Retype Field");- return true;- }- if (tokenAtCursor.Parent() instanceof ClangReturnType) {- getPopupMenuData().setMenuItemName("Retype Return");- return true;- }- if (!tokenAtCursor.isVariableRef()) {- return false;- }- HighVariable variable = tokenAtCursor.getHighVariable();- if (variable == null) {- Address addr = RenameVariableAction.getStorageAddress(tokenAtCursor, controller);- if (addr == null) {- return false;- }- variable = RenameVariableAction.forgeHighVariable(addr, controller);- if (variable == null) {- return false;- }- }- if (variable instanceof HighConstant) {-// getPopupMenuData().setMenuItemName("Retype Constant");-// return true;- }- else if (variable instanceof HighLocal) {- getPopupMenuData().setMenuItemName("Retype Variable");- return true;- }- else if (variable instanceof HighGlobal) {- getPopupMenuData().setMenuItemName("Retype Global");- return true;- }- return false;- }-- @Override- public void actionPerformed(ActionContext context) {- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-- DecompilerPanel decompilerPanel = controller.getDecompilerPanel();- ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();- HighVariable variable = null;- Structure struct = null;- DataTypeComponent comp = null;-- DataType dataType = null;- if (tokenAtCursor instanceof ClangFieldToken) {- struct = RenameVariableAction.getStructDataType(tokenAtCursor);- int offset = RenameVariableAction.getDataTypeOffset(tokenAtCursor);- if (struct == null) {- Msg.showError(this, tool.getToolFrame(), "Retype Failed",- "Failed to re-type structure");- return;- }- if (offset < 0 || offset >= struct.getLength()) {- Msg.showError(this, tool.getToolFrame(), "Retype Failed",- "Failed to re-type structure: " + struct.getName());- return;- }- comp = struct.getComponentAt(offset);- if (comp == null) {- dataType = chooseDataType(DataType.DEFAULT);- }- else {- dataType = chooseDataType(comp.getDataType());- }- }- else if (tokenAtCursor.Parent() instanceof ClangReturnType) {- ClangReturnType parent = (ClangReturnType) tokenAtCursor.Parent();- dataType = chooseDataType(parent.getDataType());- if (dataType == null) {- return;- }- retypeReturnType(dataType, parent);- return;- }- else {- variable = tokenAtCursor.getHighVariable();- if (variable == null) {- Address addr = RenameVariableAction.getStorageAddress(tokenAtCursor, controller);- if (addr == null) {- return;- }- variable = RenameVariableAction.forgeHighVariable(addr, controller);- if (variable == null) {- return;- }- }- dataType = chooseDataType(variable.getDataType());- }- if (dataType == null) {- return;- }- if (struct != null) {- retypeStructVariable(struct, comp, dataType);- }- else {- retypeVariable(variable, tokenAtCursor.getVarnode(), dataType);- }- }-private void retypeReturnType(DataType dataType, ClangReturnType parent) {Program program = controller.getProgram();DataTypeManager dataTypeManager = program.getDataTypeManager();@@ -199,12 +59,10 @@ public class RetypeVariableAction extends DockingAction {}boolean commitRequired = checkFullCommit(null, hfunction);if (commitRequired) {- int resp =- OptionDialog.showOptionDialog(- tool.getToolFrame(),- "Parameter Commit Required",- "Retyping the return value requires all other parameters to be committed!\nContinue with retype?",- "Continue");+ int resp = OptionDialog.showOptionDialog(tool.getToolFrame(),+ "Parameter Commit Required",+ "Retyping the return value requires all other parameters to be committed!\nContinue with retype?",+ "Continue");if (resp != OptionDialog.OPTION_ONE) {return;}@@ -259,9 +117,8 @@ public class RetypeVariableAction extends DockingAction {private DataType chooseDataType(DataType currentDataType) {Program program = controller.getProgram();DataTypeManager dataTypeManager = program.getDataTypeManager();- DataTypeSelectionDialog chooserDialog =- new DataTypeSelectionDialog(tool, dataTypeManager, Integer.MAX_VALUE,- AllowedDataTypes.FIXED_LENGTH);+ DataTypeSelectionDialog chooserDialog = new DataTypeSelectionDialog(tool, dataTypeManager,+ Integer.MAX_VALUE, AllowedDataTypes.FIXED_LENGTH);chooserDialog.setInitialDataType(currentDataType);tool.showDialog(chooserDialog);return chooserDialog.getUserChosenDataType();@@ -272,12 +129,10 @@ public class RetypeVariableAction extends DockingAction {boolean commitRequired = checkFullCommit(var, hfunction);if (commitRequired) {- int resp =- OptionDialog.showOptionDialog(- tool.getToolFrame(),- "Parameter Commit Required",- "Retyping a parameter requires all other parameters to be committed!\nContinue with retype?",- "Continue");+ int resp = OptionDialog.showOptionDialog(tool.getToolFrame(),+ "Parameter Commit Required",+ "Retyping a parameter requires all other parameters to be committed!\nContinue with retype?",+ "Continue");if (resp != OptionDialog.OPTION_ONE) {return;}@@ -372,7 +227,7 @@ public class RetypeVariableAction extends DockingAction {if (comp == null) {if (!dt.isNotYetDefined()) {Msg.showError(this, tool.getToolFrame(), "Retype Failed",- "Could not find component of '" + dt.getName() + "' to retype");+ "Could not find component of '" + dt.getName() + "' to retype");return;}// note if we reach here the offset must be zero, so assume we are inserting newtype@@ -467,4 +322,122 @@ public class RetypeVariableAction extends DockingAction {return false;}++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {+ Function function = controller.getFunction();+ if (function instanceof UndefinedFunction) {+ return false;+ }++ DecompilerPanel decompilerPanel = controller.getDecompilerPanel();+ ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();+ if (tokenAtCursor == null) {+ return false;+ }+ if (tokenAtCursor instanceof ClangFieldToken) {+ DataType dt = RenameVariableAction.getStructDataType(tokenAtCursor);+ if (dt == null) {+ return false;+ }+ getPopupMenuData().setMenuItemName("Retype Field");+ return true;+ }+ if (tokenAtCursor.Parent() instanceof ClangReturnType) {+ getPopupMenuData().setMenuItemName("Retype Return");+ return true;+ }+ if (!tokenAtCursor.isVariableRef()) {+ return false;+ }+ HighVariable variable = tokenAtCursor.getHighVariable();+ if (variable == null) {+ Address addr = RenameVariableAction.getStorageAddress(tokenAtCursor, controller);+ if (addr == null) {+ return false;+ }+ variable = RenameVariableAction.forgeHighVariable(addr, controller);+ if (variable == null) {+ return false;+ }+ }+ if (variable instanceof HighConstant) {+// getPopupMenuData().setMenuItemName("Retype Constant");+// return true;+ }+ else if (variable instanceof HighLocal) {+ getPopupMenuData().setMenuItemName("Retype Variable");+ return true;+ }+ else if (variable instanceof HighGlobal) {+ getPopupMenuData().setMenuItemName("Retype Global");+ return true;+ }+ return false;+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {+ DecompilerPanel decompilerPanel = controller.getDecompilerPanel();+ ClangToken tokenAtCursor = decompilerPanel.getTokenAtCursor();+ HighVariable variable = null;+ Structure struct = null;+ DataTypeComponent comp = null;++ DataType dataType = null;+ if (tokenAtCursor instanceof ClangFieldToken) {+ struct = RenameVariableAction.getStructDataType(tokenAtCursor);+ int offset = RenameVariableAction.getDataTypeOffset(tokenAtCursor);+ if (struct == null) {+ Msg.showError(this, tool.getToolFrame(), "Retype Failed",+ "Failed to re-type structure");+ return;+ }+ if (offset < 0 || offset >= struct.getLength()) {+ Msg.showError(this, tool.getToolFrame(), "Retype Failed",+ "Failed to re-type structure: " + struct.getName());+ return;+ }+ comp = struct.getComponentAt(offset);+ if (comp == null) {+ dataType = chooseDataType(DataType.DEFAULT);+ }+ else {+ dataType = chooseDataType(comp.getDataType());+ }+ }+ else if (tokenAtCursor.Parent() instanceof ClangReturnType) {+ ClangReturnType parent = (ClangReturnType) tokenAtCursor.Parent();+ dataType = chooseDataType(parent.getDataType());+ if (dataType == null) {+ return;+ }+ retypeReturnType(dataType, parent);+ return;+ }+ else {+ variable = tokenAtCursor.getHighVariable();+ if (variable == null) {+ Address addr = RenameVariableAction.getStorageAddress(tokenAtCursor, controller);+ if (addr == null) {+ return;+ }+ variable = RenameVariableAction.forgeHighVariable(addr, controller);+ if (variable == null) {+ return;+ }+ }+ dataType = chooseDataType(variable.getDataType());+ }++ if (dataType == null) {+ return;+ }+ if (struct != null) {+ retypeStructVariable(struct, comp, dataType);+ }+ else {+ retypeVariable(variable, tokenAtCursor.getVarnode(), dataType);+ }+ }}diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SpecifyCPrototypeAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SpecifyCPrototypeAction.javaindex 99474e10d9..5967d60b5d 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SpecifyCPrototypeAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/SpecifyCPrototypeAction.java@@ -17,8 +17,6 @@ package ghidra.app.plugin.core.decompile.actions;import java.util.List;-import docking.ActionContext;-import docking.action.DockingAction;import docking.action.MenuData;import ghidra.app.decompiler.ClangFuncNameToken;import ghidra.app.decompiler.ClangToken;@@ -32,91 +30,19 @@ import ghidra.program.model.listing.Function;import ghidra.program.model.listing.VariableStorage;import ghidra.program.model.pcode.*;import ghidra.program.model.symbol.SourceType;-import ghidra.util.Msg;import ghidra.util.UndefinedFunction;-public class SpecifyCPrototypeAction extends DockingAction {+public class SpecifyCPrototypeAction extends AbstractDecompilerAction {private final DecompilerController controller;private final PluginTool tool;- //private FunctionSignature signature = null;- //private String callingConventionName = null;- public SpecifyCPrototypeAction(String owner, PluginTool tool, DecompilerController controller) {- super("Edit Function Signature", owner);+ public SpecifyCPrototypeAction(PluginTool tool, DecompilerController controller) {+ super("Edit Function Signature");this.tool = tool;this.controller = controller;setPopupMenuData(new MenuData(new String[] { "Edit Function Signature" }, "Decompile"));}- @Override- public boolean isEnabledForContext(ActionContext context) {- if (!(context instanceof DecompilerActionContext)) {- return false;- }-- Function function = controller.getFunction();- if (function instanceof UndefinedFunction) {- return false;- }-- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- // Let this through here and handle it in actionPerformed(). This lets us alert- // the user that they have to wait until the decompile is finished. If we are not- // enabled at this point, then the keybinding will be propagated to the global- // actions, which is not what we want.- return true;- }-- return getFunction() != null;- }-- @Override- public void actionPerformed(ActionContext context) {-- // Note: we intentionally do this check here and not in isEnabledForContext() so- // that global events do not get triggered.- DecompilerActionContext decompilerActionContext = (DecompilerActionContext) context;- if (decompilerActionContext.isDecompiling()) {- Msg.showInfo(getClass(), context.getComponentProvider().getComponent(),- "Decompiler Action Blocked",- "You cannot perform Decompiler actions while the Decompiler is busy");- return;- }-- Function function = getFunction();- DataTypeManagerService service = tool.getService(DataTypeManagerService.class);-- FunctionEditorModel model = new FunctionEditorModel(service, function);-- HighFunction hf = controller.getHighFunction();- FunctionPrototype functionPrototype = hf.getFunctionPrototype();-- // If editing the decompiled function (i.e., not a subfunction) and function- // is not fully locked update the model to reflect the decompiled results- if (function.getEntryPoint().equals(hf.getFunction().getEntryPoint())) {- if (function.getSignatureSource() == SourceType.DEFAULT) {- model.setUseCustomizeStorage(false);- model.setCallingConventionName(functionPrototype.getModelName());- model.setFunctionData(buildSignature(hf));- verifyDynamicEditorModel(hf, model);- }- else if (function.getReturnType() == DataType.DEFAULT) {- model.setFormalReturnType(functionPrototype.getReturnType());- if (model.canCustomizeStorage()) {- model.setReturnStorage(functionPrototype.getReturnStorage());- }- }- }-- // make the model think it is not changed, so if the user doesn't change anything,- // we don't save the changes made above.- model.setModelChanged(false);-- FunctionEditorDialog dialog = new FunctionEditorDialog(model);- tool.showDialog(dialog, context.getComponentProvider());- }-/*** Verify and adjust function editor model using dynamic storage to reflect current state of* decompiled results. It may be necessary to switch model to use custom storage.@@ -224,4 +150,49 @@ public class SpecifyCPrototypeAction extends DockingAction {}return function;}++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {+ Function function = controller.getFunction();+ if (function instanceof UndefinedFunction) {+ return false;+ }++ return getFunction() != null;+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {+ Function function = getFunction();+ DataTypeManagerService service = tool.getService(DataTypeManagerService.class);++ FunctionEditorModel model = new FunctionEditorModel(service, function);++ HighFunction hf = controller.getHighFunction();+ FunctionPrototype functionPrototype = hf.getFunctionPrototype();++ // If editing the decompiled function (i.e., not a subfunction) and function+ // is not fully locked update the model to reflect the decompiled results+ if (function.getEntryPoint().equals(hf.getFunction().getEntryPoint())) {+ if (function.getSignatureSource() == SourceType.DEFAULT) {+ model.setUseCustomizeStorage(false);+ model.setCallingConventionName(functionPrototype.getModelName());+ model.setFunctionData(buildSignature(hf));+ verifyDynamicEditorModel(hf, model);+ }+ else if (function.getReturnType() == DataType.DEFAULT) {+ model.setFormalReturnType(functionPrototype.getReturnType());+ if (model.canCustomizeStorage()) {+ model.setReturnStorage(functionPrototype.getReturnStorage());+ }+ }+ }++ // make the model think it is not changed, so if the user doesn't change anything,+ // we don't save the changes made above.+ model.setModelChanged(false);++ FunctionEditorDialog dialog = new FunctionEditorDialog(model);+ tool.showDialog(dialog, context.getComponentProvider());+ }}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/ShowComponentAction.java b/Ghidra/Framework/Docking/src/main/java/docking/ShowComponentAction.javaindex 813c3a8b1e..e4e4db36fd 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/ShowComponentAction.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/ShowComponentAction.java@@ -60,7 +60,6 @@ class ShowComponentAction extends DockingActionthis.info = placeholder;this.winMgr = winMgr;this.title = truncateTitleAsNeeded(placeholder.getTitle());- String group = isTransient ? "Transient" : "Permanent";Icon icon = placeholder.getIcon();if (icon == null) {@@ -71,7 +70,6 @@ class ShowComponentAction extends DockingActionsetMenuBarData(new MenuData(new String[] { MENU_WINDOW, subMenuName, placeholder.getFullTitle() },icon, "Permanent"));- winMgr.doSetMenuGroup(new String[] { MENU_WINDOW, subMenuName }, group);}else {setMenuBarData(new MenuData(new String[] { MENU_WINDOW, title }, icon, "Permanent"));diff --git a/Ghidra/Framework/Docking/src/main/java/docking/action/DockingAction.java b/Ghidra/Framework/Docking/src/main/java/docking/action/DockingAction.javaindex ffbbd2d299..519aaed902 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/action/DockingAction.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/action/DockingAction.java@@ -396,7 +396,7 @@ public abstract class DockingAction implements DockingActionIf {buffer.append(" MENU GROUP: ").append(menuBarData.getMenuGroup());buffer.append('\n');- String parentGroup = popupMenuData.getParentMenuGroup();+ String parentGroup = menuBarData.getParentMenuGroup();if (parentGroup != null) {buffer.append(" PARENT GROUP: ").append(parentGroup);buffer.append('\n');diff --git a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.java b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.javaindex 4796e01f6f..99edf3955f 100644--- a/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.java+++ b/Ghidra/Framework/Project/src/main/java/ghidra/framework/plugintool/mgr/ToolTaskManager.java@@ -404,7 +404,7 @@ public class ToolTaskManager implements Runnable {}task.getCommand().taskCompleted();double totalTime = (System.currentTimeMillis() - start_time) / 1000.00;- Msg.debug(this, " task Complete (" + totalTime + " secs)");+ Msg.debug(this, " task complete (" + totalTime + " secs)");}/**