Ghidra 11.3.2
Ghidra internal decompiler documentation.
Loading...
Searching...
No Matches
ghidra::RulePtrsubUndo Class Reference

Remove PTRSUB operations with mismatched data-type information. More...

Inheritance diagram for ghidra::RulePtrsubUndo:
[legend]
Collaboration diagram for ghidra::RulePtrsubUndo:
[legend]

Public Member Functions

 RulePtrsubUndo (const string &g)
 Constructor.
 
virtual Ruleclone (const ActionGroupList &grouplist) const
 Clone the Rule.
 
virtual void getOpList (vector< uint4 > &oplist) const
 List of op codes this rule operates on.
 
virtual int4 applyOp (PcodeOp *op, Funcdata &data)
 Attempt to apply this Rule.
 
- Public Member Functions inherited from ghidra::Rule
 Rule (const string &g, uint4 fl, const string &nm)
 Construct given group, properties name.
 
virtual ~Rule (void)
 Destructor.
 
const string & getName (void) const
 Return the name of this Rule.
 
const string & getGroup (void) const
 Return the group this Rule belongs to.
 
uint4 getNumTests (void)
 Get number of attempted applications.
 
uint4 getNumApply (void)
 Get number of successful applications.
 
void setBreak (uint4 tp)
 Set a breakpoint on this Rule.
 
void clearBreak (uint4 tp)
 Clear a breakpoint on this Rule.
 
void clearBreakPoints (void)
 Clear all breakpoints on this Rule.
 
void turnOnWarnings (void)
 Enable warnings for this Rule.
 
void turnOffWarnings (void)
 Disable warnings for this Rule.
 
bool isDisabled (void) const
 Return true if this Rule is disabled.
 
void setDisable (void)
 Disable this Rule (within its pool)
 
void clearDisable (void)
 Enable this Rule (within its pool)
 
bool checkActionBreak (void)
 Check if an action breakpoint is turned on.
 
uint4 getBreakPoint (void) const
 Return breakpoint toggles.
 
virtual void reset (Funcdata &data)
 Reset this Rule.
 
virtual void resetStats (void)
 Reset Rule statistics.
 
virtual void printStatistics (ostream &s) const
 Print statistics for this Rule.
 

Static Private Member Functions

static int8 getConstOffsetBack (Varnode *vn, int8 &multiplier, int4 maxLevel)
 Recursively search for additive constants and multiplicative constants.
 
static int8 getExtraOffset (PcodeOp *op, int8 &multiplier)
 Collect constants and the biggest multiplier in the given PTRSUB expression.
 
static int8 removeLocalAdds (Varnode *vn, Funcdata &data)
 Remove constants in the additive expression involving the given Varnode.
 
static int8 removeLocalAddRecurse (PcodeOp *op, int4 slot, int4 maxLevel, Funcdata &data)
 Remove any constants in the additive expression rooted at the given PcodeOp.
 

Static Private Attributes

static const int4 DEPTH_LIMIT = 8
 The maximum depth of the additive expression to check.
 

Additional Inherited Members

- Public Types inherited from ghidra::Rule
enum  typeflags { type_disable = 1 , rule_debug = 2 , warnings_on = 4 , warnings_given = 8 }
 Properties associated with a Rule. More...
 

Detailed Description

Remove PTRSUB operations with mismatched data-type information.

Incorrect data-types may be assigned to Varnodes in the middle of simplification. This causes incorrect PTRSUBs, which are discovered later. This rule converts the PTRSUB back to an INT_ADD when the mistake is discovered.

Member Function Documentation

◆ applyOp()

int4 ghidra::RulePtrsubUndo::applyOp ( PcodeOp op,
Funcdata data 
)
virtual

Attempt to apply this Rule.

This method contains the main logic for applying the Rule. It must use a given PcodeOp as the point at which the Rule applies. If it does apply, changes are made directly to the function and 1 (non-zero) is returned, otherwise 0 is returned.

Parameters
opis the given PcodeOp where the Rule may apply
datais the function to which to apply

Reimplemented from ghidra::Rule.

