From 97fc20a50ee9670d014ee9b1e4793fd9c325774a Mon Sep 17 00:00:00 2001 From: ghidravore Date: Mon, 14 Dec 2020 11:46:22 -0500 Subject: [PATCH] GP-493 fixed graph navigation to go to 'fake' functions if a vertex repersenting an external function is cliked --- .../AddressBasedGraphDisplayListener.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java index 71447e37b4..8b3224d38f 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/graph/AddressBasedGraphDisplayListener.java @@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger; import docking.widgets.EventTrigger; import ghidra.app.events.*; +import ghidra.app.nav.NavigationUtils; import ghidra.framework.model.*; import ghidra.framework.plugintool.PluginEvent; import ghidra.framework.plugintool.PluginTool; @@ -158,9 +159,22 @@ public abstract class AddressBasedGraphDisplayListener if (symbols.isEmpty()) { return null; } - // there should only be one external symbol with the same name, so just assume the first one is good - return symbols.get(0).getAddress(); + // There should only be one external symbol with the same name. + // Since externals are not shown in the listing, we are going to do a hack and try + // and navigate to a "fake" function if one exists. A "fake" function in Ghidra is just + // an indirect pointer to the external function. If such a pointer exists, Ghidra marks + // up the location with the function signature. + Address symbolAddress = symbols.get(0).getAddress(); + if (symbolAddress.isExternalAddress()) { + Address[] externalLinkageAddresses = + NavigationUtils.getExternalLinkageAddresses(program, symbolAddress); + // If this is a "fake" function situation, then there should only be one address + if (externalLinkageAddresses.length == 1) { + symbolAddress = externalLinkageAddresses[0]; + } + } + return symbolAddress; } protected Address getAddress(AttributedVertex vertex) {