Ghidra is a software reverse engineering (SRE) framework
Lock unused input varnodes with special flag, not typelock
caheckman0a1da61da085
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.ccindex 207a41b2b5..be35424a27 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc@@ -3469,6 +3469,7 @@ int4 ActionPrototypeTypes::apply(Funcdata &data)ProtoParameter *param = data.getFuncProto().getParam(i);Varnode *vn = data.newVarnode( param->getSize(), param->getAddress());vn = data.setInputVarnode(vn);+ vn->setLockedInput();if (topbl != (BlockBasic *)0)extendInput(data,vn,param,topbl);if (ptr_size > 0) {diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.ccindex 372952954a..17341e4d49 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc@@ -711,12 +711,9 @@ void Funcdata::clearDeadVarnodes(void)while(iter!=vbank.endLoc()) {vn = *iter++;if (vn->hasNoDescend()) {- if (vn->isInput()&&(!vn->isMark())) {- if ((vn->isSpacebase())|| // Space base is always typelocked- (!vn->isTypeLock())) {- vbank.makeFree(vn);- vn->clearCover();- }+ if (vn->isInput() && !vn->isLockedInput()) {+ vbank.makeFree(vn);+ vn->clearCover();}if (vn->isFree())vbank.destroy(vn);diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hhindex f0cf10be50..908c6bf1c0 100644--- a/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh@@ -116,7 +116,8 @@ public:ptrcheck = 0x10, ///< The Varnode value is \e NOT a pointerptrflow = 0x20, ///< If this varnode flows to or from a pointerunsignedprint = 0x40, ///< Constant that must be explicitly printed as unsigned- stack_store = 0x80 ///< Created by an explicit STORE+ stack_store = 0x80, ///< Created by an explicit STORE+ locked_input = 0x100 ///< Input that exists even if its unused};private:mutable uint4 flags; ///< The collection of boolean attributes for this Varnode@@ -237,6 +238,7 @@ public:bool isMark(void) const { return ((flags&Varnode::mark)!=0); } ///< Has \b this been visited by the current algorithm?bool isActiveHeritage(void) const { return ((addlflags&Varnode::activeheritage)!=0); } ///< Is \b this currently being traced by the Heritage algorithm?bool isStackStore(void) const { return ((addlflags&Varnode::stack_store)!=0); } ///< Was this originally produced by an explicit STORE+ bool isLockedInput(void) const { return ((addlflags&Varnode::locked_input)!=0); } ///< Is always an input, even if unused/// Is \b this just a special placeholder representing INDIRECT creation?bool isIndirectZero(void) const { return ((flags&(Varnode::indirect_creation|Varnode::constant))==(Varnode::indirect_creation|Varnode::constant)); }@@ -297,6 +299,7 @@ public:void setUnsignedPrint(void) { addlflags |= Varnode::unsignedprint; } ///< Force \b this to be printed as unsignedbool updateType(Datatype *ct,bool lock,bool override); ///< (Possibly) set the Datatype given various restrictionsvoid setStackStore(void) { addlflags |= Varnode::stack_store; } ///< Mark as produced by explicit CPUI_STORE+ void setLockedInput(void) { addlflags |= Varnode::locked_input; } ///< Mark as existing input, even if unusedvoid copySymbol(const Varnode *vn); ///< Copy symbol info from \b vnvoid copySymbolIfValid(const Varnode *vn); ///< Copy symbol info from \b vn if constant value matchesDatatype *getLocalType(void) const; ///< Calculate type of Varnode based on local information