Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3197 - Call Trees - fixed bugs: multiple icons appearing in the toolbar; custom icons were not rendering in the help content

dragonmacherea8e2a81c6c2
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/CallTreePlugin/Call_Tree_Plugin.html b/Ghidra/Features/Base/src/main/help/help/topics/CallTreePlugin/Call_Tree_Plugin.html
index 92e66e303d..2a044dc028 100644
--- a/Ghidra/Features/Base/src/main/help/help/topics/CallTreePlugin/Call_Tree_Plugin.html
+++ b/Ghidra/Features/Base/src/main/help/help/topics/CallTreePlugin/Call_Tree_Plugin.html
@@ -37,6 +37,31 @@
right-clicking in the Listing and selecting
<B>References<IMG src="../../shared/arrow.gif" alt="-&gt;" border="0">Show Call Trees</B>
</P>
+
+ <BLOCKQUOTE>
+ <P>
+ <IMG border="0" src="../../shared/note.png">Unlike most widgets in Ghidra, the Call
+ Trees display functions differently depending upon how you launch it.
+ <UL>
+ <LI>
+ When launched from the toolbar icon, the provider that is shown will track the
+ current location in the Listing (the the <IMG src="images/locationIn.gif" border="1">
+ <A href="#Call_Tree_Action_Incoming_Navigation">Navigate on Incoming Location Changes
+ button</A> is on).
+ </LI>
+ <LI>
+ When launched from the context popup menu, the provider that is shown will not track
+ the current location in the Listing. This allows you to open multiple windows for
+ different functions, functioning much like <A HREF="help/topics/Snapshots/Snapshots.html">
+ snapshots</A>, allowing you to keep a watchful eye on particular functions, regardless
+ of where you navigate within the tool.
+ </LI>
+ </UL>
+ </P>
+ </BLOCKQUOTE>
+
+ <BR><BR>
+
<P><A name="Incoming_Call_Tree"></A>The <B>Incoming Calls</B> tree shows all caller
functions. Each node in the tree has the incoming function call icon (<IMG src=
@@ -139,7 +164,8 @@
<!-- Home -->
<P align="left"><A name="Call_Tree_Action_Home"></A>The <IMG src="images/go-home.png"
- border="1"> home button will navigate to function label of the main function.</P>
+ border="1"> home button will navigate to the function label of the main function
+ for which the call trees are being displayed.</P>
<P align="left"><A name="Call_Tree_Action_Refresh"></A>The <IMG src="Icons.REFRESH_ICON"
border="1"> refresh button will reload the trees. This is needed due to the fact that
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreePlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreePlugin.java
index c4ac98f3cf..fa41fd3741 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreePlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreePlugin.java
@@ -70,6 +70,7 @@ public class CallTreePlugin extends ProgramPlugin {
createActions();
primaryProvider = new CallTreeProvider(this, true);
+ providers.add(primaryProvider);
}
@Override
@@ -108,8 +109,12 @@ public class CallTreePlugin extends ProgramPlugin {
}
}
- private CallTreeProvider findProviderForLocation(ProgramLocation location) {
+ CallTreeProvider findTransientProviderForLocation(ProgramLocation location) {
for (CallTreeProvider provider : providers) {
+ if (provider == primaryProvider) {
+ continue; // not transient
+ }
+
if (provider.isShowingLocation(location)) {
return provider;
}
@@ -177,7 +182,7 @@ public class CallTreePlugin extends ProgramPlugin {
return; // no program; cannot show tool
}
- CallTreeProvider provider = findProviderForLocation(location);
+ CallTreeProvider provider = findTransientProviderForLocation(location);
if (provider != null) {
tool.showComponentProvider(provider, true);
return;
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeProvider.java
index 8fa58d5836..3d2b32ff4c 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeProvider.java
@@ -107,8 +107,13 @@ public class CallTreeProvider extends ComponentProviderAdapter implements Domain
setWindowMenuGroup(TITLE);
setDefaultWindowPosition(WindowPosition.BOTTOM);
+ if (isPrimary) {
+ addToToolbar();
+ }
+ else {
+ setTransient();
+ }
setIcon(CallTreePlugin.PROVIDER_ICON);
- addToToolbar();
setHelpLocation(new HelpLocation(plugin.getName(), "Call_Tree_Plugin"));
addToTool();
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/CallTreePluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/CallTreePluginTest.java
index d6858474de..eee878022f 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/CallTreePluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/CallTreePluginTest.java
@@ -63,7 +63,6 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
private PluginTool tool;
private CallTreePlugin callTreePlugin;
private CallTreeProvider provider;
- private List<CallTreeProvider> providers;
private GTree incomingTree;
private GTree outgoingTree;
@@ -73,8 +72,6 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
private GoToService goToService;
- @SuppressWarnings("unchecked")
- // cast to list
@Before
public void setUp() throws Exception {
env = new TestEnv();
@@ -84,7 +81,6 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
tool.addPlugin(CallTreePlugin.class.getName());
callTreePlugin = env.getPlugin(CallTreePlugin.class);
- providers = (List<CallTreeProvider>) getInstanceField("providers", callTreePlugin);
GoToServicePlugin goToPlugin = env.getPlugin(GoToServicePlugin.class);
goToService = (GoToService) invokeInstanceMethod("getGotoService", goToPlugin);
@@ -291,10 +287,37 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
CallTreeProvider initialProvider = provider;
CallTreeProvider newProvider = showProvider("6000");
- Assert.assertNotEquals(initialProvider, newProvider);
+ assertNotEquals(initialProvider, newProvider);
assertEquals(depth, currentDepthSetting(newProvider));
}
+ @Test
+ public void testShowingTransientProvider() {
+
+ goTo(addr("0x5000"));// new function
+ assertOnlyOneToolbarIcon(); // this was a regression
+
+ CallTreeProvider initialProvider = provider;
+ CallTreeProvider newProvider = showProvider("6000");
+ assertNotEquals(initialProvider, newProvider);
+ assertOnlyOneToolbarIcon();
+ }
+
+ private void assertOnlyOneToolbarIcon() {
+
+ int toolBarActionCount = 0;
+ Set<DockingActionIf> actions =
+ getActionsByOwnerAndName(tool, callTreePlugin.getName(), provider.getName());
+ for (DockingActionIf action : actions) {
+ ToolBarData data = action.getToolBarData();
+ if (data != null) {
+ toolBarActionCount++;
+ }
+ }
+
+ assertEquals("Expected exactly one toolbar action", 1, toolBarActionCount);
+ }
+
@Test
public void testIncomingExpandToDepthFromRoot() {
//
@@ -372,26 +395,23 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
// is selected.
//
assertTrue(provider.isVisible());
-
assertNotNull("Provider did not update its information when made visible",
providerFunction());
- ToggleDockingAction navigateIncomingLoctionsAction =
- (ToggleDockingAction) getAction("Navigation Incoming Location Changes");
- setToggleActionSelected(navigateIncomingLoctionsAction, provider.getActionContext(null),
- false);
+ toggleFollowIncomingNavigation(false);
- assertEquals("Provider's location does not match that of the listing.", currentFunction(),
- providerFunction());
+ assertProviderMatchesListingFunction();
goTo(addr("0x6000"));
+ assertNotEquals(
+ "Provider's location should not have changed when not tracking location changes",
+ getListingFunction(), providerFunction());
- assertNotEquals("Provider's location matches that of the listing when not following " +
- "location changes", currentFunction(), providerFunction());
- performAction(navigateIncomingLoctionsAction, true);
+ toggleFollowIncomingNavigation(true);
+ assertProviderMatchesListingFunction();
- assertEquals("Provider's location does not match that of the listing", currentFunction(),
- providerFunction());
+ goTo(addr("0x6100"));
+ assertProviderMatchesListingFunction();
}
@Test
@@ -405,7 +425,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeRootNode rootNode = getRootNode(incomingTree);
List<GTreeNode> children = rootNode.getChildren();
assertTrue(
- "Incoming tree does not have callers as expected for function: " + currentFunction(),
+ "Incoming tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
GTreeNode child0 = children.get(0);
@@ -425,7 +445,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeRootNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren();
assertTrue(
- "Outgoing tree does not have callers as expected for function: " + currentFunction(),
+ "Outgoing tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
GTreeNode child1 = children.get(1);
@@ -445,7 +465,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeRootNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren();
assertTrue(
- "Outgoing tree does not have callers as expected for function: " + currentFunction(),
+ "Outgoing tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
ProgramLocation originalLocation = currentLocation();
@@ -486,7 +506,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeRootNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren();
assertTrue(
- "Outgoing tree does not have callers as expected for function: " + currentFunction(),
+ "Outgoing tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
OutgoingCallNode child0 = (OutgoingCallNode) children.get(0);
@@ -506,7 +526,13 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
}
@Test
- public void testHomeAction() {
+ public void testHomeAction_Navigation_DoNotFollow() {
+
+ //
+ // Test that the 'home' address does not change when the user navigates
+ //
+
+ toggleFollowIncomingNavigation(false);
Address startAddress = addr("0x5000");
setProviderFunction("0x5000");
@@ -516,10 +542,32 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
Address firstCallAddress = addr("0x6000");
goTo(firstCallAddress);
- assertEquals(firstCallAddress, currentAddress());
+ assertEquals(firstCallAddress, getListingAddress());
+
+ performAction(homeAction, true);
+ assertEquals(startAddress, getListingAddress());
+ }
+
+ @Test
+ public void testHomeAction_Navigation_Follow() {
+
+ //
+ // Test that the 'home' address does not change when the user navigates
+ //
+
+ toggleFollowIncomingNavigation(true);
+ setProviderFunction("0x5000");
+
+ DockingActionIf homeAction = getAction("Home");
+
+ // go to some other address
+ Address firstCallAddress = addr("0x6000");
+ goTo(firstCallAddress);
+
+ assertEquals(firstCallAddress, getListingAddress());
performAction(homeAction, true);
- assertEquals(startAddress, currentAddress());
+ assertEquals(firstCallAddress, getListingAddress());
}
@Test
@@ -543,7 +591,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeRootNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren();
assertTrue(
- "Outgoing tree does not have callers as expected for function: " + currentFunction(),
+ "Outgoing tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
// copy the names of the children into a map so that we can verify that there are
@@ -583,21 +631,21 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeRootNode rootNode = getRootNode(outgoingTree);
List<GTreeNode> children = rootNode.getChildren();
assertTrue(
- "Outgoing tree does not have callers as expected for function: " + currentFunction(),
+ "Outgoing tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
OutgoingCallNode child0 = (OutgoingCallNode) children.get(0);
clickNode(outgoingTree, child0);
waitForTree(outgoingTree);
Address expectedAddress0 = child0.getSourceAddress();
- assertEquals("Node selection did not trigger navigation", currentAddress(),
+ assertEquals("Node selection did not trigger navigation", getListingAddress(),
expectedAddress0);
OutgoingCallNode child1 = (OutgoingCallNode) children.get(1);
clickNode(outgoingTree, child1);
waitForTree(outgoingTree);
Address expectedAddress1 = child1.getSourceAddress();
- assertEquals("Node selection did not trigger navigation", currentAddress(),
+ assertEquals("Node selection did not trigger navigation", getListingAddress(),
expectedAddress1);
//
@@ -610,20 +658,20 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
rootNode = getRootNode(outgoingTree);
children = rootNode.getChildren();
assertTrue(
- "Outgoing tree does not have callers as expected for function: " + currentFunction(),
+ "Outgoing tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
child0 = (OutgoingCallNode) children.get(0);
clickNode(outgoingTree, child0);
waitForTree(outgoingTree);
assertEquals("Node selection triggered navigation when the action is disabled",
- currentAddress(), startAddress);
+ getListingAddress(), startAddress);
child1 = (OutgoingCallNode) children.get(1);
clickNode(outgoingTree, child1);
waitForTree(outgoingTree);
assertEquals("Node selection triggered navigation when the action is disabled",
- currentAddress(), startAddress);
+ getListingAddress(), startAddress);
}
@Test
@@ -668,7 +716,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeRootNode rootNode = getRootNode(incomingTree);
List<GTreeNode> children = rootNode.getChildren();
assertTrue(
- "Incoming tree does not have callers as expected for function: " + currentFunction(),
+ "Incoming tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
GTreeNode child1 = children.get(0);
@@ -684,7 +732,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
rootNode = getRootNode(incomingTree);
children = rootNode.getChildren();
assertTrue(
- "Incoming tree does not have callers as expected for function: " + currentFunction(),
+ "Incoming tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
assertContainsChild(children, newName);
@@ -699,7 +747,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
GTreeRootNode rootNode = getRootNode(incomingTree);
List<GTreeNode> children = rootNode.getChildren();
assertTrue(
- "Incoming tree does not have callers as expected for function: " + currentFunction(),
+ "Incoming tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
Function rootFunction = getFunction(addr("0x5000"));
@@ -711,7 +759,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
rootNode = getRootNode(incomingTree);
children = rootNode.getChildren();
assertTrue(
- "Incoming tree does not have callers as expected for function: " + currentFunction(),
+ "Incoming tree does not have callers as expected for function: " + getListingFunction(),
children.size() > 0);
assertEquals("Incoming References - " + newName, rootNode.getName());
@@ -721,6 +769,18 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
// Private Methods
//==================================================================================================
+ private void assertProviderMatchesListingFunction() {
+ assertEquals("Provider's location does not match that of the listing.",
+ getListingFunction(), providerFunction());
+ }
+
+ private void toggleFollowIncomingNavigation(boolean selected) {
+ ToggleDockingAction navigateIncomingLoctionsAction =
+ (ToggleDockingAction) getAction("Navigation Incoming Location Changes");
+ setToggleActionSelected(navigateIncomingLoctionsAction, provider.getActionContext(null),
+ selected);
+ }
+
private void assertContainsChild(List<GTreeNode> children, String name) {
for (GTreeNode node : children) {
if (node.getName().equals(name)) {
@@ -770,21 +830,6 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
return functionManager.getFunctionAt(address);
}
- private CallTreeProvider getProvider(final String address) {
- final CallTreeProvider[] providerBox = new CallTreeProvider[1];
-
- // run in swing, as two threads are accessing/manipulating a variable
- runSwing(() -> {
- for (CallTreeProvider p : providers) {
- if (p.toString().indexOf(address) != -1) {
- providerBox[0] = p;
- break;
- }
- }
- });
- return providerBox[0];
- }
-
private void assertOutgoingNoNode(String name, int depth) {
List<NodeDepthInfo> nodes = getNodesByDepth(false);
for (NodeDepthInfo info : nodes) {
@@ -1005,7 +1050,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
return aProvider.getRecurseDepth();
}
- private Function currentFunction() {
+ private Function getListingFunction() {
FunctionManager functionManager = program.getFunctionManager();
ProgramLocation codeBrowserLocation = codeBrowserPlugin.getCurrentLocation();
return functionManager.getFunctionContaining(codeBrowserLocation.getAddress());
@@ -1019,7 +1064,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
return codeBrowserPlugin.getCurrentLocation();
}
- private Address currentAddress() {
+ private Address getListingAddress() {
return codeBrowserPlugin.getCurrentAddress();
}
@@ -1099,10 +1144,12 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
*/
private CallTreeProvider showProvider(String address) {
goTo(addr(address));
+ ProgramLocation location = codeBrowserPlugin.getCurrentLocation();
DockingAction action = callTreePlugin.getShowCallTreeFromMenuAction();
performAction(action);
- return getProvider(address);
+
+ return runSwing(() -> callTreePlugin.findTransientProviderForLocation(location));
}
private Address addr(String address) {
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/help/GHelpHTMLEditorKit.java b/Ghidra/Framework/Docking/src/main/java/docking/help/GHelpHTMLEditorKit.java
index 8f0484c207..a29e5f705e 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/help/GHelpHTMLEditorKit.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/help/GHelpHTMLEditorKit.java
@@ -15,6 +15,7 @@
*/
package docking.help;
+import java.awt.Image;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.*;
@@ -24,6 +25,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
@@ -378,10 +380,68 @@ public class GHelpHTMLEditorKit extends HTMLEditorKit {
*/
private class GHelpImageView extends ImageView {
+ /*
+ * Unusual Code Alert!
+ * This class exists to enable our help system to find custom icons defined in source
+ * code. The default behavior herein is to supply a URL to the base class to load. This
+ * works fine.
+ *
+ * There is another use case where we wish to have the base class load an image of our
+ * choosing. Why? Well, we modify, in memory, some icons we use. We do this for things
+ * like overlays and rotations.
+ *
+ * In order to have our base class use the image that we want (and not the one
+ * it loads via a URL), we have to play a small game. We have to allow the base class
+ * to load the image it wants, which is done asynchronously. If we install our custom
+ * image during that process, the loading will throw away the image and not render
+ * anything.
+ *
+ * To get the base class to use our image, we override getImage(). However, we should
+ * only return our image when the base class is finished loaded. (See the base class'
+ * paint() method for why we need to do this.)
+ *
+ * Note: if we start seeing unusual behavior, like images not rendering, or any size
+ * issues, then we can revert this code.
+ */
+ private Image image;
+ private float spanX;
+ private float spanY;
+
public GHelpImageView(Element elem) {
super(elem);
}
+ @Override
+ public Image getImage() {
+ Image superImage = super.getImage();
+ if (image == null) {
+ // no custom image
+ return superImage;
+ }
+
+ if (isLoading()) {
+ return superImage;
+ }
+
+ return image;
+ }
+
+ private boolean isLoading() {
+ return spanX < 1 || spanY < 1;
+ }
+
+ @Override
+ public float getPreferredSpan(int axis) {
+ float span = super.getPreferredSpan(axis);
+ if (axis == View.X_AXIS) {
+ spanX = span;
+ }
+ else {
+ spanY = span;
+ }
+ return span;
+ }
+
@Override
public URL getImageURL() {
@@ -407,6 +467,9 @@ public class GHelpHTMLEditorKit extends HTMLEditorKit {
return null;
}
+ ImageIcon imageIcon = iconProvider.getIcon();
+ this.image = imageIcon.getImage();
+
URL url = iconProvider.getOrCreateUrl();
return url;
}