Ghidra is a software reverse engineering (SRE) framework
GP-1383 - Added the ability to remove a non-default symbol by setting the Edit Label dialog text to the empty string; added an action to the decompiler to remove non-default labels.
dragonmacher815c6f8bc075
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/RecentlyUsedAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/RecentlyUsedAction.javaindex caec96727e..5fd27c86e4 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/RecentlyUsedAction.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/data/RecentlyUsedAction.java@@ -39,7 +39,7 @@ public class RecentlyUsedAction extends DataAction {@Overrideprotected KeyStroke getDefaultKeyStroke() {- return DEFAULT_KEY_STROKE; // we have no default, but our subclasses may+ return DEFAULT_KEY_STROKE;}@Override@@ -62,7 +62,7 @@ public class RecentlyUsedAction extends DataAction {}this.dataType = recentDataType;-+boolean enabled = super.isEnabledForContext(context);return enabled;}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/disassembler/X86_64DisassembleAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/disassembler/X86_64DisassembleAction.javaindex 04eac18b94..a67a9d0740 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/disassembler/X86_64DisassembleAction.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/disassembler/X86_64DisassembleAction.java@@ -26,6 +26,7 @@ import ghidra.program.model.address.Address;import ghidra.program.model.lang.Language;import ghidra.program.model.lang.Processor;import ghidra.program.model.listing.Program;+import ghidra.util.HelpLocation;public class X86_64DisassembleAction extends ListingContextAction {private final DisassemblerPlugin plugin;@@ -42,6 +43,11 @@ public class X86_64DisassembleAction extends ListingContextAction {int keyEvent = (disassemble32Bit ? KeyEvent.VK_F12 : KeyEvent.VK_F11);setKeyBindingData(new KeyBindingData(keyEvent, 0));++ // Need to override the default help location since this action doesn't have its own+ // section in the help.+ HelpLocation location = new HelpLocation("DisassemblerPlugin", "Disassemble");+ this.setHelpLocation(location);}@Overridediff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/label/RemoveLabelAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/label/RemoveLabelAction.javaindex c4ac18f512..e2b20aaae4 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/label/RemoveLabelAction.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/label/RemoveLabelAction.java@@ -42,16 +42,12 @@ class RemoveLabelAction extends ListingContextAction {* @param plugin Label Manager Plugin instance*/RemoveLabelAction(LabelMgrPlugin plugin) {- super("Remove Label", plugin.getName());+ super("Remove Label", plugin.getName(), KeyBindingType.SHARED);+ this.plugin = plugin;- // the above sets the default (preferred) values, but not the actuals- // below we indicate that the popup and keybinding are also neededsetPopupMenuData(new MenuData(POPUP_PATH, null, "Label"));setKeyBindingData(new KeyBindingData(KEYBINDING));- // Set the Group-- this.plugin = plugin;setEnabled(true);}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/AddEditDialog.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/AddEditDialog.javaindex 9263b3f9f2..b581b688fd 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/AddEditDialog.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/AddEditDialog.java@@ -26,9 +26,11 @@ import org.apache.commons.lang3.StringUtils;import docking.ComponentProvider;import docking.DialogComponentProvider;+import docking.widgets.OptionDialog;import docking.widgets.checkbox.GCheckBox;import docking.widgets.combobox.GhidraComboBox;import ghidra.app.cmd.label.*;+import ghidra.framework.cmd.Command;import ghidra.framework.cmd.CompoundCmd;import ghidra.framework.plugintool.PluginTool;import ghidra.program.database.symbol.FunctionSymbol;@@ -36,6 +38,7 @@ import ghidra.program.model.address.Address;import ghidra.program.model.listing.*;import ghidra.program.model.symbol.*;import ghidra.util.HelpLocation;+import ghidra.util.Swing;import ghidra.util.exception.AssertException;import ghidra.util.layout.VerticalLayout;@@ -145,6 +148,7 @@ public class AddEditDialog extends DialogComponentProvider {Namespace namespace = getSelectedNamespace();SymbolPath symbolPath = getSymbolPath(labelText);if (symbolPath == null) {+ Swing.runLater(() -> checkForRemoveLabel());return;}@@ -193,6 +197,46 @@ public class AddEditDialog extends DialogComponentProvider {close();}+ private void checkForRemoveLabel() {++ if (!isEditing()) {+ return; // adding a label; cannot delete existing label+ }++ if (isDefaultLabel()) {+ return; // label is already default; cannot be removed+ }++ if (isExternalLabel()) {+ return; // cannot remove external labels+ }++ int choice = OptionDialog.showYesNoDialog(getParent(), "Remove Label?",+ "You have removed the label text--would you like to remove the existing label?");+ if (choice == OptionDialog.YES_OPTION) {++ Command cmd = new DeleteLabelCmd(addr, symbol.getName(), symbol.getParentNamespace());+ if (!tool.execute(cmd, program)) {+ setStatusText(cmd.getStatusMsg());+ }+ else {+ close();+ }+ }+ }++ private boolean isExternalLabel() {+ return symbol != null && symbol.isExternal();+ }++ private boolean isDefaultLabel() {+ return symbol != null && symbol.getSource() == SourceType.DEFAULT;+ }++ private boolean isEditing() {+ return symbol != null; // always have a symbol when editing+ }+private SymbolPath getSymbolPath(String symbolName) {if (StringUtils.isBlank(symbolName)) {@@ -229,7 +273,7 @@ public class AddEditDialog extends DialogComponentProvider {//// At this point we can either reuse an existing function namespace or we have to create- // a new non-function namespaces, depending upon the names being used. Only use an+ // a new non-function namespaces, depending upon the names being used. Only use an// existing function as a namespace if none of namespace path entries match the function// name.//@@ -382,6 +426,7 @@ public class AddEditDialog extends DialogComponentProvider {throw new IllegalArgumentException("AddEditDialog.addLabel only valid for memory address");}+this.addr = address;this.program = p;SymbolTable symbolTable = p.getSymbolTable();diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/label/AddEditDialoglTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/label/AddEditDialoglTest.javaindex 5a097d98db..d3ede93d7c 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/label/AddEditDialoglTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/label/AddEditDialoglTest.java@@ -18,6 +18,7 @@ package ghidra.app.plugin.core.label;import static org.junit.Assert.*;import java.awt.Component;+import java.awt.Window;import java.util.List;import java.util.concurrent.atomic.AtomicReference;@@ -477,7 +478,6 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {assertNotNull(getUniqueSymbol(program, "zzzz", null));assertNotNull(getUniqueSymbol(program, "cccc", null));assertNull(getUniqueSymbol(program, "bbbb", null));-}@Test@@ -502,7 +502,44 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {s = getUniqueSymbol(program, "foo", st.getNamespace(a));assertNotNull(s);assertEquals("entry", s.getParentNamespace().getName());+ }++ @Test+ public void testEdit_CannotRemoveDefaultLabel() {++ Address refAddr = addr(0x10064b1);+ Symbol s = st.getPrimarySymbol(refAddr);+ editLabel(s);+ assertEquals("LAB_010064b1", getText());++ setText("");++ pressOk();++ assertStatusText("Name cannot be blank");+ }++ @Test+ public void testEdit_RemoveNonDefaultLabel() {++ Address a = addr(0x100642a);+ addLabel(a);+ String labelName = "aaaa";+ setText(labelName);+ pressOk();++ Symbol s = st.getPrimarySymbol(a);+ editLabel(s);+ assertEquals(labelName, getText());+ setText("");+ pressOk();++ Window w = waitForWindow("Remove Label?");+ pressButtonByText(w, "Yes");+ assertEditDialogVisible(false);++ assertNull(getUniqueSymbol(program, labelName, null));}@Test@@ -583,7 +620,7 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {setText("label_1");pressOk();- assertTrue("Encountered a problem adding a label to the Global " + "namespace",+ assertTrue("Encountered a problem adding a label to the Global namespace",!dialog.isVisible());// move the label to a new namespace@@ -594,7 +631,7 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {// make sure there were no problemsassertTrue(- "Encountered a problem changing a symbol's namespace " + "while editing the symbol",+ "Encountered a problem changing a symbol's namespace while editing the symbol",!dialog.isVisible());// now move that label to the Global namespace@@ -695,7 +732,7 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {@Testpublic void testSetNamespace_NonExistentNamespace_SameNameAsFunction() throws Exception {- //+ //// Test that we can create a new namespace using the dialog when:// 1) that namespace does not exist// 2) the namespace matches the existing function name@@ -721,6 +758,17 @@ public class AddEditDialoglTest extends AbstractGhidraHeadedIntegrationTest {// Private Methods//==================================================================================================+ private void assertStatusText(String expected) {+ assertEquals("Dialog status text not as expected", expected,+ runSwing(dialog::getStatusText));+ }++ private void assertEditDialogVisible(boolean visible) {+ assertEquals("Dialog " + (visible ? "not showing" : "showing") ++ "when it should be " + (visible ? "showing" : "not showing"), visible,+ runSwing(dialog::isShowing));+ }+private Symbol createOtherEntry(Address otherAddress) {Symbol dupEntry = st.getPrimarySymbol(otherAddress);assertNotNull(dupEntry);diff --git a/Ghidra/Features/Decompiler/src/main/doc/decompileplugin.xml b/Ghidra/Features/Decompiler/src/main/doc/decompileplugin.xmlindex 4b8fc27786..4bec5c8c27 100644--- a/Ghidra/Features/Decompiler/src/main/doc/decompileplugin.xml+++ b/Ghidra/Features/Decompiler/src/main/doc/decompileplugin.xml@@ -4555,6 +4555,22 @@</para></sect2>+<sect2 id="ActionRemoveLabel">+ <title>Remove Label</title>+ <para>+ Remove the label corresponding to the token under the cursor.+ </para>+ <para>+ A label can be removed by triggering this action while the corresponding label token is+ under the cursor. For more on removing labels, see+ <link xlink:href="help/topics/LabelMgrPlugin/Labels.htm#Remove_Label">Removing a Label</link>.+ </para>+ <para>+ The change will be immediately visible across all references to the label+ (including in any Decompiler, Listing, and Functions windows).+ </para>+</sect2>+<sect2 id="ActionRenameFunction"><title>Rename Function</title><para>diff --git a/Ghidra/Features/Decompiler/src/main/help/help/topics/DecompilePlugin/DecompilerWindow.html b/Ghidra/Features/Decompiler/src/main/help/help/topics/DecompilePlugin/DecompilerWindow.htmlindex e2aac0be72..d66560a87d 100644--- a/Ghidra/Features/Decompiler/src/main/help/help/topics/DecompilePlugin/DecompilerWindow.html+++ b/Ghidra/Features/Decompiler/src/main/help/help/topics/DecompilePlugin/DecompilerWindow.html@@ -18,7 +18,7 @@function in the Code Browser, then select the<span class="guiicon"><span class="inlinemediaobject"><img src="images/decompileFunction.gif" width="16" height="16"></span>- </span>�icon from the tool bar, or the+ </span>�icon from the tool bar, or the<span class="bold"><strong>Decompile</strong></span> option from the<span class="bold"><strong>Window</strong></span> menu in the tool.</p>@@ -91,7 +91,7 @@Initially pressing<span class="guiicon"><span class="inlinemediaobject"><img src="images/decompileFunction.gif" width="16" height="16"></span>- </span>�or selecting+ </span>�or selecting<span class="bold"><strong>Decompile</strong></span> from the <span class="bold"><strong>Window</strong></span> menu in the toolbrings up the <span class="emphasis"><em>main</em></span> window. The main window always displays the functionat the <span class="emphasis"><em>current address</em></span> within the Code Browser and follows as the user navigates@@ -153,7 +153,7 @@Pressing the<span class="guiicon"><span class="inlinemediaobject"><img src="images/camera-photo.png" width="16" height="16"></span>- </span>�icon+ </span>�iconin any Decompiler window's toolbar causes a <span class="emphasis"><em>Snapshot</em></span> windowto be created, which shows decompilation of the same function.Unlike the <span class="emphasis"><em>main</em></span> window however, the <span class="emphasis"><em>Snapshot</em></span> window@@ -240,7 +240,7 @@<p><span class="guiicon"><span class="inlinemediaobject"><img src="images/page_edit.png" width="16" height="16"></span>- </span>�- button+ </span>�- button</p><p>Exports the decompiled result of the current function to a file. A file chooser@@ -265,7 +265,7 @@<p><span class="guiicon"><span class="inlinemediaobject"><img src="images/camera-photo.png" width="16" height="16"></span>- </span>�- button+ </span>�- button</p><p>Creates a new <span class="emphasis"><em>Snapshot</em></span> window. The <span class="emphasis"><em>Snapshot</em></span> window@@ -282,7 +282,7 @@<p><span class="guiicon"><span class="inlinemediaobject"><img src="images/reload3.png" width="16" height="16"></span>- </span>�- button+ </span>�- button</p><p>Triggers a re-decompilation of the current function displayed in the window.@@ -310,7 +310,7 @@<p><span class="guiicon"><span class="inlinemediaobject"><img src="images/page_white_copy.png" width="16" height="16"></span>- </span>�- button+ </span>�- button</p><p>Copies the currently selected text in the Decompiler window to the clipboard.@@ -1037,6 +1037,26 @@</p></div>++<div class="sect2">+<div class="titlepage"><div><div><h3 class="title">+<a name="ActionRemoveLabel"></a>Remove Label</h3></div></div></div>++ <p>+ Remove the label corresponding to the token under the cursor.+ </p>+ <p>+ A label can be removed by triggering this action while the corresponding label token is+ under the cursor. For more on removing labels, see+ <a class="ulink" href="help/topics/LabelMgrPlugin/Labels.htm#Remove_Label" target="_top">Removing a Label</a>.+ </p>+ <p>+ The change will be immediately visible across all references to the label+ (including in any Decompiler, Listing, and Functions windows).+ </p>+</div>++<div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="ActionRenameFunction"></a>Rename Function</h3></div></div></div>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 e8b423c78c..cb1139c2f7 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@@ -152,7 +152,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter@Overridepublic boolean isSnapshot() {- // we are a snapshot when we are 'disconnected'+ // we are a snapshot when we are 'disconnected'return !isConnected();}@@ -225,7 +225,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapterif (!isConnected()) {if (program == null) {- // Special Case: this 'disconnected' provider is waiting to be initialized+ // Special Case: this 'disconnected' provider is waiting to be initialized// with the first goTo() callbackdoSetProgram(gotoProgram);}@@ -660,7 +660,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapterTokenHighlights myHighlights = myPanel.getSecondaryHighlightedTokens();newProvider.setLocation(currentLocation, myPanel.getViewerPosition());- // transfer any state after the new decompiler is initialized+ // transfer any state after the new decompiler is initializedDecompilerPanel newPanel = newProvider.getDecompilerPanel();Map<String, Color> highlightsByName = myHighlights.copyHighlightsByName();newProvider.doWheNotBusy(() -> {@@ -773,10 +773,13 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapterRenameFunctionAction renameFunctionAction = new RenameFunctionAction();setGroupInfo(renameFunctionAction, functionGroup, subGroupPosition++);- // not a function action, but it fits nicely in this group+ // not function actions, but they fit nicely in this groupRenameLabelAction renameLabelAction = new RenameLabelAction();setGroupInfo(renameLabelAction, functionGroup, subGroupPosition++);+ RemoveLabelAction removeLabelAction = new RemoveLabelAction();+ setGroupInfo(removeLabelAction, functionGroup, subGroupPosition++);+//// Variables//@@ -898,7 +901,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapter// Comments//// NOTE: this is just a placeholder to represent where the comment actions should appear- // in relation to our local actions.+ // in relation to our local actions.////@@ -911,8 +914,8 @@ public class DecompilerProvider extends NavigatableComponentProviderAdaptersetGroupInfo(findAction, searchGroup, subGroupPosition++);//- // References- //+ // References+ //// note: set the menu group so that the 'References' group is with the 'Find' actionString referencesParentGroup = searchGroup;@@ -986,6 +989,7 @@ public class DecompilerProvider extends NavigatableComponentProviderAdapteraddLocalAction(deleteSigAction);addLocalAction(renameFunctionAction);addLocalAction(renameLabelAction);+ addLocalAction(removeLabelAction);addLocalAction(debugFunctionAction);addLocalAction(convertAction);addLocalAction(findAction);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.javaindex 2edf4ce150..3d301e8fe2 100644--- 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.java@@ -17,7 +17,9 @@ package ghidra.app.plugin.core.decompile.actions;import docking.ActionContext;import docking.action.DockingAction;+import docking.action.KeyBindingType;import ghidra.app.decompiler.*;+import ghidra.app.decompiler.component.DecompilerUtils;import ghidra.app.plugin.core.decompile.DecompilePlugin;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.app.util.datatype.DataTypeSelectionDialog;@@ -26,15 +28,18 @@ import ghidra.program.model.address.Address;import ghidra.program.model.data.*;import ghidra.program.model.listing.*;import ghidra.program.model.pcode.*;+import ghidra.program.model.symbol.Symbol;+import ghidra.program.model.symbol.SymbolTable;+import ghidra.program.util.ProgramLocation;import ghidra.util.data.DataTypeParser.AllowedDataTypes;/**- * A base class for {@link DecompilePlugin} actions that handles checking whether the- * decompiler is busy. Each action is responsible for deciding its enablement via+ * 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+ * <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@@ -46,6 +51,10 @@ public abstract class AbstractDecompilerAction extends DockingAction {super(name, DecompilePlugin.class.getSimpleName());}+ AbstractDecompilerAction(String name, KeyBindingType kbType) {+ super(name, DecompilePlugin.class.getSimpleName(), kbType);+ }+@Overridepublic boolean isValidContext(ActionContext context) {return context instanceof DecompilerActionContext;@@ -194,7 +203,7 @@ public abstract class AbstractDecompilerAction extends DockingAction {return false;}- public DataType chooseDataType(PluginTool tool, Program program, DataType currentDataType) {+ protected DataType chooseDataType(PluginTool tool, Program program, DataType currentDataType) {DataTypeManager dataTypeManager = program.getDataTypeManager();DataTypeSelectionDialog chooserDialog = new DataTypeSelectionDialog(tool, dataTypeManager,Integer.MAX_VALUE, AllowedDataTypes.FIXED_LENGTH);@@ -203,6 +212,38 @@ public abstract class AbstractDecompilerAction extends DockingAction {return chooserDialog.getUserChosenDataType();}+ protected Symbol getSymbol(DecompilerActionContext context) {++ // prefer the decompiler's function reference over the program location's address+ Function function = getFunction(context);+ if (function != null) {+ return function.getSymbol();+ }++ Program program = context.getProgram();+ SymbolTable symbolTable = program.getSymbolTable();+ Address address = context.getAddress();+ if (address == null) {+ return null;+ }+ return symbolTable.getPrimarySymbol(address);+ }++ protected Function getFunction(DecompilerActionContext context) {+ ProgramLocation location = context.getLocation();+ if (!(location instanceof DecompilerLocation)) {+ return null;+ }++ ClangToken token = ((DecompilerLocation) location).getToken();+ if (!(token instanceof ClangFuncNameToken)) {+ return null;+ }++ Program program = location.getProgram();+ return DecompilerUtils.getFunction(program, (ClangFuncNameToken) token);+ }+/*** Subclasses return true if they are enabled for the given context*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 59ecc9226a..6507a47a32 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@@ -16,19 +16,12 @@package ghidra.app.plugin.core.decompile.actions;import docking.action.MenuData;-import ghidra.app.decompiler.*;-import ghidra.app.decompiler.component.DecompilerUtils;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.app.plugin.core.decompile.DecompilerProvider;import ghidra.app.plugin.core.navigation.locationreferences.LocationReferencesService;import ghidra.app.util.HelpTopics;-import ghidra.program.model.address.Address;-import ghidra.program.model.listing.Function;-import ghidra.program.model.listing.Program;import ghidra.program.model.symbol.Symbol;-import ghidra.program.model.symbol.SymbolTable;import ghidra.program.util.LabelFieldLocation;-import ghidra.program.util.ProgramLocation;import ghidra.util.HelpLocation;import ghidra.util.Msg;@@ -47,43 +40,6 @@ public class FindReferencesToSymbolAction extends AbstractDecompilerAction {new MenuData(new String[] { LocationReferencesService.MENU_GROUP, MENU_ITEM_TEXT }));}- private Symbol getSymbol(DecompilerActionContext context) {-- ProgramLocation location = context.getLocation();- if (location == null) {- return null;- }-- Address address = getDecompilerSymbolAddress(location);- if (address == null) {- address = location.getAddress();- }- Program program = context.getProgram();- SymbolTable symbolTable = program.getSymbolTable();- Symbol symbol = symbolTable.getPrimarySymbol(address);- return symbol;- }-- private Address getDecompilerSymbolAddress(ProgramLocation location) {-- if (!(location instanceof DecompilerLocation)) {- return null;- }-- ClangToken token = ((DecompilerLocation) location).getToken();- if (!(token instanceof ClangFuncNameToken)) {- return null;- }-- Program program = location.getProgram();- Function function = DecompilerUtils.getFunction(program, (ClangFuncNameToken) token);- if (function != null) {- return function.getEntryPoint();- }-- return null;- }-private void updateMenuName(Symbol symbol) {if (symbol == null) {diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveLabelAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveLabelAction.javanew file mode 100644index 0000000000..0e93d19d56--- /dev/null+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveLabelAction.java@@ -0,0 +1,73 @@+/* ###+ * 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 java.awt.event.KeyEvent;++import javax.swing.KeyStroke;++import docking.action.*;+import ghidra.app.cmd.label.DeleteLabelCmd;+import ghidra.app.decompiler.ClangLabelToken;+import ghidra.app.decompiler.ClangToken;+import ghidra.app.plugin.core.decompile.DecompilerActionContext;+import ghidra.app.util.HelpTopics;+import ghidra.framework.cmd.Command;+import ghidra.framework.plugintool.PluginTool;+import ghidra.program.model.symbol.SourceType;+import ghidra.program.model.symbol.Symbol;+import ghidra.util.HelpLocation;++public class RemoveLabelAction extends AbstractDecompilerAction {++ private static final String[] POPUP_PATH = { "Remove Label" };+ private static final KeyStroke KEYBINDING = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);++ public RemoveLabelAction() {+ super("Remove Label", KeyBindingType.SHARED);++ setHelpLocation(new HelpLocation(HelpTopics.DECOMPILER, "ActionRemoveLabel"));++ // same keybinding as the other remove actions+ setPopupMenuData(new MenuData(POPUP_PATH, "Decompile"));+ setKeyBindingData(new KeyBindingData(KEYBINDING));+ }++ @Override+ protected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {+ ClangToken tokenAtCursor = context.getTokenAtCursor();+ if (!(tokenAtCursor instanceof ClangLabelToken)) {+ return false;+ }++ Symbol symbol = getSymbol(context);+ return canRemoveSymbol(symbol);+ }++ private boolean canRemoveSymbol(Symbol s) {+ return s != null && s.getSource() != SourceType.DEFAULT && !s.isExternal();+ }++ @Override+ protected void decompilerActionPerformed(DecompilerActionContext context) {+ Symbol s = getSymbol(context);+ Command cmd = new DeleteLabelCmd(s.getAddress(), s.getName(), s.getParentNamespace());+ PluginTool tool = context.getTool();+ if (!tool.execute(cmd, context.getProgram())) {+ tool.setStatusInfo(cmd.getStatusMsg());+ }+ }+}