decompiler 1.0.0
Public Member Functions | Private Member Functions | List of all members
ghidra::RulePullAbsorb Class Reference

Simplify expressions explicitly using ZPULL and SPULL p-code ops. More...

#include <bitfield.hh>

Inheritance diagram for ghidra::RulePullAbsorb:
ghidra::Rule

Public Member Functions

 RulePullAbsorb (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.
 

Private Member Functions

int4 absorbRight (Funcdata &data, PcodeOp *rightOp, PcodeOp *pullOp)
 Perform transforms involving the expression: field >> #c
 
int4 absorbRightAndCompZero (Funcdata &data, PcodeOp *rightOp, PcodeOp *andOp, PcodeOp *pullOp)
 Perform transform: ((sfield >> #n) & #1) == #0 => #0 <= sfield
 
int4 absorbLeft (Funcdata &data, PcodeOp *leftOp, PcodeOp *pullOp)
 Perform transforms involving the expression: field << #c
 
int4 absorbLeftRight (Funcdata &data, PcodeOp *rightOp, PcodeOp *leftOp, PcodeOp *pullOp)
 Perform the transform: (field << #c) >> #d => field >> (#d-#c)
 
int4 absorbLeftAnd (Funcdata &data, PcodeOp *andOp, PcodeOp *leftOp, PcodeOp *pullOp)
 Perform the transform: ((field << #c) & #b) == #d => (field & #b>>c) == #d>>c
 
int4 absorbAnd (Funcdata &data, PcodeOp *andOp, PcodeOp *pullOp)
 Perform transform: field & #signbit == #0 => field < 0
 
int4 absorbCompare (Funcdata &data, PcodeOp *compOp, PcodeOp *leftOp, PcodeOp *pullOp)
 Perform transforms involving comparisons: INT_LESS, INT_SLESS.
 
int4 absorbExt (Funcdata &data, PcodeOp *extOp, PcodeOp *pullOp)
 Perform transform: y = SEXT( SPULL( x, #p, #n ) ) => y = SPULL( x, #p, #n )
 
int4 absorbSubpiece (Funcdata &data, PcodeOp *subOp, PcodeOp *pullOp)
 Perform transform: y = SUB( PULL( x, #p, #n ) ) => y = PULL( x, #p, #n )
 
int4 absorbCompZero (Funcdata &data, PcodeOp *compOp, PcodeOp *pullOp)
 Perform transform: ZPULL( x, #p, #1) != #0 => ZPULL(x, #p, #1)
 

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

Simplify expressions explicitly using ZPULL and SPULL p-code ops.

Member Function Documentation

◆ absorbAnd()

int4 ghidra::RulePullAbsorb::absorbAnd ( Funcdata data,
PcodeOp andOp,
PcodeOp pullOp 
)
private

◆ absorbCompare()

int4 ghidra::RulePullAbsorb::absorbCompare ( Funcdata data,
PcodeOp compOp,
PcodeOp leftOp,
PcodeOp pullOp 
)
private

Perform transforms involving comparisons: INT_LESS, INT_SLESS.

Perform transforms:

  • (boolfield << #c) s< #0 => boolfield
  • #0 s< (boolfield << #c) => !boolfield
  • (field << #c) < (#d<<#c) => field < #d
  • (#d<<#c) < (field << #c) => #d < field
Parameters
datais the function
compOpis the INT_LESS or INT_SLESS op
leftOpis the INT_LEFT op
pullOpis the ZPULL or SPULL op
Returns
1 if transform performed, 0 otherwise

References ghidra::calc_mask(), ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_INT_SLESS, ghidra::Funcdata::destroyVarnodeRecursive(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::Varnode::isConstant(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::opRemoveInput(), ghidra::Funcdata::opSetInput(), ghidra::Funcdata::opSetOpcode(), and ghidra::Funcdata::totalReplace().

Referenced by absorbLeft(), and applyOp().

◆ absorbCompZero()

int4 ghidra::RulePullAbsorb::absorbCompZero ( Funcdata data,
PcodeOp compOp,
PcodeOp pullOp 
)
private

◆ absorbExt()

int4 ghidra::RulePullAbsorb::absorbExt ( Funcdata data,
PcodeOp extOp,
PcodeOp pullOp 
)
private

Perform transform: y = SEXT( SPULL( x, #p, #n ) ) => y = SPULL( x, #p, #n )

Also transform: y = ZEXT( ZPULL( x, #p, #n ) ) => y = ZPULL( x, #p, #n )

Parameters
datais the function
extOpis the INT_SEXT or INT_ZEXT op
pullOpis the ZPULL or SPULL op
Returns
1 if transform performed, 0 otherwise

References ghidra::PcodeOp::code(), ghidra::CPUI_INT_SEXT, ghidra::CPUI_SPULL, ghidra::Funcdata::destroyVarnodeRecursive(), ghidra::PcodeOp::getIn(), ghidra::Varnode::loneDescend(), ghidra::Funcdata::opInsertInput(), ghidra::Funcdata::opSetInput(), and ghidra::Funcdata::opSetOpcode().

Referenced by applyOp().

◆ absorbLeft()

int4 ghidra::RulePullAbsorb::absorbLeft ( Funcdata data,
PcodeOp leftOp,
PcodeOp pullOp 
)
private

Perform transforms involving the expression: field << #c

Parameters
datais the function
leftOpis the INT_LEFT op
pullOpis the ZPULL or SPULL op
Returns
1 if a transform was performed, 0 otherwise

References absorbCompare(), absorbLeftAnd(), absorbLeftRight(), ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_INT_AND, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_INT_SLESS, ghidra::Varnode::endDescend(), and ghidra::PcodeOp::getOut().

Referenced by applyOp().

◆ absorbLeftAnd()

int4 ghidra::RulePullAbsorb::absorbLeftAnd ( Funcdata data,
PcodeOp andOp,
PcodeOp leftOp,
PcodeOp pullOp 
)
private

Perform the transform: ((field << #c) & #b) == #d => (field & #b>>c) == #d>>c

Parameters
datais the function
andOpis the INT_AND op
leftOpis the INT_LEFT op
pullOpis the ZPULL or SPULL op
Returns
1 if a transform was performed, 0 otherwise

References ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_INT_EQUAL, ghidra::CPUI_INT_NOTEQUAL, ghidra::Funcdata::destroyVarnodeRecursive(), ghidra::Varnode::endDescend(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::Varnode::getType(), ghidra::Varnode::isConstant(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::opSetInput(), and ghidra::Varnode::updateType().

Referenced by absorbLeft().

◆ absorbLeftRight()

int4 ghidra::RulePullAbsorb::absorbLeftRight ( Funcdata data,
PcodeOp rightOp,
PcodeOp leftOp,
PcodeOp pullOp 
)
private

Perform the transform: (field << #c) >> #d => field >> (#d-#c)

Parameters
datais the function
rightOpis the INT_RIGHT op
leftOpis the INT_LEFT op
pullOpis the ZPULL or SPULL op
Returns
1 if a transform was performed, 0 otherwise

References ghidra::CPUI_INT_LEFT, ghidra::Funcdata::destroyVarnodeRecursive(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::Varnode::isConstant(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::opSetInput(), ghidra::Funcdata::opSetOpcode(), and ghidra::Funcdata::totalReplace().

Referenced by absorbLeft().

◆ absorbRight()

int4 ghidra::RulePullAbsorb::absorbRight ( Funcdata data,
PcodeOp rightOp,
PcodeOp pullOp 
)
private

Perform transforms involving the expression: field >> #c

Parameters
datais the function
rightOpis the INT_RIGHT or INT_SRIGHT op
pullOpis the ZPULL or SPULL op
Returns
1 if a transform was performed, 0 otherwise

References absorbRightAndCompZero(), ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_INT_AND, ghidra::Varnode::endDescend(), and ghidra::PcodeOp::getOut().

Referenced by applyOp().

◆ absorbRightAndCompZero()

int4 ghidra::RulePullAbsorb::absorbRightAndCompZero ( Funcdata data,
PcodeOp rightOp,
PcodeOp andOp,
PcodeOp pullOp 
)
private

Perform transform: ((sfield >> #n) & #1) == #0 => #0 <= sfield

Perform the variant: ((sfield >> #n) & #1) != #0 => sfield < #0

Parameters
datais the function
rightOpis the INT_RIGHT or INT_SRIGHT op
andOpis the INT_AND
pullOpis the ZPULL or SPULL op
Returns
1 if a transform was performed, 0 otherwise

References ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::Varnode::constantMatch(), ghidra::CPUI_INT_EQUAL, ghidra::CPUI_INT_LESSEQUAL, ghidra::CPUI_INT_NOTEQUAL, ghidra::CPUI_INT_SLESS, ghidra::CPUI_SPULL, ghidra::Funcdata::destroyVarnodeRecursive(), ghidra::Varnode::endDescend(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Varnode::isConstant(), ghidra::Funcdata::opSetInput(), and ghidra::Funcdata::opSetOpcode().

Referenced by absorbRight().

◆ absorbSubpiece()

int4 ghidra::RulePullAbsorb::absorbSubpiece ( Funcdata data,
PcodeOp subOp,
PcodeOp pullOp 
)
private

Perform transform: y = SUB( PULL( x, #p, #n ) ) => y = PULL( x, #p, #n )

Parameters
datais the function
subOpis the SUBPIECE op
pullOpis the ZPULL or SPULL op
Returns
1 if transform performed, 0 otherwise

References ghidra::PcodeOp::code(), ghidra::Funcdata::destroyVarnodeRecursive(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::Varnode::loneDescend(), ghidra::Funcdata::opInsertInput(), ghidra::Funcdata::opSetInput(), and ghidra::Funcdata::opSetOpcode().

Referenced by applyOp().

◆ applyOp()

int4 ghidra::RulePullAbsorb::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 absorbAnd(), absorbCompare(), absorbCompZero(), absorbExt(), absorbLeft(), absorbRight(), absorbSubpiece(), ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_INT_AND, ghidra::CPUI_INT_EQUAL, ghidra::CPUI_INT_LEFT, ghidra::CPUI_INT_LESS, ghidra::CPUI_INT_NOTEQUAL, ghidra::CPUI_INT_RIGHT, ghidra::CPUI_INT_SEXT, ghidra::CPUI_INT_SLESS, ghidra::CPUI_INT_SRIGHT, ghidra::CPUI_INT_ZEXT, ghidra::CPUI_SUBPIECE, ghidra::Varnode::endDescend(), and ghidra::PcodeOp::getOut().

◆ clone()

virtual Rule * ghidra::RulePullAbsorb::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().

◆ getOpList()

void ghidra::RulePullAbsorb::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_SPULL, and ghidra::CPUI_ZPULL.


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