From 2a96958fd3913d7f771e55cadcba8e6aebcf2e45 Mon Sep 17 00:00:00 2001 From: ghidravore Date: Wed, 29 Sep 2021 11:44:41 -0400 Subject: [PATCH] Fixed a few bugs/tests related to new symbol schema --- .../database/symbol/SymbolManager.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolManager.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolManager.java index a904d25e26..dd2214cc50 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolManager.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/symbol/SymbolManager.java @@ -1033,11 +1033,22 @@ public class SymbolManager implements SymbolTable, ManagerDB { return list; } + private Symbol searchNamespaceForFirstSymbol(String name, Namespace namespace, + Predicate test) { + for (Symbol symbol : getSymbols(namespace)) { + if (name.equals(symbol.getName()) && test.test(symbol)) { + return symbol; + } + } + return null; + } + private Symbol getSymbolForDynamicName(String name) { Address address = SymbolUtilities.parseDynamicName(addrMap.getAddressFactory(), name); if (address != null) { Symbol primarySymbol = getPrimarySymbol(address); - if (primarySymbol != null && primarySymbol.getSource() == SourceType.DEFAULT) { + if (primarySymbol != null && primarySymbol.getSource() == SourceType.DEFAULT && + name.equals(primarySymbol.getName())) { return primarySymbol; } } @@ -1050,6 +1061,18 @@ public class SymbolManager implements SymbolTable, ManagerDB { if (namespace == null) { namespace = namespaceMgr.getGlobalNamespace(); } + + // if name is possible default parameter or local variable name, must do brute force search + if (namespace instanceof Function && + SymbolUtilities.isPossibleDefaultLocalOrParamName(name)) { + return searchNamespaceForFirstSymbol(name, namespace, test); + } + + // if the name is a possible default external name, do brute force search + if (namespace.isExternal() && SymbolUtilities.isPossibleDefaultExternalName(name)) { + return searchNamespaceForFirstSymbol(name, namespace, test); + } + lock.acquire(); try { RecordIterator it = adapter.getSymbolsByNameAndNamespace(name, namespace.getID());