Ghidra is a software reverse engineering (SRE) framework
Use correct namespace in LocalSymbolMap
caheckman84e4b8c6fe1f
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.ccindex e7fd783be2..41d39816a8 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc@@ -2479,7 +2479,7 @@ ProtoParameter *ProtoStoreSymbol::setInput(int4 i, const string &nm,const Parame}}if (res->sym == (Symbol *)0) {- if (scope->discoverScope(pieces.addr,pieces.type->getSize(),usepoint) != scope)+ if (scope->discoverScope(pieces.addr,pieces.type->getSize(),usepoint) == (Scope *)0)usepoint = restricted_usepoint;res->sym = scope->addSymbol(nm,pieces.type,pieces.addr,usepoint)->getSymbol();scope->setCategory(res->sym,0,i);diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.ccindex 2a895e3640..8f7862999b 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc@@ -1326,6 +1326,7 @@ void Funcdata::mapGlobals(void)vn = *iter++;if (vn->isFree()) continue;if (!vn->isPersist()) continue; // Could be a code ref+ if (vn->getSymbolEntry() != (SymbolEntry *)0) continue;maxvn = vn;Address addr = vn->getAddr();Address endaddr = addr + vn->getSize();diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.javaindex edf03cd90b..a3f59cebea 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java@@ -436,11 +436,12 @@ public class HighFunction extends PcodeSyntaxTree {* addresses near its entry point.** @param id is the id associated with the function symbol+ * @param namespace is the namespace containing the function symbol* @param entryPoint pass null to use the function entryPoint, pass an address to force an entry point* @param size describes how many bytes the function occupies as code* @return the XML string*/- public String buildFunctionXML(long id, Address entryPoint, int size) {+ public String buildFunctionXML(long id, Namespace namespace, Address entryPoint, int size) {// Functions aren't necessarily contiguous with the smallest address being the entry point// So size needs to be smaller than size of the contiguous chunk containing the entry pointStringBuilder resBuf = new StringBuilder();@@ -463,7 +464,7 @@ public class HighFunction extends PcodeSyntaxTree {else {resBuf.append(Varnode.buildXMLAddress(entryPoint)); // Address is forced on XML}- resBuf.append(localSymbols.buildLocalDbXML());+ localSymbols.buildLocalDbXML(resBuf, namespace);proto.buildPrototypeXML(resBuf, getDataTypeManager());if ((jumpTables != null) && (jumpTables.size() > 0)) {resBuf.append("<jumptablelist>\n");diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunctionSymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunctionSymbol.javaindex fbd1d181f4..8db7033003 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunctionSymbol.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunctionSymbol.java@@ -75,7 +75,8 @@ public class HighFunctionSymbol extends HighSymbol {public void saveXML(StringBuilder buf) {MappedEntry entry = (MappedEntry) getFirstWholeMap();String funcString =- function.buildFunctionXML(getId(), entry.getStorage().getMinAddress(), entry.getSize());+ function.buildFunctionXML(getId(), getNamespace(), entry.getStorage().getMinAddress(),+ entry.getSize());buf.append(funcString);}}diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/LocalSymbolMap.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/LocalSymbolMap.javaindex c343a8720f..ba1c4a3a77 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/LocalSymbolMap.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/LocalSymbolMap.java@@ -325,31 +325,31 @@ public class LocalSymbolMap {}/**- * @return an XML document string representing this local variable map.+ * Output an XML document representing this local variable map.+ * @param resBuf is the buffer to write to+ * @param namespace if the namespace of the function*/- public String buildLocalDbXML() { // Get memory mapped local variables- StringBuilder res = new StringBuilder();- res.append("<localdb");- SpecXmlUtils.encodeBooleanAttribute(res, "lock", false);- SpecXmlUtils.encodeStringAttribute(res, "main", spacename);- res.append(">\n");- res.append("<scope");- SpecXmlUtils.xmlEscapeAttribute(res, "name", func.getFunction().getName());- res.append(">\n");- res.append("<parent>\n");- HighFunction.createNamespaceTag(res, func.getFunction().getParentNamespace());- res.append("</parent>\n");- res.append("<rangelist/>\n"); // Empty address range- res.append("<symbollist>\n");+ public void buildLocalDbXML(StringBuilder resBuf, Namespace namespace) { // Get memory mapped local variables+ resBuf.append("<localdb");+ SpecXmlUtils.encodeBooleanAttribute(resBuf, "lock", false);+ SpecXmlUtils.encodeStringAttribute(resBuf, "main", spacename);+ resBuf.append(">\n");+ resBuf.append("<scope");+ SpecXmlUtils.xmlEscapeAttribute(resBuf, "name", func.getFunction().getName());+ resBuf.append(">\n");+ resBuf.append("<parent>\n");+ HighFunction.createNamespaceTag(resBuf, namespace);+ resBuf.append("</parent>\n");+ resBuf.append("<rangelist/>\n"); // Empty address range+ resBuf.append("<symbollist>\n");Iterator<HighSymbol> iter = symbolMap.values().iterator();while (iter.hasNext()) {HighSymbol sym = iter.next();- HighSymbol.buildMapSymXML(res, sym);+ HighSymbol.buildMapSymXML(resBuf, sym);}- res.append("</symbollist>\n");- res.append("</scope>\n");- res.append("</localdb>\n");- return res.toString();+ resBuf.append("</symbollist>\n");+ resBuf.append("</scope>\n");+ resBuf.append("</localdb>\n");}/**