From 0a1da61da0852e5fc695128b4f9db2b3b110ce58 Mon Sep 17 00:00:00 2001 From: caheckman <48068198+caheckman@users.noreply.github.com> Date: Fri, 8 Nov 2019 15:50:26 -0500 Subject: [PATCH] Lock unused input varnodes with special flag, not typelock --- .../Features/Decompiler/src/decompile/cpp/coreaction.cc | 1 + .../Decompiler/src/decompile/cpp/funcdata_varnode.cc | 9 +++------ Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh | 5 ++++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc index 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.cc index 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.hh index 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 pointer ptrflow = 0x20, ///< If this varnode flows to or from a pointer unsignedprint = 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 unsigned bool updateType(Datatype *ct,bool lock,bool override); ///< (Possibly) set the Datatype given various restrictions void 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 unused void copySymbol(const Varnode *vn); ///< Copy symbol info from \b vn void copySymbolIfValid(const Varnode *vn); ///< Copy symbol info from \b vn if constant value matches Datatype *getLocalType(void) const; ///< Calculate type of Varnode based on local information