Resolve thunk namespaces, don't send Library namespaces to decompiler

This commit is contained in:
caheckman 2020-06-18 12:02:56 -04:00
parent f7a8e264aa
commit 0d9e25548a
4 changed files with 38 additions and 6 deletions

View file

@ -467,8 +467,8 @@ public class HighFunction extends PcodeSyntaxTree {
proto.buildPrototypeXML(resBuf, getDataTypeManager());
if ((jumpTables != null) && (jumpTables.size() > 0)) {
resBuf.append("<jumptablelist>\n");
for (int i = 0; i < jumpTables.size(); ++i) {
jumpTables.get(i).buildXml(resBuf);
for (JumpTable jumpTable : jumpTables) {
jumpTable.buildXml(resBuf);
}
resBuf.append("</jumptablelist>\n");
}
@ -478,8 +478,7 @@ public class HighFunction extends PcodeSyntaxTree {
}
if ((protoOverrides != null) && (protoOverrides.size() > 0)) {
PcodeDataTypeManager dtmanage = getDataTypeManager();
for (int i = 0; i < protoOverrides.size(); ++i) {
DataTypeSymbol sym = protoOverrides.get(i);
for (DataTypeSymbol sym : protoOverrides) {
Address addr = sym.getAddress();
FunctionPrototype fproto = new FunctionPrototype(
(FunctionSignature) sym.getDataType(), compilerSpec, false);
@ -626,6 +625,9 @@ public class HighFunction extends PcodeSyntaxTree {
Namespace curspc = namespc;
while (curspc != null) {
arr.add(0, curspc.getName());
if (curspc instanceof Library) {
break; // Treat library namespace as root
}
curspc = curspc.getParentNamespace();
}
buf.append("<val/>\n"); // Force global scope to have empty name

View file

@ -17,7 +17,9 @@ package ghidra.program.model.pcode;
import ghidra.program.model.address.Address;
import ghidra.program.model.data.DataType;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.VariableStorage;
import ghidra.program.model.symbol.Namespace;
import ghidra.util.exception.InvalidInputException;
/**
@ -54,6 +56,21 @@ public class HighFunctionSymbol extends HighSymbol {
return true;
}
@Override
public Namespace getNamespace() {
Function func = function.getFunction();
Namespace namespc = func.getParentNamespace();
if (func.isThunk()) {
// Thunks can be in a different namespace than the thunked function.
// We choose the thunk's namespace unless it is the global namespace
if (namespc.getID() == Namespace.GLOBAL_NAMESPACE_ID) {
Function baseFunc = func.getThunkedFunction(true);
namespc = baseFunc.getParentNamespace();
}
}
return namespc;
}
@Override
public void saveXML(StringBuilder buf) {
MappedEntry entry = (MappedEntry) getFirstWholeMap();

View file

@ -19,6 +19,7 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.data.DataType;
import ghidra.program.model.listing.Program;
import ghidra.program.model.listing.VariableStorage;
import ghidra.program.model.symbol.Namespace;
import ghidra.program.model.symbol.Symbol;
import ghidra.util.xml.SpecXmlUtils;
import ghidra.xml.XmlElement;
@ -130,6 +131,18 @@ public class HighSymbol {
return null;
}
/**
* Fetch the namespace owning this symbol, if it exists.
* @return the Namespace object or null
*/
public Namespace getNamespace() {
Symbol sym = getSymbol();
if (sym != null) {
return sym.getParentNamespace();
}
return null;
}
/**
* Associate a particular HighVariable with this symbol. This is used to link the symbol
* into the decompiler's description of how a function manipulates a particular symbol.