Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-3252 - Function Call Trees - Added actions to: hide thunks, and show namespaces

dragonmacher8b5c7bb54422
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 c9eaf5fdd2..35f180791b 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
@@ -184,6 +184,8 @@
address order. This setting is more useful to see the overall flow of the main
function.</P>
+ <!-- Recurse Depth -->
+
<P align="left"><A name="Call_Tree_Action_Recurse_Depth">
</A>The <IMG src="images/depth-input.png" border="1">
depth setting action allows you to see and change the depth of recursive operations.
@@ -195,7 +197,7 @@
number of parents of a given node.
</P>
- <!-- Navigate on Selection -->
+ <!-- Navigate Actions-->
<P align="left"><A name="Call_Tree_Action_Incoming_Navigation"></A>The <IMG src=
"images/locationIn.gif" border="1"> button, when toggled on,
@@ -209,6 +211,17 @@
function call, you can use the <A href="#Call_Tree_Context_Action_Goto_Destination">Go To
Call Destination action</A>. No navigation will happen when toggled off.</P>
+ <!-- Filter Thunks -->
+
+ <P align="left"><A name="Call_Tree_Action_Filter_Thunks"></A>The action, when toggled on,
+ will filter thunk functions out of the tree.
+
+ <!-- Show Namespace -->
+
+ <P align="left"><A name="Call_Tree_Action_Show_Namespaces"></A>The action, when toggled on,
+ will show the function namespace in the each node.
+
+
</BLOCKQUOTE>
</BLOCKQUOTE>
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/label/SetLabelNamespaceCmd.java b/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/label/SetLabelNamespaceCmd.java
deleted file mode 100644
index 714c6230fb..0000000000
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/cmd/label/SetLabelNamespaceCmd.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/* ###
- * IP: GHIDRA
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package ghidra.app.cmd.label;
-
-import ghidra.framework.cmd.Command;
-import ghidra.program.model.address.Address;
-import ghidra.program.model.listing.CircularDependencyException;
-import ghidra.program.model.listing.Program;
-import ghidra.program.model.symbol.*;
-import ghidra.util.exception.DuplicateNameException;
-import ghidra.util.exception.InvalidInputException;
-
-/**
- * Command for changing the scope of a label.
- * The scope is the namespace that the label is associated with.
- */
-public class SetLabelNamespaceCmd implements Command<Program> {
-
- private Address addr;
- private String name;
- private Namespace oldNamespace;
- private Namespace newNamespace;
- private String errorMsg = "";
-
- /**
- * Constructs a new command for changing the scope of a label.
- * @param addr the address of the label to be changed.
- * @param name the name of the label to be changed.
- * @param oldNamespace the current scope of the label that will be changed.
- * @param newNamespace the new scope of the label.
- */
- public SetLabelNamespaceCmd(Address addr, String name, Namespace oldNamespace,
- Namespace newNamespace) {
- this.addr = addr;
- this.name = name;
- this.oldNamespace = oldNamespace;
- this.newNamespace = newNamespace;
- }
-
- @Override
- public boolean applyTo(Program program) {
- SymbolTable st = program.getSymbolTable();
-
- Symbol s = st.getSymbol(name, addr, oldNamespace);
- if (s == null) {
- errorMsg = "No symbol named " + name + " found at address " + addr + " in namespace " +
- oldNamespace;
- return false;
- }
- try {
- s.setNamespace(newNamespace);
- return true;
- }
- catch (DuplicateNameException e) {
- errorMsg = "Symbol named " + name + " already exists in namespace " + newNamespace;
- }
- catch (InvalidInputException e) {
- errorMsg = e.getMessage();
- }
- catch (CircularDependencyException e) {
- errorMsg = e.getMessage();
- }
- return false;
- }
-
- @Override
- public String getName() {
- return "Set Namespace";
- }
-
- @Override
- public String getStatusMsg() {
- return errorMsg;
- }
-
-}
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.java
index 1574a7bf26..60e39ed27e 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
@@ -16,7 +16,6 @@
package ghidra.app.plugin.core.calltree;
import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.tree.TreePath;
@@ -35,15 +34,14 @@ import ghidra.util.task.TaskMonitor;
public abstract class CallNode extends GTreeSlowLoadingNode {
- private boolean allowDuplicates;
- protected AtomicInteger filterDepth;
+ protected CallTreeOptions callTreeOptions;
private int depth = -1;
/** Used to signal that this node has been marked for replacement */
protected boolean invalid = false;
- public CallNode(AtomicInteger filterDepth) {
- this.filterDepth = filterDepth;
+ public CallNode(CallTreeOptions callTreeOptions) {
+ this.callTreeOptions = Objects.requireNonNull(callTreeOptions);
}
/**
@@ -92,30 +90,26 @@ public abstract class CallNode extends GTreeSlowLoadingNode {
return set;
}
- /**
- * True allows this node to contains children with the same name
- *
- * @param allowDuplicates true to allow duplicate nodes
- */
- protected void setAllowsDuplicates(boolean allowDuplicates) {
- this.allowDuplicates = allowDuplicates;
- }
-
- protected void addNode(LazyMap<Function, List<GTreeNode>> nodesByFunction,
- CallNode node) {
+ protected void addNode(LazyMap<Function, List<GTreeNode>> nodesByFunction, CallNode node) {
Function function = node.getRemoteFunction();
+ if (function != null && function.isThunk()) {
+ if (!callTreeOptions.allowsThunks()) {
+ return;
+ }
+ }
+
List<GTreeNode> nodes = nodesByFunction.get(function);
if (nodes.contains(node)) {
return; // never add equal() nodes
}
- if (allowDuplicates) {
+ if (callTreeOptions.allowsDuplicates()) {
nodes.add(node); // ok to add multiple nodes for this function with different addresses
}
if (nodes.isEmpty()) {
- nodes.add(node); // no duplicates allow; only add if this is the only node
+ nodes.add(node); // no duplicates allowed; only add if this is the only node
return;
}
@@ -130,7 +124,7 @@ public abstract class CallNode extends GTreeSlowLoadingNode {
@Override
public int loadAll(TaskMonitor monitor) throws CancelledException {
- if (depth() > filterDepth.get()) {
+ if (depth() > callTreeOptions.getRecurseDepth()) {
return 1;
}
return super.loadAll(monitor);
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.java
new file mode 100644
index 0000000000..21ae4fe44b
--- /dev/null
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/CallTreeOptions.java
@@ -0,0 +1,103 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.plugin.core.calltree;
+
+import ghidra.framework.options.SaveState;
+
+/**
+ * Settings for the {@link CallTreePlugin}. This class is immutable.
+ */
+public class CallTreeOptions {
+
+ private static final String DEFAULT_RECURSE_DEPTH = "5";
+
+ private static final String RECURSE_DEPTH_KEY = "RECURSE_DEPTH";
+ private static final String FILTER_DUPLICATES_KEY = "FILTER_DUPLICATES";
+ private static final String FILTER_THUNKS_KEY = "FILTER_THUNKS";
+ private static final String SHOW_NAMESPACE_KEY = "SHOW_NAMESPACE";
+
+ private boolean filterDuplicates = true;
+ private boolean filterThunks = false;
+ private boolean showNamespace = false;
+ private int recurseDepth = Integer.parseInt(DEFAULT_RECURSE_DEPTH);
+
+ CallTreeOptions() {
+ // default constructor
+ }
+
+ CallTreeOptions(SaveState saveState) {
+ filterDuplicates = saveState.getBoolean(FILTER_DUPLICATES_KEY, true);
+ filterThunks = saveState.getBoolean(FILTER_THUNKS_KEY, false);
+ showNamespace = saveState.getBoolean(SHOW_NAMESPACE_KEY, false);
+ recurseDepth = saveState.getInt(RECURSE_DEPTH_KEY, recurseDepth);
+ }
+
+ void save(SaveState saveState) {
+ saveState.putBoolean(FILTER_DUPLICATES_KEY, filterDuplicates);
+ saveState.putBoolean(FILTER_THUNKS_KEY, filterThunks);
+ saveState.putBoolean(SHOW_NAMESPACE_KEY, showNamespace);
+ saveState.putInt(RECURSE_DEPTH_KEY, recurseDepth);
+ }
+
+ private CallTreeOptions copy() {
+ CallTreeOptions newOptions = new CallTreeOptions();
+ newOptions.filterDuplicates = filterDuplicates;
+ newOptions.filterThunks = filterThunks;
+ newOptions.showNamespace = showNamespace;
+ newOptions.recurseDepth = recurseDepth;
+ return newOptions;
+ }
+
+ public int getRecurseDepth() {
+ return recurseDepth;
+ }
+
+ public boolean allowsDuplicates() {
+ return !filterDuplicates;
+ }
+
+ public boolean allowsThunks() {
+ return !filterThunks;
+ }
+
+ public boolean showNamespace() {
+ return showNamespace;
+ }
+
+ public CallTreeOptions withRecurseDepth(int depth) {
+ CallTreeOptions copy = copy();
+ copy.recurseDepth = depth;
+ return copy;
+ }
+
+ public CallTreeOptions withFilterDuplicates(boolean filter) {
+ CallTreeOptions copy = copy();
+ copy.filterDuplicates = filter;
+ return copy;
+ }
+
+ public CallTreeOptions withFilterThunks(boolean filter) {
+ CallTreeOptions copy = copy();
+ copy.filterThunks = filter;
+ return copy;
+ }
+
+ public CallTreeOptions withShowNamespace(boolean show) {
+ CallTreeOptions copy = copy();
+ copy.showNamespace = show;
+ return copy;
+ }
+}
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 797ffd5954..381a9a64ad 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
@@ -28,6 +28,7 @@ import ghidra.app.CorePluginPackage;
import ghidra.app.context.ListingActionContext;
import ghidra.app.plugin.PluginCategoryNames;
import ghidra.app.plugin.ProgramPlugin;
+import ghidra.framework.options.SaveState;
import ghidra.framework.plugintool.PluginInfo;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.PluginStatus;
@@ -101,6 +102,16 @@ public class CallTreePlugin extends ProgramPlugin {
}
}
+ @Override
+ public void readConfigState(SaveState saveState) {
+ primaryProvider.readConfigState(saveState);
+ }
+
+ @Override
+ public void writeConfigState(SaveState saveState) {
+ primaryProvider.writeConfigState(saveState);
+ }
+
@Override
protected void dispose() {
List<CallTreeProvider> copy = new ArrayList<>(providers);
@@ -126,23 +137,22 @@ public class CallTreePlugin extends ProgramPlugin {
// use the name of the provider so that the shared key binding data will get used
String actionName = "Static Function Call Trees";
- showCallTreeFromMenuAction =
- new DockingAction(actionName, getName()) {
- @Override
- public void actionPerformed(ActionContext context) {
- showOrCreateNewCallTree(currentLocation);
- }
-
- @Override
- public boolean isAddToPopup(ActionContext context) {
- return (context instanceof ListingActionContext);
- }
- };
+ showCallTreeFromMenuAction = new DockingAction(actionName, getName()) {
+ @Override
+ public void actionPerformed(ActionContext context) {
+ showOrCreateNewCallTree(currentLocation);
+ }
+
+ @Override
+ public boolean isAddToPopup(ActionContext context) {
+ return (context instanceof ListingActionContext);
+ }
+ };
showCallTreeFromMenuAction.setPopupMenuData(new MenuData(
new String[] { "References", "Show Call Trees" }, PROVIDER_ICON, "ShowReferencesTo"));
- showCallTreeFromMenuAction.setHelpLocation(
- new HelpLocation("CallTreePlugin", "Call_Tree_Plugin"));
+ showCallTreeFromMenuAction
+ .setHelpLocation(new HelpLocation("CallTreePlugin", "Call_Tree_Plugin"));
showCallTreeFromMenuAction.setDescription("Shows the Function Call Trees window for the " +
"item under the cursor. The new window will not change along with the Listing cursor.");
tool.addAction(showCallTreeFromMenuAction);
@@ -150,6 +160,10 @@ public class CallTreePlugin extends ProgramPlugin {
private void creatAndShowProvider() {
CallTreeProvider provider = new CallTreeProvider(this, false);
+
+ CallTreeOptions callTreeOptions = primaryProvider.getCallTreeOptions();
+ provider.setCallTreeOptions(callTreeOptions);
+
providers.add(provider);
provider.initialize(currentProgram, currentLocation);
tool.showComponentProvider(provider, true);
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 d9d4345089..98affa9c8c 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
@@ -21,13 +21,13 @@ import static ghidra.program.util.ProgramEvent.*;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.*;
import javax.swing.tree.TreePath;
import docking.*;
import docking.action.*;
+import docking.action.builder.ToggleActionBuilder;
import docking.resources.icons.NumberIcon;
import docking.widgets.dialogs.NumberInputDialog;
import docking.widgets.label.GLabel;
@@ -41,8 +41,8 @@ import ghidra.app.events.ProgramSelectionPluginEvent;
import ghidra.app.services.GoToService;
import ghidra.framework.model.DomainObjectListener;
import ghidra.framework.model.DomainObjectListenerBuilder;
+import ghidra.framework.options.SaveState;
import ghidra.framework.plugintool.ComponentProviderAdapter;
-import ghidra.framework.preferences.Preferences;
import ghidra.program.database.symbol.FunctionSymbol;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.Function;
@@ -67,9 +67,6 @@ public class CallTreeProvider extends ComponentProviderAdapter {
private static Icon REFRESH_NOT_NEEDED_ICON =
new GIcon("icon.plugin.calltree.refresh.not.needed");
- private static final String RECURSE_DEPTH_PROPERTY_NAME = "call.tree.recurse.depth";
- private static final String DEFAULT_RECURSE_DEPTH = "5";
-
private final CallTreePlugin plugin;
private JComponent component;
@@ -84,16 +81,19 @@ public class CallTreeProvider extends ComponentProviderAdapter {
private Function currentFunction;
private DockingAction recurseDepthAction;
private ToggleDockingAction filterDuplicates;
+ private ToggleDockingAction filterThunksAction;
+ private ToggleDockingAction showNamespaceAction;
private ToggleDockingAction navigationOutgoingAction;
private ToggleDockingAction navigateIncomingToggleAction;
private DockingAction refreshAction;
+ private CallTreeOptions callTreeOptions = new CallTreeOptions();
+
private boolean isFiringNavigationEvent;
/**
* A variable used to restrict open-ended operations, like expanding all nodes or filtering.
*/
- private AtomicInteger recurseDepth = new AtomicInteger();
private NumberIcon recurseIcon;
private DomainObjectListener domainObjectListener = createDomainObjectListener();
@@ -120,7 +120,6 @@ public class CallTreeProvider extends ComponentProviderAdapter {
setHelpLocation(new HelpLocation(plugin.getName(), "Call_Tree_Plugin"));
addToTool();
- loadRecurseDepthPreference();
createActions();
}
@@ -148,7 +147,8 @@ public class CallTreeProvider extends ComponentProviderAdapter {
TreePath[] paths = gTree.getSelectionPaths();
for (TreePath treePath : paths) {
GTreeNode node = (GTreeNode) treePath.getLastPathComponent();
- gTree.runTask(new ExpandToDepthTask(gTree, node, recurseDepth.get()));
+ int recurseDepth = callTreeOptions.getRecurseDepth();
+ gTree.runTask(new ExpandToDepthTask(gTree, node, recurseDepth));
}
}
@@ -366,6 +366,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {
filterDuplicates = new ToggleDockingAction("Filter Duplicates", plugin.getName()) {
@Override
public void actionPerformed(ActionContext context) {
+ callTreeOptions = callTreeOptions.withFilterDuplicates(isSelected());
doUpdate();
}
};
@@ -382,8 +383,9 @@ public class CallTreeProvider extends ComponentProviderAdapter {
recurseDepthAction = new DockingAction("Recurse Depth", plugin.getName()) {
@Override
public void actionPerformed(ActionContext context) {
+ int recurseDepth = callTreeOptions.getRecurseDepth();
NumberInputDialog dialog =
- new NumberInputDialog("", "", recurseDepth.get(), 0, Integer.MAX_VALUE, false);
+ new NumberInputDialog("", "", recurseDepth, 0, Integer.MAX_VALUE, false);
if (!dialog.show()) {
return;
}
@@ -395,7 +397,9 @@ public class CallTreeProvider extends ComponentProviderAdapter {
recurseDepthAction.setDescription(
"<html>Recurse Depth<br><br>Limits the depth to " + "which recursing tree operations" +
"<br> will go. Example operations include <b>Expand All</b> and filtering");
- recurseIcon = new NumberIcon(recurseDepth.get());
+
+ int recurseDepth = callTreeOptions.getRecurseDepth();
+ recurseIcon = new NumberIcon(recurseDepth);
recurseDepthAction
.setToolBarData(new ToolBarData(recurseIcon, filterOptionsToolbarGroup, "2"));
recurseDepthAction.setHelpLocation(
@@ -676,6 +680,35 @@ public class CallTreeProvider extends ComponentProviderAdapter {
newCallTree.setDescription(
"Show the Function Call Tree window for the function " + "selected in the call tree");
tool.addLocalAction(this, newCallTree);
+
+ //
+ // Provider menu actions
+ //
+ //@formatter:off
+ filterThunksAction = new ToggleActionBuilder("Filter Thunks", plugin.getName())
+ .selected(false)
+ .description("Thunk functions will not be shown in the tree when selected")
+ .helpLocation(new HelpLocation(plugin.getName(), "Call_Tree_Action_Filter_Thunks"))
+ .menuPath("Filter Thunks")
+ .onAction(c -> {
+ callTreeOptions = callTreeOptions.withFilterThunks(filterThunksAction.isSelected());
+ doUpdate();
+ })
+ .buildAndInstallLocal(this);
+ //@formatter:on
+
+ //@formatter:off
+ showNamespaceAction = new ToggleActionBuilder("Show Namespace", plugin.getName())
+ .selected(false)
+ .description("Function nodes will include the funtion namespace when selected")
+ .helpLocation(new HelpLocation(plugin.getName(), "Call_Tree_Action_Show_Namespaces"))
+ .menuPath("Show Namespace")
+ .onAction(c -> {
+ callTreeOptions = callTreeOptions.withShowNamespace(showNamespaceAction.isSelected());
+ doUpdate();
+ })
+ .buildAndInstallLocal(this);
+ //@formatter:on
}
private void makeSelectionFromPaths(TreePath[] paths, boolean selectSource) {
@@ -919,7 +952,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {
return;
}
- resetTrees();
+ setTreesPending();
updateTitle();
reloadUpdateManager.update();
}
@@ -939,7 +972,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {
outgoingTree.setRootNode(new EmptyRootNode());
}
- private void resetTrees() {
+ private void setTreesPending() {
incomingTree.setRootNode(new PendingRootNode());
outgoingTree.setRootNode(new PendingRootNode());
}
@@ -957,7 +990,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {
}
else {
rootNode = new IncomingCallsRootNode(currentProgram, function, function.getEntryPoint(),
- filterDuplicates.isSelected(), recurseDepth);
+ callTreeOptions);
}
incomingTree.setRootNode(rootNode);
}
@@ -969,7 +1002,7 @@ public class CallTreeProvider extends ComponentProviderAdapter {
}
else {
rootNode = new OutgoingCallsRootNode(currentProgram, function, function.getEntryPoint(),
- filterDuplicates.isSelected(), recurseDepth);
+ callTreeOptions);
}
outgoingTree.setRootNode(rootNode);
@@ -1029,6 +1062,23 @@ public class CallTreeProvider extends ComponentProviderAdapter {
currentProgram = null;
}
+ CallTreeOptions getCallTreeOptions() {
+ return callTreeOptions;
+ }
+
+ void setCallTreeOptions(CallTreeOptions callTreeOptions) {
+ this.callTreeOptions = callTreeOptions;
+ recurseIcon.setNumber(callTreeOptions.getRecurseDepth());
+ }
+
+ void readConfigState(SaveState saveState) {
+ setCallTreeOptions(new CallTreeOptions(saveState));
+ }
+
+ void writeConfigState(SaveState saveState) {
+ callTreeOptions.save(saveState);
+ }
+
private void clearState() {
incomingTree.cancelWork();
outgoingTree.cancelWork();
@@ -1087,7 +1137,6 @@ public class CallTreeProvider extends ComponentProviderAdapter {
private boolean updateRootNodes(Function function) {
GTreeNode root = incomingTree.getModelRoot();
// root might be a "PendingRootNode"
- //TODO do we need to use a PendingRootNode?
if (root instanceof CallNode) {
CallNode callNode = (CallNode) root;
Function nodeFunction = callNode.getRemoteFunction();
@@ -1100,46 +1149,6 @@ public class CallTreeProvider extends ComponentProviderAdapter {
return false;
}
- private class UpdateFunctionNodeTask extends GTreeTask {
-
- private Function function;
-
- protected UpdateFunctionNodeTask(GTree tree, Function function) {
- super(tree);
- this.function = function;
- }
-
- @Override
- public void run(TaskMonitor monitor) throws CancelledException {
- CallNode rootNode = (CallNode) tree.getModelRoot();
- List<GTreeNode> children = rootNode.getChildren();
- for (GTreeNode node : children) {
- updateFunction((CallNode) node);
- }
- }
-
- private void updateFunction(CallNode node) {
- if (!node.isLoaded()) {
- // children not loaded, don't force a load by asking for them
- return;
- }
-
- // first, if the given node represents the function we have, then we don't need to
- // go any further
- if (function.equals(node.getRemoteFunction())) {
- GTreeNode parent = node.getParent();
- parent.removeNode(node);
- parent.addNode(node.recreate());
- return;
- }
-
- List<GTreeNode> children = node.getChildren();
- for (GTreeNode child : children) {
- updateFunction((CallNode) child);
- }
- }
- }
-
private void setStale(boolean stale) {
if (stale) {
refreshAction.getToolBarData().setIcon(REFRESH_ICON);
@@ -1183,56 +1192,19 @@ public class CallTreeProvider extends ComponentProviderAdapter {
return; // always have at least one level showing
}
- if (recurseDepth.get() == depth) {
+ int recurseDepth = callTreeOptions.getRecurseDepth();
+ if (recurseDepth == depth) {
return;
}
- this.recurseDepth.set(depth);
- this.recurseIcon.setNumber(depth);
-
- removeFilterCache();
- incomingTree.refilterLater();
- outgoingTree.refilterLater();
+ callTreeOptions = callTreeOptions.withRecurseDepth(depth);
+ recurseIcon.setNumber(depth);
- saveRecurseDepth();
- }
-
- /**
- * The nodes will cache filtered values, which are restricted by the recurse depth. We
- * have to remove this cache to get the nodes to reload children to the new depth.
- */
- private void removeFilterCache() {
- //
- // I don't like this, BTW. The problem with this approach is that you lose any loading
- // you have done. Normally this is not that big of a problem. However, if the loading
- // takes a long time, then you lose some work.
- //
- GTreeNode rootNode = incomingTree.getModelRoot();
- rootNode.removeAll();
- rootNode = outgoingTree.getModelRoot();
- rootNode.removeAll();
- }
-
- private void saveRecurseDepth() {
- Preferences.setProperty(RECURSE_DEPTH_PROPERTY_NAME, Integer.toString(recurseDepth.get()));
- Preferences.store();
- }
-
- private void loadRecurseDepthPreference() {
- String value = Preferences.getProperty(RECURSE_DEPTH_PROPERTY_NAME, DEFAULT_RECURSE_DEPTH);
- int intValue;
- try {
- intValue = Integer.parseInt(value);
- }
- catch (NumberFormatException nfe) {
- intValue = Integer.parseInt(DEFAULT_RECURSE_DEPTH);
- }
-
- recurseDepth.set(intValue);
+ doUpdate();
}
public int getRecurseDepth() {
- return recurseDepth.get();
+ return callTreeOptions.getRecurseDepth();
}
public void setIncomingFilter(String text) {
@@ -1327,4 +1299,47 @@ public class CallTreeProvider extends ComponentProviderAdapter {
return true;
}
}
+
+ /*
+ * Finds the node in the tree for the given function and replaces that node with a new version.
+ */
+ private class UpdateFunctionNodeTask extends GTreeTask {
+
+ private Function function;
+
+ protected UpdateFunctionNodeTask(GTree tree, Function function) {
+ super(tree);
+ this.function = function;
+ }
+
+ @Override
+ public void run(TaskMonitor monitor) throws CancelledException {
+ CallNode rootNode = (CallNode) tree.getModelRoot();
+ List<GTreeNode> children = rootNode.getChildren();
+ for (GTreeNode node : children) {
+ updateFunction((CallNode) node);
+ }
+ }
+
+ private void updateFunction(CallNode node) {
+ if (!node.isLoaded()) {
+ // children not loaded, don't force a load by asking for them
+ return;
+ }
+
+ // first, if the given node represents the function we have, then we don't need to
+ // go any further
+ if (function.equals(node.getRemoteFunction())) {
+ GTreeNode parent = node.getParent();
+ parent.removeNode(node);
+ parent.addNode(node.recreate());
+ return;
+ }
+
+ List<GTreeNode> children = node.getChildren();
+ for (GTreeNode child : children) {
+ updateFunction((CallNode) child);
+ }
+ }
+ }
}
diff --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.java
index bce14bc4f6..4a23e4b8dd 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
@@ -17,7 +17,6 @@ package ghidra.app.plugin.core.calltree;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.Icon;
@@ -40,15 +39,20 @@ public class DeadEndNode extends CallNode {
private final Program program;
- DeadEndNode(Program program, Reference reference) {
- super(new AtomicInteger(0)); // can't recurse
+ DeadEndNode(Program program, Reference reference, CallTreeOptions callTreeOptions) {
+ super(callTreeOptions);
this.program = program;
this.reference = reference;
}
+ @Override
+ public int loadAll(TaskMonitor monitor) throws CancelledException {
+ return 1; // this node cannot be opened
+ }
+
@Override
CallNode recreate() {
- return new DeadEndNode(program, reference);
+ return new DeadEndNode(program, reference, callTreeOptions);
}
@Override
diff --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.java
index d4269e8791..bf38ab826d 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
@@ -17,7 +17,6 @@ package ghidra.app.plugin.core.calltree;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.Icon;
@@ -42,8 +41,9 @@ public class ExternalCallNode extends CallNode {
private final Address sourceAddress;
private final String name;
- ExternalCallNode(Function function, Address sourceAddress, Icon baseIcon) {
- super(new AtomicInteger(0)); // can't recurse
+ ExternalCallNode(Function function, Address sourceAddress, Icon baseIcon,
+ CallTreeOptions callTreeOptions) {
+ super(callTreeOptions);
this.function = function;
this.sourceAddress = sourceAddress;
this.name = function.getName();
@@ -55,9 +55,14 @@ public class ExternalCallNode extends CallNode {
EXTERNAL_FUNCTION_ICON = outgoingFunctionIcon;
}
+ @Override
+ public int loadAll(TaskMonitor monitor) throws CancelledException {
+ return 1; // this node cannot be opened
+ }
+
@Override
CallNode recreate() {
- return new ExternalCallNode(function, sourceAddress, baseIcon);
+ return new ExternalCallNode(function, sourceAddress, baseIcon, callTreeOptions);
}
@Override
diff --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.java
index 7dafe5b8aa..c5634ab572 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
@@ -16,7 +16,6 @@
package ghidra.app.plugin.core.calltree;
import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import javax.swing.Icon;
@@ -45,31 +44,26 @@ public class IncomingCallNode extends CallNode {
protected final Program program;
protected final Function function;
protected String name;
- protected final boolean filterDuplicates;
private final Address sourceAddress;
IncomingCallNode(Program program, Function function, Address sourceAddress,
- boolean filterDuplicates, AtomicInteger filterDepth) {
- super(filterDepth);
+ CallTreeOptions callTreeOptions) {
+ super(callTreeOptions);
this.program = program;
this.function = function;
- this.name = function.getName();
+ this.name = function.getName(callTreeOptions.showNamespace());
this.sourceAddress = sourceAddress;
- this.filterDuplicates = filterDuplicates;
this.functionAddress = function.getEntryPoint();
MultiIcon incomingFunctionIcon = new MultiIcon(INCOMING_ICON, false, 32, 16);
TranslateIcon translateIcon = new TranslateIcon(CallTreePlugin.FUNCTION_ICON, 16, 0);
incomingFunctionIcon.addIcon(translateIcon);
INCOMING_FUNCTION_ICON = incomingFunctionIcon;
-
- setAllowsDuplicates(!filterDuplicates);
}
@Override
CallNode recreate() {
- return new IncomingCallNode(program, function, sourceAddress, filterDuplicates,
- filterDepth);
+ return new IncomingCallNode(program, function, sourceAddress, callTreeOptions);
}
@Override
@@ -99,16 +93,15 @@ public class IncomingCallNode extends CallNode {
continue;
}
- IncomingCallNode node = new IncomingCallNode(program, callerFunction, fromAddress,
- filterDuplicates, filterDepth);
+ IncomingCallNode node =
+ new IncomingCallNode(program, callerFunction, fromAddress, callTreeOptions);
addNode(nodesByFunction, node);
}
- List<GTreeNode> children =
- nodesByFunction.values()
- .stream()
- .flatMap(list -> list.stream())
- .collect(Collectors.toList());
+ List<GTreeNode> children = nodesByFunction.values()
+ .stream()
+ .flatMap(list -> list.stream())
+ .collect(Collectors.toList());
Collections.sort(children, new CallNodeComparator());
return children;
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.java
index 3a07ff0b2d..ca3c36da66 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
@@ -15,8 +15,6 @@
*/
package ghidra.app.plugin.core.calltree;
-import java.util.concurrent.atomic.AtomicInteger;
-
import javax.swing.Icon;
import ghidra.program.model.address.Address;
@@ -26,15 +24,14 @@ import ghidra.program.model.listing.Program;
public class IncomingCallsRootNode extends IncomingCallNode {
IncomingCallsRootNode(Program program, Function function, Address sourceAddress,
- boolean filterDuplicates, AtomicInteger filterDepth) {
- super(program, function, sourceAddress, filterDuplicates, filterDepth);
+ CallTreeOptions callTreeOptions) {
+ super(program, function, sourceAddress, callTreeOptions);
name = function.getName();
}
@Override
CallNode recreate() {
- return new IncomingCallsRootNode(program, function, getSourceAddress(), filterDuplicates,
- filterDepth);
+ return new IncomingCallsRootNode(program, function, getSourceAddress(), callTreeOptions);
}
@Override
diff --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.java
index 885fc0e1d9..b3c13e9732 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
@@ -16,7 +16,6 @@
package ghidra.app.plugin.core.calltree;
import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import javax.swing.Icon;
@@ -47,25 +46,21 @@ public abstract class OutgoingCallNode extends CallNode {
protected final Function function;
protected String name;
private final Address sourceAddress;
- protected final boolean filterDuplicates;
private final Icon baseIcon;
OutgoingCallNode(Program program, Function function, Address sourceAddress, Icon baseIcon,
- boolean filterDuplicates, AtomicInteger filterDepth) {
- super(filterDepth);
+ CallTreeOptions callTreeOptions) {
+ super(callTreeOptions);
this.program = program;
this.function = function;
- this.name = function.getName();
+ this.name = function.getName(callTreeOptions.showNamespace());
this.sourceAddress = sourceAddress;
this.baseIcon = baseIcon;
- this.filterDuplicates = filterDuplicates;
MultiIcon outgoingFunctionIcon = new MultiIcon(OUTGOING_ICON, false, 32, 16);
TranslateIcon translateIcon = new TranslateIcon(baseIcon, 16, 0);
outgoingFunctionIcon.addIcon(translateIcon);
OUTGOING_FUNCTION_ICON = outgoingFunctionIcon;
-
- setAllowsDuplicates(!filterDuplicates);
}
@Override
@@ -92,11 +87,10 @@ public abstract class OutgoingCallNode extends CallNode {
createNode(nodesByFunction, reference, calledFunction);
}
- List<GTreeNode> children =
- nodesByFunction.values()
- .stream()
- .flatMap(list -> list.stream())
- .collect(Collectors.toList());
+ List<GTreeNode> children = nodesByFunction.values()
+ .stream()
+ .flatMap(list -> list.stream())
+ .collect(Collectors.toList());
Collections.sort(children, new CallNodeComparator());
return children;
@@ -104,16 +98,16 @@ public abstract class OutgoingCallNode extends CallNode {
private void createNode(LazyMap<Function, List<GTreeNode>> nodes, Reference reference,
Function calledFunction) {
+ Address fromAddress = reference.getFromAddress();
if (calledFunction != null) {
if (isExternalCall(calledFunction)) {
CallNode node =
- new ExternalCallNode(calledFunction, reference.getFromAddress(), baseIcon);
- node.setAllowsDuplicates(!filterDuplicates);
+ new ExternalCallNode(calledFunction, fromAddress, baseIcon, callTreeOptions);
addNode(nodes, node);
}
else {
- addNode(nodes, new OutgoingFunctionCallNode(program, calledFunction,
- reference.getFromAddress(), filterDuplicates, filterDepth));
+ addNode(nodes,
+ new OutgoingFunctionCallNode(program, calledFunction, fromAddress, callTreeOptions));
}
}
else if (isCallReference(reference)) {
@@ -121,14 +115,12 @@ public abstract class OutgoingCallNode extends CallNode {
Function externalFunction = getExternalFunctionTempHackWorkaround(reference);
if (externalFunction != null) {
CallNode node =
- new ExternalCallNode(externalFunction, reference.getFromAddress(), baseIcon);
- node.setAllowsDuplicates(!filterDuplicates);
+ new ExternalCallNode(externalFunction, fromAddress, baseIcon, callTreeOptions);
addNode(nodes, node);
}
else {
// we have a call reference, but no function
- CallNode node = new DeadEndNode(program, reference);
- node.setAllowsDuplicates(!filterDuplicates);
+ CallNode node = new DeadEndNode(program, reference, callTreeOptions);
addNode(nodes, node);
}
}
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.java
index 21d2ac6068..471b035fdc 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
@@ -15,8 +15,6 @@
*/
package ghidra.app.plugin.core.calltree;
-import java.util.concurrent.atomic.AtomicInteger;
-
import javax.swing.Icon;
import ghidra.program.model.address.Address;
@@ -26,15 +24,13 @@ import ghidra.program.model.listing.Program;
public class OutgoingCallsRootNode extends OutgoingCallNode {
OutgoingCallsRootNode(Program program, Function function, Address sourceAddress,
- boolean filterDuplicates, AtomicInteger filterDepth) {
- super(program, function, sourceAddress, CallTreePlugin.FUNCTION_ICON, filterDuplicates,
- filterDepth);
+ CallTreeOptions callTreeOptions) {
+ super(program, function, sourceAddress, CallTreePlugin.FUNCTION_ICON, callTreeOptions);
}
@Override
CallNode recreate() {
- return new OutgoingCallsRootNode(program, function, getSourceAddress(), filterDuplicates,
- filterDepth);
+ return new OutgoingCallsRootNode(program, function, getSourceAddress(), callTreeOptions);
}
@Override
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingFunctionCallNode.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingFunctionCallNode.java
index 80f1b49547..d8a694bbd1 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingFunctionCallNode.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/calltree/OutgoingFunctionCallNode.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,19 +19,15 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Program;
-import java.util.concurrent.atomic.AtomicInteger;
-
public class OutgoingFunctionCallNode extends OutgoingCallNode {
OutgoingFunctionCallNode(Program program, Function function, Address sourceAddress,
- boolean filterDuplicates, AtomicInteger filterDepth) {
- super(program, function, sourceAddress, CallTreePlugin.FUNCTION_ICON, filterDuplicates,
- filterDepth);
+ CallTreeOptions callTreeOptions) {
+ super(program, function, sourceAddress, CallTreePlugin.FUNCTION_ICON, callTreeOptions);
}
@Override
CallNode recreate() {
- return new OutgoingFunctionCallNode(program, function, getSourceAddress(),
- filterDuplicates, filterDepth);
+ return new OutgoingFunctionCallNode(program, function, getSourceAddress(), callTreeOptions);
}
}
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 0b6d3645dc..a4a5c91be1 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
@@ -35,8 +35,8 @@ import docking.action.*;
import docking.widgets.tree.*;
import generic.test.AbstractGenericTest;
import ghidra.app.cmd.data.CreateDataCmd;
-import ghidra.app.cmd.function.CreateExternalFunctionCmd;
-import ghidra.app.cmd.function.SetFunctionNameCmd;
+import ghidra.app.cmd.function.*;
+import ghidra.app.cmd.label.RenameLabelCmd;
import ghidra.app.cmd.refs.AddMemRefCmd;
import ghidra.app.cmd.refs.SetExternalRefCmd;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
@@ -47,6 +47,7 @@ import ghidra.app.util.NamespaceUtils;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.database.ProgramDB;
+import ghidra.program.database.symbol.SymbolManager;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.DataType;
import ghidra.program.model.data.PointerDataType;
@@ -101,6 +102,9 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
tool.showComponentProvider(provider, true);
incomingTree = (GTree) getInstanceField("incomingTree", provider);
outgoingTree = (GTree) getInstanceField("outgoingTree", provider);
+
+ // this may have been changed by a previous test
+ setDepth(5);
}
private ProgramDB createProgram() throws Exception {
@@ -248,7 +252,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
setIncomingFilter(existingCaller);
assertIncomingMaxDepth(0, true);// filter no longer matches
- assertIncomingNoNode(existingCaller, depth, true);
+ assertNoIncomingNode(existingCaller, depth, true);
}
@Test
@@ -269,7 +273,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
setOutgoingFilter(existingCallee);
assertOutgoingMaxDepth(0, true);// filter no longer matches
- assertOutgoingNoNode(existingCallee, depth, true);
+ assertNoOutgoingNode(existingCallee, depth, true);
}
@Test
@@ -880,6 +884,144 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals("Incoming References - " + newName, rootNode.getName());
}
+ @Test
+ public void testFilterThunks_Outgoing() {
+
+ /*
+
+ Outgoing References - Function 5000
+
+ Function_6000 * make this a thunk for the test
+ Function_7000
+
+ Function_6100
+ Function_7100 * make this a thunk for the test
+
+ */
+
+ makeThunk("0x6000", "0x8000");
+ makeThunk("0x7100", "0x9000");
+
+ toggleFilterThunks(false);
+
+ // show a function that contains calls to thunks
+ setProviderFunction("0x5000");
+ fullyExpandOutgoingTree();
+
+ // verify the thunks are present
+ assertOutgoingNode("Function_6000", "Function_7000");
+ assertOutgoingNode("Function_6100", "Function_7100");
+
+ // toggle the action to filter thunks
+ toggleFilterThunks(true);
+ fullyExpandOutgoingTree();
+
+ // verify no thunks
+ assertOutgoingNode("Function_6100");
+ assertNoOutgoingNode("Function_6000");
+ assertNoOutgoingNode("Function_6100", "Function_7100");
+ }
+
+ @Test
+ public void testFilterThunks_Incoming() {
+
+ /*
+
+ Incoming References - Function 5000
+
+ Function_4000
+ Function_3000
+
+
+ */
+
+ makeThunk("0x3000", "0x9000");
+
+ toggleFilterThunks(false);
+
+ // show a function that contains calls to thunks
+ setProviderFunction("0x5000");
+ fullyExpandIncomingTree();
+
+ // verify the thunks are present
+ assertIncomingNode("Function_4000", "Function_3000");
+
+ // toggle the action to filter thunks
+ toggleFilterThunks(true);
+ fullyExpandIncomingTree();
+
+ // verify no thunks
+ assertIncomingNode("Function_4000");
+ assertNoIncomingNode("Function_3000");
+ }
+
+ @Test
+ public void testShowNamespace_Outgoing() {
+
+ /*
+
+ Outgoing References - Function 5000
+
+ Function_6000 * make this a thunk for the test
+ Function_7000
+
+ Function_6100
+ Function_7100 * make this a thunk for the test
+
+ */
+
+ makeNamespace("NS1::Function_6000", "0x6000");
+ makeNamespace("NS2::Function_7000", "0x7000");
+
+ toggleShowNamespace(false);
+
+ // show a function
+ setProviderFunction("0x5000");
+ fullyExpandOutgoingTree();
+
+ // verify no namespace in the name
+ assertOutgoingNode("Function_6000", "Function_7000");
+
+ // toggle the action
+ toggleShowNamespace(true);
+ fullyExpandOutgoingTree();
+
+ // verify namespace in the name
+ assertOutgoingNode("NS1::Function_6000", "NS2::Function_7000");
+ }
+
+ @Test
+ public void testShowNamespace_Incoming() {
+
+ /*
+
+ Incoming References - Function 5000
+
+ Function_4000
+ Function_3000
+
+
+ */
+ makeNamespace("NS1::Function_4000", "0x4000");
+ makeNamespace("NS2::Function_3000", "0x3000");
+
+ toggleShowNamespace(false);
+
+ // show a function
+ setProviderFunction("0x5000");
+ fullyExpandIncomingTree();
+
+ // verify no namespace in the name
+ assertIncomingNode("Function_4000", "Function_3000");
+
+ // toggle the action
+ toggleShowNamespace(true);
+ fullyExpandIncomingTree();
+
+ // verify namespace in the name
+ assertIncomingNode("NS1::Function_4000", "NS2::Function_3000");
+ }
+
//==================================================================================================
// Private Methods
//==================================================================================================
@@ -889,6 +1031,16 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
getListingFunction(), providerFunction());
}
+ private void toggleShowNamespace(boolean selected) {
+ ToggleDockingAction action = (ToggleDockingAction) getAction("Show Namespace");
+ setToggleActionSelected(action, provider.getActionContext(null), selected);
+ }
+
+ private void toggleFilterThunks(boolean selected) {
+ ToggleDockingAction action = (ToggleDockingAction) getAction("Filter Thunks");
+ setToggleActionSelected(action, provider.getActionContext(null), selected);
+ }
+
private void toggleFollowIncomingNavigation(boolean selected) {
ToggleDockingAction navigateIncomingLoctionsAction =
(ToggleDockingAction) getAction("Navigation Incoming Location Changes");
@@ -925,23 +1077,29 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
return ref.get();
}
+ private void makeNamespace(String newName, String entry) {
+ SymbolManager symbolTable = program.getSymbolTable();
+ Symbol[] symbols = symbolTable.getSymbols(addr(entry));
+ RenameLabelCmd cmd = new RenameLabelCmd(symbols[0], newName, SourceType.USER_DEFINED);
+ boolean result = applyCmd(program, cmd);
+ assertTrue("Failed to set namespace: " + cmd.getStatusMsg(), result);
+ }
+
+ private void makeThunk(String thunkAddress, String thunkedAddress) {
+
+ CreateThunkFunctionCmd cmd =
+ new CreateThunkFunctionCmd(addr(thunkAddress), null, addr(thunkedAddress));
+ boolean result = applyCmd(program, cmd);
+ assertTrue("Failed to turn function to thunk: " + cmd.getStatusMsg(), result);
+ }
+
private void renameFunction(Function function, String newName) {
SetFunctionNameCmd cmd =
new SetFunctionNameCmd(function.getEntryPoint(), newName, SourceType.USER_DEFINED);
- boolean result = false;
-
- int txID = program.startTransaction("Test - Create Function");
- try {
- result = cmd.applyTo(program);
- }
- finally {
- program.endTransaction(txID, true);
- }
+ boolean result = applyCmd(program, cmd);
assertTrue("Failed to rename function: " + cmd.getStatusMsg(), result);
- program.flushEvents();
- waitForSwing();
}
private Function getFunction(Address address) {
@@ -949,7 +1107,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
return functionManager.getFunctionAt(address);
}
- private void assertOutgoingNoNode(String name, int depth, boolean filtered) {
+ private void assertNoOutgoingNode(String name, int depth, boolean filtered) {
List<NodeDepthInfo> nodes = getNodesByDepth(false, filtered);
for (NodeDepthInfo info : nodes) {
String nodeName = info.node.getName();
@@ -960,6 +1118,70 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
}
}
+ private void assertNoIncomingNode(String... path) {
+ GTreeNode root = getRootNode(outgoingTree);
+ List<String> pathList = new ArrayList<>(List.of(path));
+ assertNoNodePath(root, pathList);
+ }
+
+ private void assertNoOutgoingNode(String... path) {
+ GTreeNode root = getRootNode(outgoingTree);
+ List<String> pathList = new ArrayList<>(List.of(path));
+ assertNoNodePath(root, pathList);
+ }
+
+ private void assertNoNodePath(GTreeNode root, List<String> pathList) {
+ List<String> originalPath = new ArrayList<>(pathList);
+ String lastName = pathList.remove(pathList.size() - 1);
+ GTreeNode node = root;
+ while (!pathList.isEmpty()) {
+ String expectedName = pathList.remove(0);
+ List<GTreeNode> children = node.getChildren();
+ node = getNode(expectedName, children);
+ assertNotNull(
+ "Did not find node '%s' in path '%s'".formatted(expectedName, originalPath), node);
+ }
+
+ GTreeNode lastParentNode = node;
+ GTreeNode child = lastParentNode.getChild(lastName);
+ assertNull("Node is not supposed to be in the outgoing tree '%s'".formatted(lastName),
+ child);
+ }
+
+ private void assertIncomingNode(String... path) {
+ GTreeNode root = getRootNode(incomingTree);
+ List<String> pathList = new ArrayList<>(List.of(path));
+ assertNodePath(root, pathList);
+ }
+
+ private void assertOutgoingNode(String... path) {
+ GTreeNode root = getRootNode(outgoingTree);
+ List<String> pathList = new ArrayList<>(List.of(path));
+ assertNodePath(root, pathList);
+ }
+
+ private void assertNodePath(GTreeNode root, List<String> pathList) {
+ List<String> originalPath = new ArrayList<>(pathList);
+ GTreeNode node = root;
+ while (!pathList.isEmpty()) {
+ String expectedName = pathList.remove(0);
+ List<GTreeNode> children = node.getChildren();
+ node = getNode(expectedName, children);
+ assertNotNull(
+ "Did not find node '%s' in path '%s'".formatted(expectedName, originalPath), node);
+ }
+ }
+
+ private GTreeNode getNode(String name, List<GTreeNode> nodes) {
+ for (GTreeNode node : nodes) {
+ String nodeName = node.getName();
+ if (nodeName.equals(name)) {
+ return node;
+ }
+ }
+ return null;
+ }
+
private void assertOutgoingNode(String name, int depth) {
List<NodeDepthInfo> nodes = getNodesByDepth(false);
List<NodeDepthInfo> matches = new ArrayList<>();
@@ -984,7 +1206,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
List<NodeDepthInfo> nodes = getNodesByDepth(false, filtered);
NodeDepthInfo maxDepthNode = nodes.get(nodes.size() - 1);
- assertEquals("Node max depth does not match: " + maxDepthNode, depth, maxDepthNode.depth);
+ assertEquals("Node max depth does not match: " + depth, depth, maxDepthNode.depth);
}
private void setOutgoingFilter(final String text) {
@@ -1009,6 +1231,10 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
private GTreeNode selectIncomingNode(String text) {
GTreeNode rootNode = getRootNode(incomingTree);
GTreeNode node = findNode(rootNode, text);
+ return selectIncomingNode(node);
+ }
+
+ private GTreeNode selectIncomingNode(GTreeNode node) {
assertNotNull(node);
incomingTree.setSelectedNode(node);
waitForTree(incomingTree);
@@ -1018,6 +1244,10 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
private GTreeNode selectOutgoingNode(String text) {
GTreeNode rootNode = getRootNode(outgoingTree);
GTreeNode node = findNode(rootNode, text);
+ return selectOutgoingNode(node);
+ }
+
+ private GTreeNode selectOutgoingNode(GTreeNode node) {
assertNotNull(node);
outgoingTree.setSelectedNode(node);
waitForTree(outgoingTree);
@@ -1082,6 +1312,18 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
waitForTree(node.getTree());
}
+ private void fullyExpandOutgoingTree() {
+ GTreeNode root = getRootNode(outgoingTree);
+ selectOutgoingNode(root);
+ fullyExpandOutgoingNode(root);
+ }
+
+ private void fullyExpandIncomingTree() {
+ GTreeNode root = getRootNode(incomingTree);
+ selectIncomingNode(root);
+ fullyExpandIncomingNode(root);
+ }
+
private void assertIncomingNode(String name, int depth) {
List<NodeDepthInfo> nodes = getNodesByDepth(true);
List<NodeDepthInfo> matches = new ArrayList<>();
@@ -1102,7 +1344,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
Assert.fail("Unable to find a node by name: " + name + " at depth: " + depth);
}
- private void assertIncomingNoNode(String name, int depth, boolean filtered) {
+ private void assertNoIncomingNode(String name, int depth, boolean filtered) {
List<NodeDepthInfo> nodes = getNodesByDepth(true, filtered);
for (NodeDepthInfo info : nodes) {
String nodeName = info.node.getName();
@@ -1117,7 +1359,7 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
List<NodeDepthInfo> nodes = getNodesByDepth(true, filtered);
NodeDepthInfo maxDepthNode = nodes.get(nodes.size() - 1);
- assertEquals("Node max depth does not match: " + maxDepthNode, depth, maxDepthNode.depth);
+ assertEquals("Node max depth does not match: " + depth, depth, maxDepthNode.depth);
}
private List<NodeDepthInfo> getNodesByDepth(boolean incoming) {
@@ -1160,6 +1402,8 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
private void setDepth(final int depth) {
runSwing(() -> provider.setRecurseDepth(depth));
+ waitForTree(incomingTree);
+ waitForTree(outgoingTree);
}
private int currentDepthSetting(CallTreeProvider aProvider) {
@@ -1207,9 +1451,8 @@ public class CallTreePluginTest extends AbstractGhidraHeadedIntegrationTest {
}
}
- String errorMessage =
- (shouldHaveDuplicates ? "Did not find " : "Found") + " duplicate child entries for '" +
- duplicateName + "'";
+ String errorMessage = (shouldHaveDuplicates ? "Did not find " : "Found") +
+ " duplicate child entries for '" + duplicateName + "'";
assertEquals(errorMessage, shouldHaveDuplicates, foundDuplicates);
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/OutgoingFunctionCallNodeTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/OutgoingFunctionCallNodeTest.java
index de437a8a71..362571be0b 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/OutgoingFunctionCallNodeTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/calltree/OutgoingFunctionCallNodeTest.java
@@ -15,11 +15,9 @@
*/
package ghidra.app.plugin.core.calltree;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Before;
import org.junit.Test;
@@ -47,10 +45,6 @@ public class OutgoingFunctionCallNodeTest extends AbstractGenericTest {
private OutgoingFunctionCallNode node;
private String nodeAddress = "0x0000";
- public OutgoingFunctionCallNodeTest() {
- super();
- }
-
@Before
public void setUp() throws Exception {
builder = new ToyProgramBuilder("Call Node Test", true);
@@ -61,7 +55,9 @@ public class OutgoingFunctionCallNodeTest extends AbstractGenericTest {
program = builder.getProgram();
Address source = builder.addr("0x1000"); // fake
- node = new OutgoingFunctionCallNode(program, function, source, true, new AtomicInteger(5));
+ CallTreeOptions callTreeOptions = new CallTreeOptions();
+ callTreeOptions = callTreeOptions.withRecurseDepth(5);
+ node = new OutgoingFunctionCallNode(program, function, source, callTreeOptions);
}
@Test