Skip to content

Commit 0a1da61

Browse files
committed
Lock unused input varnodes with special flag, not typelock
1 parent 6bac1a8 commit 0a1da61

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,6 +3469,7 @@ int4 ActionPrototypeTypes::apply(Funcdata &data)
34693469
ProtoParameter *param = data.getFuncProto().getParam(i);
34703470
Varnode *vn = data.newVarnode( param->getSize(), param->getAddress());
34713471
vn = data.setInputVarnode(vn);
3472+
vn->setLockedInput();
34723473
if (topbl != (BlockBasic *)0)
34733474
extendInput(data,vn,param,topbl);
34743475
if (ptr_size > 0) {

Ghidra/Features/Decompiler/src/decompile/cpp/funcdata_varnode.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -711,12 +711,9 @@ void Funcdata::clearDeadVarnodes(void)
711711
while(iter!=vbank.endLoc()) {
712712
vn = *iter++;
713713
if (vn->hasNoDescend()) {
714-
if (vn->isInput()&&(!vn->isMark())) {
715-
if ((vn->isSpacebase())|| // Space base is always typelocked
716-
(!vn->isTypeLock())) {
717-
vbank.makeFree(vn);
718-
vn->clearCover();
719-
}
714+
if (vn->isInput() && !vn->isLockedInput()) {
715+
vbank.makeFree(vn);
716+
vn->clearCover();
720717
}
721718
if (vn->isFree())
722719
vbank.destroy(vn);

Ghidra/Features/Decompiler/src/decompile/cpp/varnode.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public:
116116
ptrcheck = 0x10, ///< The Varnode value is \e NOT a pointer
117117
ptrflow = 0x20, ///< If this varnode flows to or from a pointer
118118
unsignedprint = 0x40, ///< Constant that must be explicitly printed as unsigned
119-
stack_store = 0x80 ///< Created by an explicit STORE
119+
stack_store = 0x80, ///< Created by an explicit STORE
120+
locked_input = 0x100 ///< Input that exists even if its unused
120121
};
121122
private:
122123
mutable uint4 flags; ///< The collection of boolean attributes for this Varnode
@@ -237,6 +238,7 @@ public:
237238
bool isMark(void) const { return ((flags&Varnode::mark)!=0); } ///< Has \b this been visited by the current algorithm?
238239
bool isActiveHeritage(void) const { return ((addlflags&Varnode::activeheritage)!=0); } ///< Is \b this currently being traced by the Heritage algorithm?
239240
bool isStackStore(void) const { return ((addlflags&Varnode::stack_store)!=0); } ///< Was this originally produced by an explicit STORE
241+
bool isLockedInput(void) const { return ((addlflags&Varnode::locked_input)!=0); } ///< Is always an input, even if unused
240242

241243
/// Is \b this just a special placeholder representing INDIRECT creation?
242244
bool isIndirectZero(void) const { return ((flags&(Varnode::indirect_creation|Varnode::constant))==(Varnode::indirect_creation|Varnode::constant)); }
@@ -297,6 +299,7 @@ public:
297299
void setUnsignedPrint(void) { addlflags |= Varnode::unsignedprint; } ///< Force \b this to be printed as unsigned
298300
bool updateType(Datatype *ct,bool lock,bool override); ///< (Possibly) set the Datatype given various restrictions
299301
void setStackStore(void) { addlflags |= Varnode::stack_store; } ///< Mark as produced by explicit CPUI_STORE
302+
void setLockedInput(void) { addlflags |= Varnode::locked_input; } ///< Mark as existing input, even if unused
300303
void copySymbol(const Varnode *vn); ///< Copy symbol info from \b vn
301304
void copySymbolIfValid(const Varnode *vn); ///< Copy symbol info from \b vn if constant value matches
302305
Datatype *getLocalType(void) const; ///< Calculate type of Varnode based on local information

0 commit comments

Comments
 (0)