References ghidra::calc_mask(), ghidra::PcodeOp::clearStopTypePropagation(), ghidra::CPUI_INT_ADD, getExtraOffset(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::Varnode::getTypeReadFacing(), ghidra::Funcdata::hasTypeRecoveryStarted(), ghidra::Datatype::isPtrsubMatching(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::opSetInput(), ghidra::Funcdata::opSetOpcode(), and removeLocalAdds().

◆ clone()

virtual Rule * ghidra::RulePtrsubUndo::clone ( const ActionGroupList grouplist) const
inlinevirtual

Clone the Rule.

If this Rule is a member of one of the groups in the grouplist, this returns a clone of the Rule, otherwise NULL is returned.

Parameters
grouplistis the list of groups being cloned
Returns
the cloned Rule or NULL

Implements ghidra::Rule.

References ghidra::ActionGroupList::contains(), and ghidra::Rule::getGroup().

◆ getConstOffsetBack()

int8 ghidra::RulePtrsubUndo::getConstOffsetBack ( Varnode vn,
int8 &  multiplier,
int4  maxLevel 
)
staticprivate

Recursively search for additive constants and multiplicative constants.

Walking backward from the given Varnode, search for constants being added in and return the sum of all the constants. Additionally pass back the biggest constant coefficient, for any term formed with INT_MULT.

Parameters
vnis the given root Varnode of the additive tree
multiplierwill hold the biggest constant multiplier or 0, if no multiplier is present
maxLevelis the maximum depth to search in the tree
Returns
the sum of all constants in the additive expression

References ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_MULT, getConstOffsetBack(), ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::isConstant(), and ghidra::Varnode::isWritten().

Referenced by getConstOffsetBack(), and getExtraOffset().

◆ getExtraOffset()

int8 ghidra::RulePtrsubUndo::getExtraOffset ( PcodeOp op,
int8 &  multiplier 
)
staticprivate

Collect constants and the biggest multiplier in the given PTRSUB expression.

Walking the additive expression (INT_ADD, PTRADD, and other PTRSUBs) and calculate any additional constant value being added to the PTRSUB. Additionally pass back the biggest constant coefficient of any multiplicative term in the expression.

Parameters
opis the given PTRSUB
multiplierwill hold the biggest multiplicative coefficient or 0, if no INT_MULT or PTRADD is present.

References ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, DEPTH_LIMIT, getConstOffsetBack(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::PcodeOp::getSlot(), ghidra::Varnode::isConstant(), and ghidra::Varnode::loneDescend().

Referenced by applyOp().

◆ getOpList()

void ghidra::RulePtrsubUndo::getOpList ( vector< uint4 > &  oplist) const
virtual

List of op codes this rule operates on.

Populate the given array with all possible OpCodes this Rule might apply to. By default, this method returns all possible OpCodes

Parameters
oplistis the array to populate

Reimplemented from ghidra::Rule.

References ghidra::CPUI_PTRSUB.

◆ removeLocalAddRecurse()

int8 ghidra::RulePtrsubUndo::removeLocalAddRecurse ( PcodeOp op,
int4  slot,
int4  maxLevel,
Funcdata data 
)
staticprivate

Remove any constants in the additive expression rooted at the given PcodeOp.

Walking recursively through the expression, any INT_ADD with a constant input is converted to a COPY. The INT_ADD must only contribute to the root expression.

Parameters
opis the given root PcodeOp
slotis the input slot to walk back from
maxLevelis the maximum depth to recurse
datais the function containing the expression
Returns
the sum of all constants that are removed

References ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INT_ADD, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::isConstant(), ghidra::Varnode::isWritten(), ghidra::Varnode::loneDescend(), ghidra::Funcdata::opRemoveInput(), ghidra::Funcdata::opSetOpcode(), and removeLocalAddRecurse().

Referenced by removeLocalAddRecurse(), and removeLocalAdds().

◆ removeLocalAdds()

int8 ghidra::RulePtrsubUndo::removeLocalAdds ( Varnode vn,
Funcdata data 
)
staticprivate

Remove constants in the additive expression involving the given Varnode.

Any additional PTRADD, PTRSUB, or INT_ADD that uses the Varnode and adds a constant is converted to a COPY. Additionally any other INT_ADD involved in the expression that adds a constant is also converted to COPY.

Parameters
vnis the given Varnode
datais the function containing the expression
Returns
the sum of all constants that are removed

References ghidra::PcodeOp::clearStopTypePropagation(), ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INT_ADD, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, DEPTH_LIMIT, ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::PcodeOp::getSlot(), ghidra::Varnode::isConstant(), ghidra::Varnode::loneDescend(), ghidra::Funcdata::opRemoveInput(), ghidra::Funcdata::opSetOpcode(), ghidra::Funcdata::opUndoPtradd(), and removeLocalAddRecurse().

Referenced by applyOp().


The documentation for this class was generated from the following files: