From e7b63fdab564ec8a0175f031d5cb71b108e3e8ad Mon Sep 17 00:00:00 2001 From: caheckman <48068198+caheckman@users.noreply.github.com> Date: Tue, 6 Oct 2020 15:40:58 -0400 Subject: [PATCH 1/3] Fix "Duplicate scope id" error with undefined functions in decompiler --- .../main/java/ghidra/program/model/pcode/HighFunction.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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.java index 25e3121d4d..de9571acb1 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 @@ -79,14 +79,15 @@ public class HighFunction extends PcodeSyntaxTree { } /** - * Get the id with the associated function symbol, if it exists - * @return the id or 0 otherwise + * Get the id with the associated function symbol, if it exists. + * Otherwise return a dynamic id based on the entry point. + * @return the symbol id, or possibly a dynamic id */ public long getID() { if (func instanceof FunctionDB) { return func.getSymbol().getID(); } - return 0; + return func.getProgram().getSymbolTable().getDynamicSymbolID(func.getEntryPoint()); } /** From e8b7a61197a1a1b212f9f1b9e061582de10d1f56 Mon Sep 17 00:00:00 2001 From: caheckman <48068198+caheckman@users.noreply.github.com> Date: Wed, 7 Oct 2020 15:27:13 -0400 Subject: [PATCH 2/3] Fix combinatorial explosion in ancestorOpUse --- .../src/decompile/cpp/funcdata_varnode.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc index 46e676e9c6..7cbdb14d9b 100644 --- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc +++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc @@ -1584,13 +1584,20 @@ bool Funcdata::ancestorOpUse(int4 maxlevel,const Varnode *invn, // as an "only use" if (def->isIndirectCreation()) return false; - // fallthru + return ancestorOpUse(maxlevel-1,def->getIn(0),op,trial); case CPUI_MULTIEQUAL: // Check if there is any ancestor whose only // use is in this op - for(i=0;inumInput();++i) - if (ancestorOpUse(maxlevel-1,def->getIn(i),op,trial)) return true; - + if (def->isMark()) return false; // Trim the loop + def->setMark(); // Mark that this MULTIEQUAL is on the path + // Note: onlyOpUse is using Varnode::setMark + for(i=0;inumInput();++i) { + if (ancestorOpUse(maxlevel-1,def->getIn(i),op,trial)) { + def->clearMark(); + return true; + } + } + def->clearMark(); return false; case CPUI_COPY: if ((invn->getSpace()->getType()==IPTR_INTERNAL)||def->isIncidentalCopy()||def->getIn(0)->isIncidentalCopy()) { From 078159dd2912fd6575ea358cb52d668b15cab642 Mon Sep 17 00:00:00 2001 From: caheckman <48068198+caheckman@users.noreply.github.com> Date: Tue, 13 Oct 2020 17:45:53 -0400 Subject: [PATCH 3/3] Scope id fix for external references --- .../java/ghidra/app/decompiler/DecompileCallback.java | 11 ++++++++++- .../program/model/pcode/HighFunctionShellSymbol.java | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileCallback.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileCallback.java index 92002b4d14..1140ca057f 100644 --- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileCallback.java +++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/DecompileCallback.java @@ -757,8 +757,17 @@ public class DecompileCallback { if (extRef != null) { func = listing.getFunctionAt(extRef.getToAddress()); if (func == null) { + Symbol symbol = extRef.getExternalLocation().getSymbol(); + long extId; + if (symbol != null) { + extId = symbol.getID(); + } + else { + extId = program.getSymbolTable().getDynamicSymbolID(addr); + + } HighSymbol shellSymbol = - new HighFunctionShellSymbol(0, extRef.getLabel(), addr, dtmanage); + new HighFunctionShellSymbol(extId, extRef.getLabel(), addr, dtmanage); return buildResult(shellSymbol, null); } } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunctionShellSymbol.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunctionShellSymbol.java index 82857373c1..ec8782fb5b 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunctionShellSymbol.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunctionShellSymbol.java @@ -55,6 +55,7 @@ public class HighFunctionShellSymbol extends HighSymbol { @Override public void saveXML(StringBuilder buf) { buf.append("\n");