Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-4393 add hover to show symbol source type

ghidragon2a1a15857804
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ExternalAddConflictPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ExternalAddConflictPanel.java
index 5fb75fbb2a..189b6260b6 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ExternalAddConflictPanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/listing/ExternalAddConflictPanel.java
@@ -4,9 +4,9 @@
* 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.
@@ -86,7 +86,7 @@ class ExternalAddConflictPanel extends JPanel implements CodeFormatService {
private ReferenceListingHover referenceHoverService;
private DataTypeListingHover dataTypeHoverService;
private TruncatedTextListingHover truncatedTextHoverService;
- private FunctionNameListingHover functionNameHoverService;
+ private LabelListingHover labelListingHoverService;
private boolean showListingPanel;
ExternalAddConflictPanel(MergeManager mergeManager, int totalConflicts, Program latestProgram,
@@ -108,7 +108,7 @@ class ExternalAddConflictPanel extends JPanel implements CodeFormatService {
referenceHoverService = new ReferenceListingHover(tool, this);
dataTypeHoverService = new DataTypeListingHover(tool);
truncatedTextHoverService = new TruncatedTextListingHover(tool);
- functionNameHoverService = new FunctionNameListingHover(tool);
+ labelListingHoverService = new LabelListingHover(tool);
initializeListingHoverService(latestPanel);
initializeListingHoverService(myPanel);
@@ -118,7 +118,7 @@ class ExternalAddConflictPanel extends JPanel implements CodeFormatService {
listingPanel.addHoverService(referenceHoverService);
listingPanel.addHoverService(dataTypeHoverService);
listingPanel.addHoverService(truncatedTextHoverService);
- listingPanel.addHoverService(functionNameHoverService);
+ listingPanel.addHoverService(labelListingHoverService);
listingPanel.setHoverMode(true);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/tool/ListingMergePanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/tool/ListingMergePanel.java
index fde9f3b9e4..6dcb0b384b 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/merge/tool/ListingMergePanel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/merge/tool/ListingMergePanel.java
@@ -4,9 +4,9 @@
* 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.
@@ -84,7 +84,7 @@ public class ListingMergePanel extends JPanel
private ReferenceListingHover referenceHoverService;
private DataTypeListingHover dataTypeHoverService;
private TruncatedTextListingHover truncatedTextHoverService;
- private FunctionNameListingHover functionNameHoverService;
+ private LabelListingHover labelListingHoverService;
public ListingMergePanel(PluginTool tool, Program original, Program result, Program myChanges,
Program latest, boolean showListings) {
@@ -133,7 +133,7 @@ public class ListingMergePanel extends JPanel
referenceHoverService = new ReferenceListingHover(tool, this);
dataTypeHoverService = new DataTypeListingHover(tool);
truncatedTextHoverService = new TruncatedTextListingHover(tool);
- functionNameHoverService = new FunctionNameListingHover(tool);
+ labelListingHoverService = new LabelListingHover(tool);
initializeListingHoverService(listingPanels[RESULT]);
initializeListingHoverService(listingPanels[LATEST]);
@@ -145,7 +145,7 @@ public class ListingMergePanel extends JPanel
listingPanel.addHoverService(referenceHoverService);
listingPanel.addHoverService(dataTypeHoverService);
listingPanel.addHoverService(truncatedTextHoverService);
- listingPanel.addHoverService(functionNameHoverService);
+ listingPanel.addHoverService(labelListingHoverService);
listingPanel.setHoverMode(true);
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/FunctionNameListingHover.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/LabelListingHover.java
similarity index 59%
rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/FunctionNameListingHover.java
rename to Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/LabelListingHover.java
index 1600a211b5..9366c44d2d 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/FunctionNameListingHover.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/LabelListingHover.java
@@ -4,9 +4,9 @@
* 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.
@@ -15,6 +15,8 @@
*/
package ghidra.app.plugin.core.codebrowser.hover;
+import static ghidra.util.HTMLUtilities.*;
+
import javax.swing.JComponent;
import docking.widgets.fieldpanel.field.Field;
@@ -22,27 +24,25 @@ import docking.widgets.fieldpanel.support.FieldLocation;
import ghidra.GhidraOptions;
import ghidra.app.plugin.core.hover.AbstractConfigurableHover;
import ghidra.framework.plugintool.PluginTool;
-import ghidra.program.model.listing.*;
-import ghidra.program.model.symbol.*;
+import ghidra.program.model.listing.Program;
+import ghidra.program.model.symbol.Symbol;
import ghidra.program.util.LabelFieldLocation;
import ghidra.program.util.ProgramLocation;
/**
- * A hover service to show tool tip text for hovering over a label.
- * The tooltip shows the label along with its namespace information.
- * This provides the hover capability for the FunctionNameHoverPlugin and can
- * also be used to directly provide this hover capability to a listing.
+ * A hover service to show the full namespace path of a symbol along with its symbol type and
+ * source type.
*/
-public class FunctionNameListingHover extends AbstractConfigurableHover
+public class LabelListingHover extends AbstractConfigurableHover
implements ListingHoverService {
- private static final String NAME = "Function Name Display";
+ private static final String NAME = "Label Display";
private static final String DESCRIPTION =
"Toggle whether the full symbol name is shown as a tooltip. This only applies " +
"when displaying namespaces.";
private static final int PRIORITY = 20;
- public FunctionNameListingHover(PluginTool tool) {
+ public LabelListingHover(PluginTool tool) {
super(tool, PRIORITY);
}
@@ -65,6 +65,14 @@ public class FunctionNameListingHover extends AbstractConfigurableHover
public JComponent getHoverComponent(Program program, ProgramLocation programLocation,
FieldLocation fieldLocation, Field field) {
+ Symbol symbol = getLabelSymbol(programLocation);
+ if (symbol == null) {
+ return null;
+ }
+ return createTooltipComponent(getToolTipText(symbol));
+ }
+
+ private Symbol getLabelSymbol(ProgramLocation programLocation) {
if (!enabled || programLocation == null) {
return null;
}
@@ -73,37 +81,27 @@ public class FunctionNameListingHover extends AbstractConfigurableHover
return null;
}
- // is the label local to the function
Symbol symbol = ((LabelFieldLocation) programLocation).getSymbol();
- if (isLocalFunctionSymbol(program, symbol)) {
- return createTooltipComponent(symbol.getName(true));
- }
-
- return null;
- }
-
- private boolean isLocalFunctionSymbol(Program program, Symbol symbol) {
if (symbol == null) {
- return false;
+ return null;
}
- Namespace parentScope = symbol.getParentNamespace();
- SymbolType symbolType = symbol.getSymbolType();
-
- if (symbolType != SymbolType.LABEL) {
- return false;
- }
+ return symbol;
+ }
- if (parentScope.getID() == Namespace.GLOBAL_NAMESPACE_ID) {
- return false;
- }
+ private String getToolTipText(Symbol symbol) {
+ StringBuilder buf = new StringBuilder(HTML);
+ buf.append(friendlyEncodeHTML(symbol.getName(true)));
+ buf.append(BR).append(BR);
+ buf.append("Type: ");
+ buf.append(HTML_SPACE).append(HTML_SPACE).append(HTML_SPACE).append(HTML_SPACE);
+ buf.append(symbol.getSymbolType());
+ buf.append(BR);
+ buf.append("Source: ");
+ buf.append(symbol.getSource().getDisplayString());
+ buf.append(BR);
+ return buf.toString();
- FunctionManager functionManager = program.getFunctionManager();
- Function function = functionManager.getFunctionContaining(symbol.getAddress());
- if (function == null) {
- return false;
- }
- return function.getName().equals(parentScope.getName());
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/FunctionNameListingHoverPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/LabelListingHoverPlugin.java
similarity index 64%
rename from Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/FunctionNameListingHoverPlugin.java
rename to Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/LabelListingHoverPlugin.java
index d25927b998..ffd5d2eceb 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/FunctionNameListingHoverPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/hover/LabelListingHoverPlugin.java
@@ -4,9 +4,9 @@
* 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.
@@ -21,32 +21,30 @@ import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.PluginStatus;
/**
- * A plugin to show tool tip text for hovering over function names in the listing.
- *
- *
+ * A plugin to show tool tip text for hovering over labels in the listing.
*/
//@formatter:off
@PluginInfo(
status = PluginStatus.RELEASED,
packageName = CorePluginPackage.NAME,
category = PluginCategoryNames.CODE_VIEWER,
- shortDescription = "Function Name Hover",
- description = "Displays the function name of labels within functions in the Code Viewer.",
+ shortDescription = "Label Name Hover",
+ description = "Displays the information about labels in the Code Viewer.",
servicesProvided = { ListingHoverService.class }
)
//@formatter:on
-public class FunctionNameListingHoverPlugin extends Plugin {
+public class LabelListingHoverPlugin extends Plugin {
- private FunctionNameListingHover functionNameHoverService;
+ private LabelListingHover labelListingHoverService;
- public FunctionNameListingHoverPlugin(PluginTool tool) {
+ public LabelListingHoverPlugin(PluginTool tool) {
super(tool);
- functionNameHoverService = new FunctionNameListingHover(tool);
- registerServiceProvided(ListingHoverService.class, functionNameHoverService);
+ labelListingHoverService = new LabelListingHover(tool);
+ registerServiceProvided(ListingHoverService.class, labelListingHoverService);
}
@Override
public void dispose() {
- functionNameHoverService.dispose();
+ labelListingHoverService.dispose();
}
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/ToolTipUtils.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/ToolTipUtils.java
index 87de4e07af..b285d1dd46 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/ToolTipUtils.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/ToolTipUtils.java
@@ -4,9 +4,9 @@
* 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.
@@ -29,7 +29,6 @@ import ghidra.app.util.viewer.field.ListingColors.FunctionColors;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.*;
import ghidra.program.model.data.Enum;
-import ghidra.program.model.lang.PrototypeModel;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.ExternalLocation;
import ghidra.program.model.symbol.Symbol;
@@ -186,9 +185,13 @@ public class ToolTipUtils {
if (includeSymbolDetails) {
buf.append("Function");
buf.append(HTML_SPACE).append("-").append(HTML_SPACE);
- String functionName = function.getSymbol().getName(true);
+ Symbol symbol = function.getSymbol();
+ String functionName = symbol.getName(true);
functionName = StringUtilities.trimMiddle(functionName, LINE_LENGTH);
buf.append(friendlyEncodeHTML(functionName));
+ buf.append("   <");
+ buf.append(friendlyEncodeHTML(symbol.getSource().getDisplayString()));
+ buf.append(">");
if (extLoc != null) {
Address addr = extLoc.getAddress();
if (addr != null) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/features/base/codecompare/listing/ListingDisplay.java b/Ghidra/Features/Base/src/main/java/ghidra/features/base/codecompare/listing/ListingDisplay.java
index 943d36fe78..c81b4c5078 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/features/base/codecompare/listing/ListingDisplay.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/features/base/codecompare/listing/ListingDisplay.java
@@ -85,7 +85,7 @@ public class ListingDisplay implements ListingDiffChangeListener {
listingPanel.addHoverService(new ReferenceListingHover(tool, () -> formatManager));
listingPanel.addHoverService(new DataTypeListingHover(tool));
listingPanel.addHoverService(new TruncatedTextListingHover(tool));
- listingPanel.addHoverService(new FunctionNameListingHover(tool));
+ listingPanel.addHoverService(new LabelListingHover(tool));
listingDiff.addListingDiffChangeListener(this);
setHoverMode(true);