Ghidra is a software reverse engineering (SRE) framework
GP-5116 - Function Call Trees Improvements (see below):
dragonmacher7a3a5027c070
diff --git a/Ghidra/Features/Base/certification.manifest b/Ghidra/Features/Base/certification.manifestindex b197639840..f3b40b420c 100644--- a/Ghidra/Features/Base/certification.manifest+++ b/Ghidra/Features/Base/certification.manifest@@ -834,6 +834,7 @@ src/main/resources/images/hexData.png||GHIDRA||||END|src/main/resources/images/house.png||FAMFAMFAM Icons - CC 2.5|||famfamfam silk icon set|END|src/main/resources/images/hoverOff.gif||GHIDRA||||END|src/main/resources/images/hoverOn.gif||GHIDRA||||END|+src/main/resources/images/icon_link.gif||FAMFAMFAM Mini Icons - Public Domain|||famfamfam mini icon set|END|src/main/resources/images/imported_bookmark.gif||GHIDRA||||END|src/main/resources/images/katomic.png||Nuvola Icons - LGPL 2.1|||Nuvola icon set|END|src/main/resources/images/key.png||FAMFAMFAM Icons - CC 2.5|||silk|END|diff --git a/Ghidra/Features/Base/data/base.icons.theme.properties b/Ghidra/Features/Base/data/base.icons.theme.propertiesindex 2885347564..6549fbe9b1 100644--- a/Ghidra/Features/Base/data/base.icons.theme.properties+++ b/Ghidra/Features/Base/data/base.icons.theme.properties@@ -52,11 +52,12 @@ icon.plugin.calltree.function = FunctionScope.gificon.plugin.calltree.recursive = arrow_rotate_clockwise.pngicon.plugin.calltree.refresh = icon.refreshicon.plugin.calltree.refresh.not.needed = icon.plugin.calltree.refresh [disabled]-icon.plugin.calltree.filter.duplicates = application_double.png+icon.plugin.calltree.unify.functions = application_double.png+icon.plugin.calltree.filter.non.calls = icon_link.gificon.plugin.calltree.filter.select.source = text_align_justify.pngicon.plugin.calltree.node.dead.end = stopNode.pngicon.plugin.calltree.node.external = package.png-icon.plugin.calltree.data = D.gif+icon.plugin.calltree.reference = icon_link.gif [size(12,12)][move(4,4)]icon.plugin.checksum.compute = icon.refreshicon.plugin.checksum.select = NextSelectionBlock16.gifdiff --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.htmlindex a362ebff7e..d21e2222d2 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@@ -67,16 +67,16 @@<P><A name="Incoming_Call_Tree"></A>The <B>Incoming</B> tree shows all functions callingand/or referencing the main function. Each node in the tree has the incoming functionicon (<IMG src="Icons.ARROW_UP_LEFT_ICON" border="0">) combined with- (<IMG src="images/FunctionScope.gif" border="0">) for calls and- (<IMG src="images/D.gif" border="0">) for other reference types. Expanding a+ (<IMG src="icon.plugin.calltree.function" border="0">) for calls and+ (<IMG src="images/icon_link.gif" border="0">) for other reference types. Expanding anode in this tree shows all functions that call or reference the function correspondingto the expanded node. Nodes may be expanded recursively to any depth desired.</P><P><A name="Outgoing_Call_Tree"></A>The <B>Outgoing</B> tree shows all functionscalled or referenced by the main function. Each node in the tree has the outgoing functionicon (<IMG src="Icons.ARROW_DOWN_RIGHT_ICON" border="0">) combined with- (<IMG src="images/FunctionScope.gif" border="0">) for calls and- (<IMG src="images/D.gif" border="0">) for other reference types. Expanding a node in this+ (<IMG src="icon.plugin.calltree.function" border="0">) for calls and+ (<IMG src="images/icon_link.gif" border="0">) for other reference types. Expanding a node in thistree shows all functions that are called or referenced by the expanded node. Nodes may beexpanded recursively to any depth desired.</P>@@ -180,14 +180,27 @@taken place that <b>may</b> affect the structure of the tree.</P>- <!-- Filter Duplicates -->- <P align="left"><A name="Call_Tree_Action_Filter"></A>The+ <!-- Unify Functions-->+ <P align="left"><A name="Call_Tree_Action_Unify_Functions"></A>The<IMG src="images/application_double.png"- border="1"> action, when toggled on, will filter out duplicate function calls.- This setting is useful to see the set of all functions called. When- toggled off this action will show all function calls, including duplicate calls, in- address order. This setting is more useful to see the overall flow of the main- function.</P>+ border="1"> action, when toggled on, will filter out duplicate function calls. For+ incoming function calls, only one entry will exist in the child nodes for a given+ function, even if that function calls the parent node multiple times. For outgoing+ function calls, only one entry will exist in the child nodes for a given function, even+ if the parent node calls a given function repeatedly.+ This setting is useful to see the set of all functions called in order to see the basic+ function call graph. When toggled off this action will show all function calls,+ including duplicate calls, in address order. This setting is more useful to see the+ overall flow of the main function and to navigate each individual call site.</P>++ <!-- Filter References -->+ <P align="left"><A name="Call_Tree_Action_Filter_Calls"></A>The+ <IMG src="images/icon_link.gif"+ border="1"> action, when toggled on, will filter out function calls that are from+ non-call reference types. This setting is useful to see the set of all functions called+ specifically with a reference type that is considered a call reference.+ Toggling this setting off may be useful to see all ways functions are referenced, even+ when they are not considered function calls by Ghidra.<!-- Recurse Depth -->diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallNode.javaindex 3074b5abd7..ba7c685f70 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallNode.java@@ -17,17 +17,21 @@ package ghidra.app.plugin.core.calltree;import java.util.*;+import javax.swing.Icon;import javax.swing.tree.TreePath;import org.apache.commons.collections4.map.LazyMap;import docking.widgets.tree.GTreeNode;import docking.widgets.tree.GTreeSlowLoadingNode;+import generic.theme.GIcon;import ghidra.program.model.address.Address;import ghidra.program.model.listing.Function;import ghidra.program.util.ProgramLocation;import ghidra.util.exception.CancelledException;import ghidra.util.task.TaskMonitor;+import resources.MultiIcon;+import resources.icons.TranslateIcon;/*** In general, a CallNode represents a function and its relationship (either a call reference or@@ -35,6 +39,10 @@ import ghidra.util.task.TaskMonitor;*/public abstract class CallNode extends GTreeSlowLoadingNode {+ static final Icon FUNCTION_ICON = new GIcon("icon.plugin.calltree.function");+ static final Icon REFERENCE_ICON = new GIcon("icon.plugin.calltree.reference");+ static final Icon RECURSIVE_ICON = new GIcon("icon.plugin.calltree.recursive");+protected CallTreeOptions callTreeOptions;private int depth = -1;@@ -42,7 +50,19 @@ public abstract class CallNode extends GTreeSlowLoadingNode {protected boolean invalid = false;/** Indicates whether the associated reference is a call reference **/- protected boolean isCallRef = false;+ protected boolean isCallReference = false;++ protected static Icon createIcon(Icon baseIcon, boolean isCallReference) {++ MultiIcon multiIcon = new MultiIcon(baseIcon, false, 32, 16);+ //@formatter:off+ TranslateIcon translateIcon = isCallReference ?+ new TranslateIcon(FUNCTION_ICON, 16, 0) :+ new TranslateIcon(REFERENCE_ICON, 16, 0);+ //@formatter:on+ multiIcon.addIcon(translateIcon);+ return multiIcon;+ }public CallNode(CallTreeOptions callTreeOptions) {this.callTreeOptions = Objects.requireNonNull(callTreeOptions);@@ -76,56 +96,96 @@ public abstract class CallNode extends GTreeSlowLoadingNode {*/abstract CallNode recreate();+ /**+ * Returns true if the reference associated with this node is a call reference type.+ * @return true if the reference associated with this node is a call reference type.+ */+ public boolean isCallReference() {+ return isCallReference;+ }@Overridepublic String getToolTip() {- String refString = isCallRef ? "Called from " : "Referenced from ";+ String refString = isCallReference ? "Called from " : "Referenced from ";return refString + getSourceAddress();}protected void addNode(LazyMap<Function, List<GTreeNode>> nodesByFunction, CallNode nodeToAdd) {+ if (ignoreNonCallReference(nodeToAdd)) {+ return;+ }+Function function = nodeToAdd.getRemoteFunction();List<GTreeNode> nodes = nodesByFunction.get(function);+ if (nodes.isEmpty()) {+ nodes.add(nodeToAdd); // can can always add new nodes when the list is empty+ return;+ }- GTreeNode nodeToRemove = null;for (GTreeNode node : nodes) {+if (node.equals(nodeToAdd)) {return; // never add equal() nodes}- // don't allow a call reference and a non-call node to the same remote function- // at the same address- CallNode callNode = (CallNode) node;- if (nodeToAdd.isCallRef != callNode.isCallRef) {- if (Objects.equals(nodeToAdd.getSourceAddress(), callNode.getSourceAddress())) {- if (Objects.equals(nodeToAdd.getRemoteFunction(),- callNode.getRemoteFunction())) {- if (nodeToAdd.isCallRef) {- return; // don't replace a call node with a non-call node- }- // add the call node and remove the non-call node- nodeToRemove = callNode;- break;- }- }++ // Don't allow a call reference and a non-call reference to the same remote function+ // at the same address. One call node in the tree is sufficient to show the user that+ // the references exist.+ CallNode existingNode = (CallNode) node;+ if (resovleConflictingReferenceTypes(nodes, existingNode, nodeToAdd)) {+ return;}}- if (nodeToRemove != null) {- nodes.remove(nodeToRemove);- nodes.add(nodeToAdd);- return;- }+ // At this point we have verified that the node being added is not the same as an existing+ // node and has not replaced a similar node with a different type of reference. We also+ // know that there are multiple child nodes for the given remote function. Since we have+ // multiples, only add the new node if the user is allowing duplicate nodes.if (callTreeOptions.allowsDuplicates()) {nodes.add(nodeToAdd); // ok to add multiple nodes for this function with different addressesreturn;}- if (nodes.isEmpty()) {- nodes.add(nodeToAdd); // no duplicates allowed; only add if this is the only node- return;+ }++ private boolean ignoreNonCallReference(CallNode nodeToAdd) {+ if (nodeToAdd.isCallReference()) {+ return false; // is a call reference; do not ignore node+ }++ // a non-call reference; check options+ return !callTreeOptions.allowsNonCallReferences();+ }++ private boolean resovleConflictingReferenceTypes(List<GTreeNode> nodes, CallNode existingNode,+ CallNode nodeToAdd) {++ //+ // This code is looking for a special case where the two nodes passed in both come from the+ // same address, point to the same function, but one is a call reference and the other is+ // not. In this case, we prefer the call reference.+ //+ Address newAddress = nodeToAdd.getSourceAddress();+ Address exitingAddress = existingNode.getSourceAddress();+ if (!newAddress.equals(exitingAddress)) {+ return false; // different source addresses; nothing to do+ }++ if (nodeToAdd.isCallReference() == existingNode.isCallReference()) {+ return false; // same reference type; nothing to do}+ // The 2 given nodes point to the same function and from the same address. Remove the+ // existing node if it is not a call reference. Otherwise, if the new node is not a call+ // reference, then the existing node is and we should just throw away the new node.+ if (!existingNode.isCallReference()) {+ // swap the old node for the new one+ nodes.remove(existingNode);+ nodes.add(nodeToAdd);+ }+ // else { // ignore the new node by returning true+ return true; // return true to signal we have handled the new node}protected class CallNodeComparator implements Comparator<GTreeNode> {@@ -137,9 +197,10 @@ public abstract class CallNode extends GTreeSlowLoadingNode {if (addrCompare != 0) {return addrCompare;}- return Boolean.compare(node1.isCallRef, node2.isCallRef);+ return Boolean.compare(node1.isCallReference, node2.isCallReference);}+}@Override@@ -189,7 +250,7 @@ public abstract class CallNode extends GTreeSlowLoadingNode {if (!Objects.equals(getSourceAddress(), other.getSourceAddress())) {return false;}- if (other.isCallRef != isCallRef) {+ if (other.isCallReference != isCallReference) {return false;}return Objects.equals(getRemoteFunction(), other.getRemoteFunction());@@ -199,7 +260,7 @@ public abstract class CallNode extends GTreeSlowLoadingNode {public int hashCode() {final int prime = 31;int result = super.hashCode();- result = prime * result + Boolean.hashCode(isCallRef);+ result = prime * result + Boolean.hashCode(isCallReference);Function function = getRemoteFunction();result = prime * result + ((function == null) ? 0 : function.hashCode());Address sourceAddress = getSourceAddress();diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeOptions.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeOptions.javaindex 21ae4fe44b..5bf24bb61c 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeOptions.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeOptions.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.@@ -26,10 +26,12 @@ public class CallTreeOptions {private static final String RECURSE_DEPTH_KEY = "RECURSE_DEPTH";private static final String FILTER_DUPLICATES_KEY = "FILTER_DUPLICATES";+ private static final String FILTER_REFERENCES_KEY = "FILTER_REFERENCES";private static final String FILTER_THUNKS_KEY = "FILTER_THUNKS";private static final String SHOW_NAMESPACE_KEY = "SHOW_NAMESPACE";private boolean filterDuplicates = true;+ private boolean filterReferences = false;private boolean filterThunks = false;private boolean showNamespace = false;private int recurseDepth = Integer.parseInt(DEFAULT_RECURSE_DEPTH);@@ -40,6 +42,7 @@ public class CallTreeOptions {CallTreeOptions(SaveState saveState) {filterDuplicates = saveState.getBoolean(FILTER_DUPLICATES_KEY, true);+ filterReferences = saveState.getBoolean(FILTER_REFERENCES_KEY, true);filterThunks = saveState.getBoolean(FILTER_THUNKS_KEY, false);showNamespace = saveState.getBoolean(SHOW_NAMESPACE_KEY, false);recurseDepth = saveState.getInt(RECURSE_DEPTH_KEY, recurseDepth);@@ -47,6 +50,7 @@ public class CallTreeOptions {void save(SaveState saveState) {saveState.putBoolean(FILTER_DUPLICATES_KEY, filterDuplicates);+ saveState.putBoolean(FILTER_REFERENCES_KEY, filterReferences);saveState.putBoolean(FILTER_THUNKS_KEY, filterThunks);saveState.putBoolean(SHOW_NAMESPACE_KEY, showNamespace);saveState.putInt(RECURSE_DEPTH_KEY, recurseDepth);@@ -69,6 +73,15 @@ public class CallTreeOptions {return !filterDuplicates;}+ /**+ * This value is based on the {@code filterReferences} value. When filtering references, we+ * only allow call references to be shown.+ * @return true if allowing all reference types+ */+ public boolean allowsNonCallReferences() {+ return !filterReferences;+ }+public boolean allowsThunks() {return !filterThunks;}@@ -89,6 +102,12 @@ public class CallTreeOptions {return copy;}+ public CallTreeOptions withFilterReferences(boolean filter) {+ CallTreeOptions copy = copy();+ copy.filterReferences = filter;+ return copy;+ }+public CallTreeOptions withFilterThunks(boolean filter) {CallTreeOptions copy = copy();copy.filterThunks = filter;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.javaindex c4c396c581..3194f7b8d3 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@@ -15,15 +15,13 @@*/package ghidra.app.plugin.core.calltree;-import java.util.ArrayList;-import java.util.List;+import java.util.*;import javax.swing.Icon;import docking.ActionContext;import docking.action.DockingAction;import docking.action.MenuData;-import generic.theme.GIcon;import ghidra.app.CorePluginPackage;import ghidra.app.context.FunctionSupplierContext;import ghidra.app.context.ListingActionContext;@@ -39,7 +37,9 @@ import ghidra.program.model.symbol.Reference;import ghidra.program.model.symbol.ReferenceManager;import ghidra.program.util.ProgramLocation;import ghidra.util.HelpLocation;+import ghidra.util.StringUtilities;import resources.Icons;+import util.CollectionUtils;/*** Assuming a function <b>foo</b>, this plugin will show:@@ -63,9 +63,6 @@ import resources.Icons;public class CallTreePlugin extends ProgramPlugin {static final Icon PROVIDER_ICON = Icons.ARROW_DOWN_RIGHT_ICON;- static final Icon FUNCTION_ICON = new GIcon("icon.plugin.calltree.function");- static final Icon RECURSIVE_ICON = new GIcon("icon.plugin.calltree.recursive");- static final Icon DATA_ICON = new GIcon("icon.plugin.calltree.data");private List<CallTreeProvider> providers = new ArrayList<>();private DockingAction showCallTreeFromMenuAction;@@ -125,6 +122,20 @@ public class CallTreePlugin extends ProgramPlugin {}}+ private CallTreeProvider findTransientProviderForLocation(Function function) {+ for (CallTreeProvider provider : providers) {+ if (!provider.isTransient()) {+ continue;+ }++ if (provider.isShowingFunction(function)) {+ return provider;+ }+ }+ return null;+ }++ // Used by tests to find providers by locationCallTreeProvider findTransientProviderForLocation(ProgramLocation location) {for (CallTreeProvider provider : providers) {if (!provider.isTransient()) {@@ -142,28 +153,32 @@ public class CallTreePlugin extends ProgramPlugin {// use the name of the provider so that the shared key binding data will get usedString actionName = "Static Function Call Trees";+ String group = "ShowReferencesTo";showCallTreeFromMenuAction = new DockingAction(actionName, getName()) {@Overridepublic void actionPerformed(ActionContext context) {- showOrCreateNewCallTree(currentLocation);+ Function f = getFunction(context);+ showNewCallTree(f);}@Override- public boolean isAddToPopup(ActionContext context) {- if (context instanceof ListingActionContext) {- return true;+ public boolean isEnabledForContext(ActionContext context) {+ Function f = getFunction(context);+ if (f == null) {+ return false;}- if (context instanceof FunctionSupplierContext functionContext) {- return functionContext.hasFunctions();- }+ String menuText = "Show Call Trees for " + f.getName();+ String trimmedMenuText = StringUtilities.trim(menuText, 50);- return false;+ setPopupMenuData(new MenuData(+ new String[] { "References", trimmedMenuText }, PROVIDER_ICON, group));+ return true;}};showCallTreeFromMenuAction.setPopupMenuData(new MenuData(- new String[] { "References", "Show Call Trees" }, PROVIDER_ICON, "ShowReferencesTo"));+ new String[] { "References", "Show Call Trees" }, PROVIDER_ICON, group));showCallTreeFromMenuAction.setHelpLocation(new HelpLocation("CallTreePlugin", "Call_Tree_Plugin"));showCallTreeFromMenuAction.setDescription("Shows the Function Call Trees window for the " +@@ -171,14 +186,36 @@ public class CallTreePlugin extends ProgramPlugin {tool.addAction(showCallTreeFromMenuAction);}- private void createAndShowProvider(ProgramLocation location) {+ private Function getFunction(ActionContext context) {++ if (context instanceof ListingActionContext) {+ //+ // Unusual Code: We know that the ListingActionContext is a FunctionSupplierContext.+ // We also know that this context does not report the current function as specifically+ // as we would like. So, handle this case ourselves. The fall-through case will allow+ // this plugin to work in other places like the Decompiler or the Functions window.+ //+ return getFunction(currentLocation);+ }++ if (context instanceof FunctionSupplierContext functionContext) {+ if (functionContext.hasFunctions()) {+ Set<Function> functions = functionContext.getFunctions();+ return CollectionUtils.any(functions);+ }+ }++ return getFunction(currentLocation);+ }++ private void createAndShowProvider(Function function) {CallTreeProvider provider = new CallTreeProvider(this, false);CallTreeOptions callTreeOptions = primaryProvider.getCallTreeOptions();provider.setCallTreeOptions(callTreeOptions);providers.add(provider);- provider.initialize(currentProgram, location);+ provider.initialize(currentProgram, function);tool.showComponentProvider(provider, true);}@@ -206,51 +243,34 @@ public class CallTreePlugin extends ProgramPlugin {provider.dispose();}- void showOrCreateNewCallTree(ProgramLocation location) {+ void showNewCallTree(Function function) {if (currentProgram == null) {return; // no program; cannot show tool}- CallTreeProvider provider = findTransientProviderForLocation(location);+ CallTreeProvider provider = findTransientProviderForLocation(function);if (provider != null) {tool.showComponentProvider(provider, true);return;}- Function function = getFunction(location);- if (function == null) {- tool.setStatusInfo("No function containing address: " + location.getAddress(), true);- return;- }-- createAndShowProvider(location);+ createAndShowProvider(function);}- Function getFunction(ProgramLocation location) {+ private Function getFunction(ProgramLocation location) {+ if (location == null) {+ return null;+ }FunctionManager functionManager = currentProgram.getFunctionManager();Address address = location.getAddress();- Function function = functionManager.getFunctionContaining(address);- function = resolveFunction(function, address);- return function;- }-- /**- *- * Apparently, we create fake function markup for external functions. Thus, there is no- * real function at that address and our plugin has to do some work to find out where- * we 'hang' references to the external function, which is itself a Function. These- * fake function will usually just be a pointer to another function.- *- * @param function the function to resolve; if it is not null, then it will be used- * @param address the address for which to find a function- * @return either the given function if non-null, or a function being referenced from the- * given address.- */- Function resolveFunction(Function function, Address address) {- if (function != null) {- return function;+ Function destinationFunction = getReferencedFunction(address);+ if (destinationFunction != null) {+ return destinationFunction;}+ return functionManager.getFunctionContaining(address);+ }+ Function getReferencedFunction(Address address) {// maybe we point to another function?FunctionManager functionManager = currentProgram.getFunctionManager();ReferenceManager referenceManager = currentProgram.getReferenceManager();@@ -262,7 +282,6 @@ public class CallTreePlugin extends ProgramPlugin {return toFunction;}}-return null;}}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.javaindex e07785ba5f..7ca3d922f5 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@@ -45,8 +45,7 @@ import ghidra.framework.options.SaveState;import ghidra.framework.plugintool.ComponentProviderAdapter;import ghidra.program.database.symbol.FunctionSymbol;import ghidra.program.model.address.*;-import ghidra.program.model.listing.Function;-import ghidra.program.model.listing.Program;+import ghidra.program.model.listing.*;import ghidra.program.model.symbol.Symbol;import ghidra.program.util.*;import ghidra.util.HelpLocation;@@ -81,11 +80,12 @@ public class CallTreeProvider extends ComponentProviderAdapter {private Program currentProgram;private Function currentFunction;private DockingAction recurseDepthAction;- private ToggleDockingAction filterDuplicates;+ private ToggleDockingAction unifyFunctionsAction;+ private ToggleDockingAction filterNonCallsAction;private ToggleDockingAction filterThunksAction;private ToggleDockingAction showNamespaceAction;private ToggleDockingAction navigationOutgoingAction;- private ToggleDockingAction navigateIncomingToggleAction;+ private ToggleDockingAction navigateIncomingAction;private DockingAction refreshAction;private CallTreeOptions callTreeOptions = new CallTreeOptions();@@ -362,24 +362,48 @@ public class CallTreeProvider extends ComponentProviderAdapter {tool.addLocalAction(this, goToSourceAction);//- // filter duplicates action+ // Unify Functions action//- filterDuplicates = new ToggleDockingAction("Filter Duplicates", plugin.getName()) {+ unifyFunctionsAction = new ToggleDockingAction("Unify Functions", plugin.getName()) {@Overridepublic void actionPerformed(ActionContext context) {callTreeOptions = callTreeOptions.withFilterDuplicates(isSelected());doUpdate();}};- filterDuplicates.setToolBarData(new ToolBarData(- new GIcon("icon.plugin.calltree.filter.duplicates"), filterOptionsToolbarGroup, "1"));- filterDuplicates.setSelected(true);- filterDuplicates- .setHelpLocation(new HelpLocation(plugin.getName(), "Call_Tree_Action_Filter"));- tool.addLocalAction(this, filterDuplicates);+ unifyFunctionsAction.setToolBarData(new ToolBarData(+ new GIcon("icon.plugin.calltree.unify.functions"), filterOptionsToolbarGroup, "1"));+ unifyFunctionsAction.setSelected(true);+ unifyFunctionsAction+ .setDescription("<html>Filters the trees to only show one node per function,<br>" ++ "regardless of how many incoming or outgoing references exist at a given level");+ unifyFunctionsAction+ .setHelpLocation(+ new HelpLocation(plugin.getName(), "Call_Tree_Action_Unify_Functions"));+ tool.addLocalAction(this, unifyFunctionsAction);//- // recurse depth+ // Filter Non-calls action+ //+ filterNonCallsAction = new ToggleDockingAction("Filter Non-calls", plugin.getName()) {+ @Override+ public void actionPerformed(ActionContext context) {+ callTreeOptions = callTreeOptions.withFilterReferences(isSelected());+ doUpdate();+ }+ };+ filterNonCallsAction.setToolBarData(new ToolBarData(+ new GIcon("icon.plugin.calltree.filter.non.calls"), filterOptionsToolbarGroup, "2"));+ filterNonCallsAction.setSelected(true);+ filterNonCallsAction+ .setDescription("Filters the trees to only show function call references");+ filterNonCallsAction+ .setHelpLocation(+ new HelpLocation(plugin.getName(), "Call_Tree_Action_Filter_Calls"));+ tool.addLocalAction(this, filterNonCallsAction);++ //+ // Recurse Depth action//recurseDepthAction = new DockingAction("Recurse Depth", plugin.getName()) {@Override@@ -402,14 +426,14 @@ public class CallTreeProvider extends ComponentProviderAdapter {int recurseDepth = callTreeOptions.getRecurseDepth();recurseIcon = new NumberIcon(recurseDepth);recurseDepthAction- .setToolBarData(new ToolBarData(recurseIcon, filterOptionsToolbarGroup, "2"));+ .setToolBarData(new ToolBarData(recurseIcon, filterOptionsToolbarGroup, "3"));recurseDepthAction.setHelpLocation(new HelpLocation(plugin.getName(), "Call_Tree_Action_Recurse_Depth"));tool.addLocalAction(this, recurseDepthAction);//- // navigate outgoing nodes on selection+ // Navigate outgoing nodes on selection action//navigationOutgoingAction =new ToggleDockingAction("Navigate Outgoing Nodes", plugin.getName()) {@@ -429,7 +453,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {//// navigate incoming nodes on selection//- navigateIncomingToggleAction =+ navigateIncomingAction =new ToggleDockingAction("Navigation Incoming Location Changes", plugin.getName()) {@Overridepublic void actionPerformed(ActionContext context) {@@ -449,16 +473,16 @@ public class CallTreeProvider extends ComponentProviderAdapter {// note: the default state is to follow navigation events for the primary provider;// non-primary providers will function like snapshots of the function with// which they were activated.- navigateIncomingToggleAction.setSelected(isPrimary);- navigateIncomingToggleAction.setToolBarData(new ToolBarData(+ navigateIncomingAction.setSelected(isPrimary);+ navigateIncomingAction.setToolBarData(new ToolBarData(Icons.NAVIGATE_ON_INCOMING_EVENT_ICON, navigationOptionsToolbarGroup, "2"));- navigateIncomingToggleAction.setDescription("<html>Incoming Navigation" ++ navigateIncomingAction.setDescription("<html>Incoming Navigation" +"<br><br>Toggle <b>On</b> - change the displayed " +"function on Listing navigation events" +"<br>Toggled <b>Off</b> - don't change the displayed function on Listing navigation events");- navigateIncomingToggleAction.setHelpLocation(+ navigateIncomingAction.setHelpLocation(new HelpLocation(plugin.getName(), "Call_Tree_Action_Incoming_Navigation"));- tool.addLocalAction(this, navigateIncomingToggleAction);+ tool.addLocalAction(this, navigateIncomingAction);//// selection actions@@ -574,7 +598,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {tool.addLocalAction(this, selectDestinationAction);//- // home button+ // Home action//DockingAction homeAction = new DockingAction("Home", plugin.getName()) {@Override@@ -617,9 +641,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {GTree gTree = (GTree) context.getContextObject();TreePath[] selectionPaths = gTree.getSelectionPaths();CallNode callNode = (CallNode) selectionPaths[0].getLastPathComponent();- ProgramLocation location = new ProgramLocation(currentProgram,- callNode.getRemoteFunction().getEntryPoint());- plugin.showOrCreateNewCallTree(location);+ plugin.showNewCallTree(callNode.getRemoteFunction());}@Override@@ -896,9 +918,10 @@ public class CallTreeProvider extends ComponentProviderAdapter {recurseDepthAction.dispose();refreshAction.dispose();- filterDuplicates.dispose();+ unifyFunctionsAction.dispose();+ filterNonCallsAction.dispose();navigationOutgoingAction.dispose();- navigateIncomingToggleAction.dispose();+ navigateIncomingAction.dispose();}void setLocation(ProgramLocation location) {@@ -914,12 +937,23 @@ public class CallTreeProvider extends ComponentProviderAdapter {return;}- doSetLocation(location);+ if (location == null) {+ return;+ }++ Address address = location.getAddress();+ FunctionManager functionManager = currentProgram.getFunctionManager();+ Function function = functionManager.getFunctionContaining(address);+ if (function == null) {+ function = plugin.getReferencedFunction(address);+ }++ doSetFunction(function);}- private void doSetLocation(ProgramLocation location) {- if (location == null) {- setFunction(null);+ // used by tests+ void doSetFunction(Function function) {+ if (function == null) {return;}@@ -932,20 +966,16 @@ public class CallTreeProvider extends ComponentProviderAdapter {currentProgram.addListener(domainObjectListener);}- Function function = plugin.getFunction(location);- setFunction(function);- }-- private void setFunction(Function function) {- if (function != null && function.equals(currentFunction)) {+ if (function.equals(currentFunction)) {return;}- doSetFunction(function);+ currentFunction = function;+ updateUiForFunction(function);}- private void doSetFunction(Function function) {- currentFunction = function;+ private void updateUiForFunction(Function function) {+notifyContextChanged();if (currentFunction == null) {clearTrees();@@ -1022,7 +1052,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {setSubTitle(subTitle);}- void initialize(Program program, ProgramLocation location) {+ void initialize(Program program, Function function) {if (program == null) { // no program opensetLocation(null);return;@@ -1030,7 +1060,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {currentProgram = program;currentProgram.addListener(domainObjectListener);- doSetLocation(location);+ doSetFunction(function);}void programActivated(Program program) {@@ -1069,6 +1099,8 @@ public class CallTreeProvider extends ComponentProviderAdapter {void setCallTreeOptions(CallTreeOptions callTreeOptions) {this.callTreeOptions = callTreeOptions;recurseIcon.setNumber(callTreeOptions.getRecurseDepth());+ unifyFunctionsAction.setSelected(!callTreeOptions.allowsDuplicates());+ filterNonCallsAction.setSelected(!callTreeOptions.allowsNonCallReferences());}void readConfigState(SaveState saveState) {@@ -1086,6 +1118,10 @@ public class CallTreeProvider extends ComponentProviderAdapter {reloadUpdateManager.update();}+ boolean isShowingFunction(Function function) {+ return currentFunction == function; // yes, '=='+ }+boolean isShowingLocation(ProgramLocation location) {if (currentFunction == null) {return false;@@ -1096,7 +1132,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {}private boolean followLocationChanges() {- return navigateIncomingToggleAction.isSelected();+ return navigateIncomingAction.isSelected();}private DomainObjectListener createDomainObjectListener() {@@ -1105,7 +1141,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {.ignoreWhen(() -> !isVisible() || isEmpty()).any(RESTORED).terminate(() -> setStale(true)).any(MEMORY_BLOCK_MOVED, MEMORY_BLOCK_REMOVED, SYMBOL_ADDED, SYMBOL_REMOVED,- REFERENCE_ADDED, REFERENCE_REMOVED)+ REFERENCE_ADDED, REFERENCE_REMOVED, REFERENCE_TYPE_CHANGED).call(() -> setStale(true)).with(ProgramChangeRecord.class).each(SYMBOL_RENAMED).call(r -> handleSymbolRenamed(r))@@ -1258,7 +1294,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {@Overridepublic Icon getIcon(boolean expanded) {- return CallTreePlugin.FUNCTION_ICON;+ return CallNode.FUNCTION_ICON;}@Overridediff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/DeadEndNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/DeadEndNode.javaindex 1a6dac4298..655e5ea1d8 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/DeadEndNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/DeadEndNode.java@@ -29,16 +29,15 @@ import ghidra.program.model.symbol.*;import ghidra.program.util.ProgramLocation;import ghidra.util.exception.CancelledException;import ghidra.util.task.TaskMonitor;-import resources.MultiIcon;-import resources.icons.TranslateIcon;public class DeadEndNode extends CallNode {- private static final Icon ICON = new GIcon("icon.plugin.calltree.node.dead.end");+ private static final Icon DEAD_END_ICON = new GIcon("icon.plugin.calltree.node.dead.end");+ private static final Icon CALL_REFERENCE_ICON = createIcon(DEAD_END_ICON, true);+ private static final Icon NON_CALL_REFERENCE_ICON = createIcon(DEAD_END_ICON, false);private final Reference reference;private String name;- private MultiIcon deadEndIcon;private final Program program;@@ -46,12 +45,7 @@ public class DeadEndNode extends CallNode {super(callTreeOptions);this.program = program;this.reference = reference;- this.isCallRef = reference.getReferenceType().isCall();- deadEndIcon = new MultiIcon(ICON, false, 32, 16);- TranslateIcon translateIcon =- isCallRef ? new TranslateIcon(CallTreePlugin.FUNCTION_ICON, 16, 0)- : new TranslateIcon(CallTreePlugin.DATA_ICON, 16, 0);- deadEndIcon.addIcon(translateIcon);+ this.isCallReference = reference.getReferenceType().isCall();}@Override@@ -80,7 +74,7 @@ public class DeadEndNode extends CallNode {@Overridepublic Icon getIcon(boolean expanded) {- return deadEndIcon;+ return isCallReference ? CALL_REFERENCE_ICON : NON_CALL_REFERENCE_ICON;}@Overridediff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/ExternalCallNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/ExternalCallNode.javaindex 37390e1812..121c8ecfa1 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/ExternalCallNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/ExternalCallNode.java@@ -28,32 +28,24 @@ import ghidra.program.util.FunctionSignatureFieldLocation;import ghidra.program.util.ProgramLocation;import ghidra.util.exception.CancelledException;import ghidra.util.task.TaskMonitor;-import resources.MultiIcon;-import resources.icons.TranslateIcon;public class ExternalCallNode extends CallNode {private static final Icon EXTERNAL_ICON = new GIcon("icon.plugin.calltree.node.external");- private MultiIcon externalFunctionIcon;+ private static final Icon CALL_REFERENCE_ICON = createIcon(EXTERNAL_ICON, true);+ private static final Icon NON_CALL_REFERENCE_ICON = createIcon(EXTERNAL_ICON, false);private final Function function;private final Address sourceAddress;private final String name;ExternalCallNode(Function function, Address sourceAddress,- boolean isCallRef, CallTreeOptions callTreeOptions) {+ boolean isCallReference, CallTreeOptions callTreeOptions) {super(callTreeOptions);this.function = function;this.sourceAddress = sourceAddress;this.name = function.getName();- this.isCallRef = isCallRef;-- externalFunctionIcon = new MultiIcon(EXTERNAL_ICON, false, 32, 16);- TranslateIcon translateIcon =- isCallRef ? new TranslateIcon(CallTreePlugin.FUNCTION_ICON, 16, 0)- : new TranslateIcon(CallTreePlugin.DATA_ICON, 16, 0);- externalFunctionIcon.addIcon(translateIcon);-+ this.isCallReference = isCallReference;}@Override@@ -63,7 +55,7 @@ public class ExternalCallNode extends CallNode {@OverrideCallNode recreate() {- return new ExternalCallNode(function, sourceAddress, isCallRef, callTreeOptions);+ return new ExternalCallNode(function, sourceAddress, isCallReference, callTreeOptions);}@Override@@ -88,7 +80,7 @@ public class ExternalCallNode extends CallNode {@Overridepublic Icon getIcon(boolean expanded) {- return externalFunctionIcon;+ return isCallReference ? CALL_REFERENCE_ICON : NON_CALL_REFERENCE_ICON;}@Overridediff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/IncomingCallNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/IncomingCallNode.javaindex b1473d24c7..ee2785bdbf 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/IncomingCallNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/IncomingCallNode.java@@ -32,13 +32,14 @@ import ghidra.program.util.ProgramLocation;import ghidra.util.exception.CancelledException;import ghidra.util.task.TaskMonitor;import resources.Icons;-import resources.MultiIcon;-import resources.icons.TranslateIcon;public class IncomingCallNode extends CallNode {private static final Icon INCOMING_ICON = Icons.ARROW_UP_LEFT_ICON;- private Icon incomingFunctionIcon;+ private static final Icon CALL_REFERENCE_ICON = createIcon(INCOMING_ICON, true);+ private static final Icon NON_CALL_REFERENCE_ICON = createIcon(INCOMING_ICON, false);+ private static final Icon RECURSIVE_CALL_REFERENCE_ICON = createIcon(RECURSIVE_ICON, true);+ private static final Icon RECURSIVE_NON_CALL_REFERENCE_ICON = createIcon(RECURSIVE_ICON, false);private Icon icon = null;private final Address functionAddress;@@ -47,27 +48,21 @@ public class IncomingCallNode extends CallNode {protected String name;private final Address sourceAddress;- IncomingCallNode(Program program, Function function, Address sourceAddress, boolean isCallRef,- CallTreeOptions callTreeOptions) {+ IncomingCallNode(Program program, Function function, Address sourceAddress,+ boolean isCallReference, CallTreeOptions callTreeOptions) {super(callTreeOptions);this.program = program;this.function = function;this.name = function.getName(callTreeOptions.showNamespace());this.sourceAddress = sourceAddress;this.functionAddress = function.getEntryPoint();- this.isCallRef = isCallRef;-- MultiIcon multiIcon = new MultiIcon(INCOMING_ICON, false, 32, 16);- TranslateIcon translateIcon =- isCallRef ? new TranslateIcon(CallTreePlugin.FUNCTION_ICON, 16, 0)- : new TranslateIcon(CallTreePlugin.DATA_ICON, 16, 0);- multiIcon.addIcon(translateIcon);- incomingFunctionIcon = multiIcon;+ this.isCallReference = isCallReference;}@OverrideCallNode recreate() {- return new IncomingCallNode(program, function, sourceAddress, isCallRef, callTreeOptions);+ return new IncomingCallNode(program, function, sourceAddress, isCallReference,+ callTreeOptions);}@Override@@ -110,7 +105,9 @@ public class IncomingCallNode extends CallNode {// If we are not showing thunks, then replace each thunk with all calls to that thunkif (caller.isThunk() && !callTreeOptions.allowsThunks()) {Address callerEntry = caller.getEntryPoint();- doGenerateChildren(callerEntry, results, monitor);+ if (!address.equals(callerEntry)) { // recursive reference from thunk to itself+ doGenerateChildren(callerEntry, results, monitor);+ }continue;}@@ -135,14 +132,12 @@ public class IncomingCallNode extends CallNode {@Overridepublic Icon getIcon(boolean expanded) {if (icon == null) {- icon = incomingFunctionIcon;if (functionIsInPath()) {- MultiIcon multiIcon = new MultiIcon(CallTreePlugin.RECURSIVE_ICON, false, 32, 16);- TranslateIcon translateIcon =- isCallRef ? new TranslateIcon(CallTreePlugin.FUNCTION_ICON, 16, 0)- : new TranslateIcon(CallTreePlugin.DATA_ICON, 16, 0);- multiIcon.addIcon(translateIcon);- icon = multiIcon;+ icon = isCallReference ? RECURSIVE_CALL_REFERENCE_ICON+ : RECURSIVE_NON_CALL_REFERENCE_ICON;+ }+ else {+ icon = isCallReference ? CALL_REFERENCE_ICON : NON_CALL_REFERENCE_ICON;}}return icon;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/IncomingCallsRootNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/IncomingCallsRootNode.javaindex a037b78b31..326a8ad26d 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/IncomingCallsRootNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/IncomingCallsRootNode.java@@ -36,7 +36,7 @@ public class IncomingCallsRootNode extends IncomingCallNode {@Overridepublic Icon getIcon(boolean expanded) {- return CallTreePlugin.FUNCTION_ICON;+ return FUNCTION_ICON;}@Overridediff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingCallNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingCallNode.javaindex 4a3b88df48..92e9e021ed 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingCallNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingCallNode.java@@ -32,13 +32,14 @@ import ghidra.program.util.ProgramLocation;import ghidra.util.exception.CancelledException;import ghidra.util.task.TaskMonitor;import resources.Icons;-import resources.MultiIcon;-import resources.icons.TranslateIcon;public class OutgoingCallNode extends CallNode {private static final Icon OUTGOING_ICON = Icons.ARROW_DOWN_RIGHT_ICON;- private final Icon outgoingFunctionIcon;+ private static final Icon CALL_REFERENCE_ICON = createIcon(OUTGOING_ICON, true);+ private static final Icon NON_CALL_REFERENCE_ICON = createIcon(OUTGOING_ICON, false);+ private static final Icon RECURSIVE_CALL_REFERENCE_ICON = createIcon(RECURSIVE_ICON, true);+ private static final Icon RECURSIVE_NON_CALL_REFERENCE_ICON = createIcon(RECURSIVE_ICON, false);private Icon icon = null;protected final Program program;@@ -47,24 +48,19 @@ public class OutgoingCallNode extends CallNode {private final Address sourceAddress;OutgoingCallNode(Program program, Function function, Address sourceAddress,- boolean isCallRef, CallTreeOptions callTreeOptions) {+ boolean isCallReference, CallTreeOptions callTreeOptions) {super(callTreeOptions);this.program = program;this.function = function;this.name = function.getName(callTreeOptions.showNamespace());this.sourceAddress = sourceAddress;- this.isCallRef = isCallRef;-- MultiIcon multiIcon = new MultiIcon(OUTGOING_ICON, false, 32, 16);- TranslateIcon translateIcon = new TranslateIcon(- isCallRef ? CallTreePlugin.FUNCTION_ICON : CallTreePlugin.DATA_ICON, 16, 0);- multiIcon.addIcon(translateIcon);- outgoingFunctionIcon = multiIcon;+ this.isCallReference = isCallReference;}@OverrideCallNode recreate() {- return new OutgoingCallNode(program, function, sourceAddress, isCallRef, callTreeOptions);+ return new OutgoingCallNode(program, function, sourceAddress, isCallReference,+ callTreeOptions);}@Override@@ -97,7 +93,7 @@ public class OutgoingCallNode extends CallNode {AddressRangeIterator rangeIter = currentFunction.getBody().getAddressRanges();while (rangeIter.hasNext()) {AddressRange range = rangeIter.next();- ReferenceIterator refIter =refManager.getReferenceIterator(range.getMinAddress());+ ReferenceIterator refIter = refManager.getReferenceIterator(range.getMinAddress());while (refIter.hasNext()) {monitor.checkCancelled();Reference reference = refIter.next();@@ -110,12 +106,14 @@ public class OutgoingCallNode extends CallNode {createNode(nodesByFunction, reference, calledFunction);continue;}+// If we are not showing thunks, then replace the thunk with the thunked functionif (calledFunction.isThunk() && !callTreeOptions.allowsThunks()) {Function thunkedFunction = calledFunction.getThunkedFunction(true);createNode(nodesByFunction, reference, thunkedFunction);continue;}+createNode(nodesByFunction, reference, calledFunction);}}@@ -143,7 +141,7 @@ public class OutgoingCallNode extends CallNode {callTreeOptions));}}- else if (isCallReference(reference)) {+ else if (isReferencingFunction(reference)) {Function externalFunction = getExternalFunctionTempHackWorkaround(reference);if (externalFunction != null) {@@ -183,7 +181,7 @@ public class OutgoingCallNode extends CallNode {return calledFunction.isExternal();}- private boolean isCallReference(Reference reference) {+ private boolean isReferencingFunction(Reference reference) {RefType type = reference.getReferenceType();if (type.isCall()) {return true;@@ -234,14 +232,12 @@ public class OutgoingCallNode extends CallNode {@Overridepublic Icon getIcon(boolean expanded) {if (icon == null) {- icon = outgoingFunctionIcon;if (functionIsInPath()) {- MultiIcon multiIcon = new MultiIcon(CallTreePlugin.RECURSIVE_ICON, false, 32, 16);- TranslateIcon translateIcon =- isCallRef ? new TranslateIcon(CallTreePlugin.FUNCTION_ICON, 16, 0)- : new TranslateIcon(CallTreePlugin.DATA_ICON, 16, 0);- multiIcon.addIcon(translateIcon);- icon = multiIcon;+ icon = isCallReference ? RECURSIVE_CALL_REFERENCE_ICON+ : RECURSIVE_NON_CALL_REFERENCE_ICON;+ }+ else {+ icon = isCallReference ? CALL_REFERENCE_ICON : NON_CALL_REFERENCE_ICON;}}return icon;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingCallsRootNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingCallsRootNode.javaindex 565c4f4ba4..a06b66056b 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingCallsRootNode.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingCallsRootNode.java@@ -35,7 +35,7 @@ public class OutgoingCallsRootNode extends OutgoingCallNode {@Overridepublic Icon getIcon(boolean expanded) {- return CallTreePlugin.FUNCTION_ICON;+ return FUNCTION_ICON;}@Overridediff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.javaindex 6f723e9e09..0fa47221f4 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/database/ProgramBuilder.java@@ -1113,7 +1113,7 @@ public class ProgramBuilder {});}- private <E extends Exception> void tx(ExceptionalCallback<E> c) {+ public <E extends Exception> void tx(ExceptionalCallback<E> c) {startTransaction();boolean commit = true;try {@@ -1128,7 +1128,7 @@ public class ProgramBuilder {}}- private <R, E extends Exception> R tx(ExceptionalSupplier<R, E> s) {+ public <R, E extends Exception> R tx(ExceptionalSupplier<R, E> s) {startTransaction();boolean commit = true;try {@@ -1143,7 +1143,7 @@ public class ProgramBuilder {}}- private interface ExceptionalSupplier<R, E extends Exception> {+ public interface ExceptionalSupplier<R, E extends Exception> {public R get() throws E;}}diff --git a/Ghidra/Features/Base/src/main/resources/images/icon_link.gif b/Ghidra/Features/Base/src/main/resources/images/icon_link.gifnew file mode 100644index 0000000000..c64c23c1fdBinary files /dev/null and b/Ghidra/Features/Base/src/main/resources/images/icon_link.gif differdiff --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.javaindex a4a5c91be1..e94b4f990a 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@@ -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.@@ -153,6 +153,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {function(0x6000, 0x7000);function(0x6100, 0x7100);function(0x7000, 0x8000);+function(0x8000, 0x9000);function(0x9000, 0x10000);@@ -608,9 +609,9 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {setProviderFunction("0x5000");- ToggleDockingAction filterDuplicatesAction =- (ToggleDockingAction) getAction("Filter Duplicates");- setToggleActionSelected(filterDuplicatesAction, new DefaultActionContext(), true);+ ToggleDockingAction unifyFunctions =+ (ToggleDockingAction) getAction("Unify Functions");+ setToggleActionSelected(unifyFunctions, new DefaultActionContext(), true);waitForTree(outgoingTree);GTreeNode rootNode = getRootNode(outgoingTree);@@ -618,7 +619,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {Map<String, List<GTreeNode>> nameCountMap = createNameCountMap(rootNode);assertDuplicateChildStatus(nameCountMap, shouldHaveDuplicates);- performAction(filterDuplicatesAction, true);// deselect+ performAction(unifyFunctions, true);// deselectwaitForTree(outgoingTree);@@ -640,10 +641,10 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {setProviderFunction("0x5000");- ToggleDockingAction filterDuplicatesAction =- (ToggleDockingAction) getAction("Filter Duplicates");+ ToggleDockingAction unifyFunctions =+ (ToggleDockingAction) getAction("Unify Functions");- setToggleActionSelected(filterDuplicatesAction, new DefaultActionContext(), true);+ setToggleActionSelected(unifyFunctions, new DefaultActionContext(), true);waitForTree(outgoingTree);GTreeNode rootNode = getRootNode(outgoingTree);@@ -652,7 +653,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {// 1, not 2 entries (the exact duplicate and the duplicate destination are ignored)assertEquals(1, nameCountMap.get("Function_6000").size());- performAction(filterDuplicatesAction, true);// deselect+ performAction(unifyFunctions, true);// deselectwaitForTree(outgoingTree);rootNode = getRootNode(outgoingTree);@@ -674,9 +675,9 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {setProviderFunction("0x5000");- ToggleDockingAction filterDuplicatesAction =- (ToggleDockingAction) getAction("Filter Duplicates");- setToggleActionSelected(filterDuplicatesAction, new DefaultActionContext(), true);+ ToggleDockingAction unifyFunctions =+ (ToggleDockingAction) getAction("Unify Functions");+ setToggleActionSelected(unifyFunctions, new DefaultActionContext(), true);waitForTree(outgoingTree);GTreeNode rootNode = getRootNode(outgoingTree);@@ -684,7 +685,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {Map<String, List<GTreeNode>> nameCountMap = createNameCountMap(rootNode);assertDuplicateChildStatus(nameCountMap, shouldHaveDuplicates);- performAction(filterDuplicatesAction, true);// deselect+ performAction(unifyFunctions, true);// deselectwaitForTree(outgoingTree);@@ -717,9 +718,9 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {setProviderFunction("0x0000");- ToggleDockingAction filterDuplicatesAction =- (ToggleDockingAction) getAction("Filter Duplicates");- setToggleActionSelected(filterDuplicatesAction, new DefaultActionContext(), true);+ ToggleDockingAction unifyFunctions =+ (ToggleDockingAction) getAction("Unify Functions");+ setToggleActionSelected(unifyFunctions, new DefaultActionContext(), true);waitForTree(incomingTree);// copy the names of the children into a map so that we can verify no duplicates@@ -1215,13 +1216,10 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {}private void setProviderFunction(String address) {- final Address addr = addr(address);+ Address addr = addr(address);+ Function function = getFunction(addr);goTo(addr);- runSwing(() -> {- ProgramLocation location = new ProgramLocation(program, addr);- invokeInstanceMethod("doSetLocation", provider, new Class[] { ProgramLocation.class },- new Object[] { location });- });+ runSwing(() -> provider.doSetFunction(function));waitForSwing();waitForTree(incomingTree);@@ -1261,7 +1259,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {}if (node instanceof GTreeSlowLoadingNode) {- boolean loaded = ((GTreeSlowLoadingNode) node).isLoaded();+ boolean loaded = node.isLoaded();if (!loaded) {return null;// children not loaded--don't load}@@ -1286,7 +1284,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {private int getMaxNodeDepth(GTreeNode node, int currentDepth) {int maxDepth = currentDepth;if (node instanceof GTreeSlowLoadingNode) {- boolean loaded = ((GTreeSlowLoadingNode) node).isLoaded();+ boolean loaded = node.isLoaded();if (!loaded) {return maxDepth;// children not loaded--don't load}@@ -1383,7 +1381,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {}if (node instanceof GTreeSlowLoadingNode) {- boolean loaded = ((GTreeSlowLoadingNode) node).isLoaded();+ boolean loaded = node.isLoaded();if (!loaded) {return;// children not loaded--don't load}@@ -1479,7 +1477,10 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {DockingAction action = callTreePlugin.getShowCallTreeFromMenuAction();performAction(action);- return runSwing(() -> callTreePlugin.findTransientProviderForLocation(location));+ CallTreeProvider newProvider =+ runSwing(() -> callTreePlugin.findTransientProviderForLocation(location));+ assertNotNull(newProvider);+ return newProvider;}private Address addr(String address) {diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/IncomingCallNodeTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/IncomingCallNodeTest.javaindex 40d3467f68..08a6826d8e 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/IncomingCallNodeTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/IncomingCallNodeTest.java@@ -25,10 +25,11 @@ import docking.widgets.tree.GTreeNode;import generic.test.AbstractGenericTest;import ghidra.program.model.address.Address;import ghidra.program.model.data.DataType;+import ghidra.program.model.data.VoidDataType;import ghidra.program.model.listing.*;+import ghidra.program.model.symbol.*;import ghidra.test.ToyProgramBuilder;import ghidra.util.task.TaskMonitor;-import utility.function.ExceptionalCallback;public class IncomingCallNodeTest extends AbstractGenericTest {@@ -162,7 +163,7 @@ public class IncomingCallNodeTest extends AbstractGenericTest {String thunkAddress = "0x1050";Function thunkFunction =builder.createEmptyFunction("Thunk_Function_1050", thunkAddress, 10, DataType.DEFAULT);- tx(() -> {+ builder.tx(() -> {thunkFunction.setThunkedFunction(thunkedFunction);});@@ -174,22 +175,48 @@ public class IncomingCallNodeTest extends AbstractGenericTest {builder.createMemoryCallReference("0x1200", thunkAddress);}- private <E extends Exception> void tx(ExceptionalCallback<E> c) {- int txId = program.startTransaction("Test - Function in Transaction");- boolean commit = true;- try {- c.call();- program.flushEvents();- }- catch (Exception e) {- commit = false;- failWithException("Exception modifying program '" + program.getName() + "'", e);- }- finally {- program.endTransaction(txId, commit);- }+ @Test+ public void testGenerateChildren_MultipleReferences_SameSource_SameRemoteFunction()+ throws Exception {++ //+ // This is testing when more than 1 reference exists at an address to the same function.+ // We have code that will ensure that call references are preferred over other reference+ // types, creating one node for the call reference.+ //++ String toAddress = "0x1000";+ Function calledFunction =+ builder.createEmptyFunction("Function_1000", toAddress, 1, new VoidDataType());+ builder.addBytesFallthrough(firstCalledFunctionAddress);+ builder.disassemble(firstCalledFunctionAddress, 2);++ // create non-call read reference+ builder.createMemoryReference(firstCalledFunctionAddress, toAddress, RefType.READ,+ SourceType.USER_DEFINED);++ // create call reference at a different op index so both references can co-exist+ builder.tx(() -> {+ ReferenceManager refManager = program.getReferenceManager();+ Reference ref =+ refManager.addMemoryReference(addr(firstCalledFunctionAddress), addr(toAddress),+ RefType.UNCONDITIONAL_CALL, SourceType.USER_DEFINED, 1);+ return ref;+ });++ IncomingCallNode calledNode = new IncomingCallNode(program, calledFunction, addr(toAddress),+ true, new CallTreeOptions());++ List<GTreeNode> children = calledNode.generateChildren(TaskMonitor.DUMMY);+ assertEquals(1, children.size());+ IncomingCallNode outgoingNode = (IncomingCallNode) children.get(0);+ assertTrue(outgoingNode.isCallReference());}+//=================================================================================================+// Private Methods+//=================================================================================================+private Address addr(String addrString) {return builder.addr(addrString);}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/OutgoingCallNodeTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/OutgoingCallNodeTest.javaindex cbd65bfbbe..39b029e791 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/OutgoingCallNodeTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/OutgoingCallNodeTest.java@@ -306,10 +306,12 @@ public class OutgoingCallNodeTest extends AbstractGenericTest {}@Test- public void testGenerateChildren_ReadReference_NotCallInstruction() throws Exception {+ public void testGenerateChildren_ReadReference_NotCallInstruction_NoFunctionAtToAddress()+ throws Exception {//- // Read reference to an instruction with a flow type that is not a call+ // Read reference to an instruction with a flow type that is not a call. There is no+ // function a the destination.//builder.addBytesFallthrough(firstCalledFunctionAddress);@@ -321,6 +323,26 @@ public class OutgoingCallNodeTest extends AbstractGenericTest {assertTrue(children.isEmpty());}+ @Test+ public void testGenerateChildren_ReadReference_NotCallInstruction_FunctionAtToAddress()+ throws Exception {++ //+ // Read reference to an instruction with a flow type that is not a call. There is a+ // function at the destination.+ //++ String toAddress = "0x1000";+ builder.createEmptyFunction("Function_1000", toAddress, 1, new VoidDataType());+ builder.addBytesFallthrough(firstCalledFunctionAddress);+ builder.disassemble(firstCalledFunctionAddress, 2);++ builder.createMemoryReference(firstCalledFunctionAddress, toAddress, RefType.READ,+ SourceType.USER_DEFINED);+ List<GTreeNode> children = node1.generateChildren(TaskMonitor.DUMMY);+ assertEquals(1, children.size());+ }+@Testpublic void testGenerateChildren_ReadReference_CallInstruction_InstructionAtToAddress()throws Exception {@@ -422,6 +444,79 @@ public class OutgoingCallNodeTest extends AbstractGenericTest {assertTrue(children.get(0) instanceof DeadEndNode);}+ @Test+ public void testGenerateChildren_MultipleReferences_SameSource_SameRemoteFunction()+ throws Exception {++ //+ // This is testing when more than 1 reference exists at an address to the same function.+ // We have code that will ensure that call references are preferred over other reference+ // types, creating one node for the call reference.+ //++ String toAddress = "0x1000";+ builder.createEmptyFunction("Function_1000", toAddress, 1, new VoidDataType());+ builder.addBytesFallthrough(firstCalledFunctionAddress);+ builder.disassemble(firstCalledFunctionAddress, 2);++ // create non-call read reference+ builder.createMemoryReference(firstCalledFunctionAddress, toAddress, RefType.READ,+ SourceType.USER_DEFINED);++ // create call reference at a different op index so both references can co-exist+ builder.tx(() -> {+ ReferenceManager refManager = program.getReferenceManager();+ Reference ref =+ refManager.addMemoryReference(addr(firstCalledFunctionAddress), addr(toAddress),+ RefType.UNCONDITIONAL_CALL, SourceType.USER_DEFINED, 1);+ return ref;+ });++ List<GTreeNode> children = node1.generateChildren(TaskMonitor.DUMMY);+ assertEquals(1, children.size());+ OutgoingCallNode outgoingNode = (OutgoingCallNode) children.get(0);+ assertTrue(outgoingNode.isCallReference());+ }++ @Test+ public void testGenerateChildren_MultipleReferences_SameSource_DifferentRemoteFunction()+ throws Exception {++ //+ // This is testing when more than 1 reference exists at an address to different functions.+ // We have code that will ensure that call references are preferred over other reference+ // types. In this scenario, since the remote functions are different, there should be 2+ // nodes created in the tree, 1 for each reference.+ //++ String toAddress = "0x1000";+ builder.createEmptyFunction("Function_1000", toAddress, 1, new VoidDataType());+ builder.addBytesFallthrough(firstCalledFunctionAddress);+ builder.disassemble(firstCalledFunctionAddress, 2);++ String secondToAddress = "0x2000";++ // create non-call read reference+ builder.createMemoryReference(firstCalledFunctionAddress, toAddress, RefType.READ,+ SourceType.USER_DEFINED);++ // create call reference at a different op index so both references can co-exist+ builder.tx(() -> {+ ReferenceManager refManager = program.getReferenceManager();+ Reference ref =+ refManager.addMemoryReference(addr(firstCalledFunctionAddress),+ addr(secondToAddress), RefType.UNCONDITIONAL_CALL, SourceType.USER_DEFINED, 1);+ return ref;+ });++ List<GTreeNode> children = node1.generateChildren(TaskMonitor.DUMMY);+ assertEquals(2, children.size());+ }++//=================================================================================================+// Private Methods+//=================================================================================================+private Address addr(String addrString) {return builder.addr(addrString);}