Ghidra Decompiler Analysis Engine
Public Types | Public Member Functions | Friends | List of all members
Rule Class Referenceabstract

Class for performing a single transformation on a PcodeOp or Varnode. More...

#include <action.hh>

Inherited by Rule2Comp2Mult, Rule2Comp2Sub, RuleAddMultCollapse, RuleAddUnsigned, RuleAndCommute, RuleAndCompare, RuleAndDistribute, RuleAndMask, RuleAndOrLump, RuleAndPiece, RuleBitUndistribute, RuleBooleanNegate, RuleBoolNegate, RuleBoolZext, RuleBxor2NotEqual, RuleCarryElim, RuleCollapseConstants, RuleCollectTerms, RuleConcatCommute, RuleConcatLeftShift, RuleConcatShift, RuleConcatZero, RuleConcatZext, RuleConditionalMove, RuleCondNegate, RuleDivOpt, RuleDivTermAdd, RuleDivTermAdd2, RuleDoubleArithShift, RuleDoubleIn, RuleDoubleLoad, RuleDoubleShift, RuleDoubleSub, RuleDumptyHump, RuleEarlyRemoval, RuleEmbed, RuleEqual2Constant, RuleEqual2Zero, RuleEquality, RuleFloatCast, RuleFloatRange, RuleFuncPtrEncoding, RuleGeneric, RuleHighOrderAnd, RuleHumptyDumpty, RuleHumptyOr, RuleIdentityEl, RuleIgnoreNan, RuleIndirectCollapse, RuleIntLessEqual, RuleLeftRight, RuleLess2Zero, RuleLessEqual, RuleLessEqual2Zero, RuleLessNotEqual, RuleLessOne, RuleLoadVarnode, RuleLogic2Bool, RuleModOpt, RuleMultiCollapse, RuleMultNegOne, RuleNegateIdentity, RuleNegateNegate, RuleNotDistribute, RuleOrCollapse, RuleOrConsume, RuleOrMask, RuleOrPredicate, RulePiece2Sext, RulePiece2Zext, RulePiecePathology, RulePopcountBoolXor, RulePositiveDiv, RulePropagateCopy, RulePtraddUndo, RulePtrArith, RulePtrFlow, RulePtrsubCharConstant, RulePtrsubUndo, RulePullsubIndirect, RulePullsubMulti, RulePushMulti, RulePushPtr, RuleRangeMeld, RuleRightShiftAnd, RuleSborrow, RuleSegment, RuleSelectCse, RuleShift2Mult, RuleShiftAnd, RuleShiftBitops, RuleShiftCompare, RuleShiftPiece, RuleShiftSub, RuleSignDiv2, RuleSignForm, RuleSignNearMult, RuleSignShift, RuleSLess2Zero, RuleSlessToLess, RuleSplitFlow, RuleStoreVarnode, RuleStructOffset0, RuleSub2Add, RuleSubCancel, RuleSubCommute, RuleSubExtComm, RuleSubfloatConvert, RuleSubNormal, RuleSubRight, RuleSubvarAnd, RuleSubvarCompZero, RuleSubvarSext, RuleSubvarShift, RuleSubvarSubpiece, RuleSubvarZext, RuleSubZext, RuleSwitchSingle, RuleTermOrder, RuleTestSign, RuleThreeWayCompare, RuleTransformCpool, RuleTrivialArith, RuleTrivialBool, RuleTrivialShift, RuleXorCollapse, RuleXorSwap, RuleZextCommute, RuleZextEliminate, RuleZextShiftZext, and RuleZextSless.

Public Types

enum  typeflags { type_disable = 1, rule_debug = 2, warnings_on = 4, warnings_given = 8 }
 Properties associated with a Rule. More...
 

Public Member Functions

 Rule (const string &g, uint4 fl, const string &nm)
 Construct given group, properties name. More...
 
bool checkActionBreak (void)
 Check if an action breakpoint is turned on. More...
 
virtual Ruleclone (const ActionGroupList &grouplist) const =0
 Clone the Rule. More...
 
virtual void getOpList (vector< uint4 > &oplist) const
 List of op codes this rule operates on. More...
 
virtual int4 applyOp (PcodeOp *op, Funcdata &data)
 Attempt to apply this Rule. More...
 
virtual void reset (Funcdata &data)
 Reset this Rule. More...
 
virtual void resetStats (void)
 Reset Rule statistics. More...
 
virtual void printStatistics (ostream &s) const
 Print statistics for this Rule. More...
 

Friends

class ActionPool
 

Detailed Description

Class for performing a single transformation on a PcodeOp or Varnode.

A Rule, through its applyOp() method, is handed a specific PcodeOp as a potential point to apply. It determines if it can apply at that point, then makes any changes. Rules inform the system of what types of PcodeOps they can possibly apply to through the getOpList() method. A set of Rules are pooled together into a single Action via the ActionPool, which efficiently applies each Rule across a whole function. A Rule supports the same breakpoint properties as an Action. A Rule is allowed to keep state that is specific to a given function (Funcdata). The reset() method is invoked to purge this state for each new function to be transformed.

Member Enumeration Documentation

◆ typeflags

Properties associated with a Rule.

Enumerator
type_disable 

Is this rule disabled.

rule_debug 

Print debug info specific for this rule.

warnings_on 

A warning is issued if this rule is applied.

warnings_given 

Set if a warning for this rule has been given before.

Constructor & Destructor Documentation

◆ Rule()

Rule::Rule ( const string &  g,
uint4  fl,
const string &  nm 
)

Construct given group, properties name.

Parameters
gis the groupname to which this Rule belongs
flis the set of properties
nmis the name of the Rule

Member Function Documentation

◆ applyOp()

virtual int4 Rule::applyOp ( PcodeOp op,
Funcdata data 
)
inlinevirtual

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 in RuleXorSwap, RulePiecePathology, RulePopcountBoolXor, RuleThreeWayCompare, RuleFuncPtrEncoding, RuleIgnoreNan, RuleFloatCast, RuleConditionalMove, RuleNegateNegate, RuleSubfloatConvert, RuleSubvarSext, RuleSubvarZext, RuleSubvarShift, RuleSubvarCompZero, RulePtrFlow, RuleSplitFlow, RuleSubvarSubpiece, RuleSubvarAnd, RuleSegment, RuleModOpt, RuleSignNearMult, RuleSignForm, RuleSignDiv2, RuleDivOpt, RuleDivTermAdd2, RuleDivTermAdd, RulePositiveDiv, RuleSubNormal, RulePtrsubCharConstant, RuleSubRight, Rule2Comp2Sub, RuleAddUnsigned, RuleMultNegOne, RulePtrsubUndo, RulePtraddUndo, RulePushPtr, RuleStructOffset0, RulePtrArith, RuleEqual2Constant, RuleEqual2Zero, RuleSLess2Zero, RuleLessEqual2Zero, RuleLess2Zero, RuleBoolNegate, RuleCondNegate, RuleSwitchSingle, RuleEmbed, RuleHumptyOr, RuleDumptyHump, RuleHumptyDumpty, RuleShiftSub, RuleSubCancel, RuleSubZext, RuleConcatLeftShift, RuleConcatZero, RuleShiftAnd, RuleZextShiftZext, RuleZextCommute, RuleConcatZext, RuleConcatCommute, RuleSubCommute, RuleSubExtComm, RuleStoreVarnode, RuleLoadVarnode, RuleAddMultCollapse, RuleXorCollapse, RuleSub2Add, RuleCarryElim, Rule2Comp2Mult, RulePropagateCopy, RuleTransformCpool, RuleCollapseConstants, RuleShiftPiece, RuleShift2Mult, RuleIdentityEl, RuleTestSign, RuleSignShift, RuleTrivialShift, RuleSborrow, RuleMultiCollapse, RuleIndirectCollapse, RuleLogic2Bool, RuleBoolZext, RuleBooleanNegate, RuleBitUndistribute, RuleZextSless, RuleSlessToLess, RuleZextEliminate, RuleTrivialBool, RuleTrivialArith, RuleLessNotEqual, RuleLessEqual, RuleShiftCompare, RuleLeftRight, RuleConcatShift, RuleDoubleArithShift, RuleDoubleShift, RuleDoubleSub, RuleAndCompare, RuleAndPiece, RuleAndCommute, RuleFloatRange, RuleRangeMeld, RuleLessOne, RuleAndDistribute, RuleDoubleLoad, RuleHighOrderAnd, RuleDoubleIn, RuleNotDistribute, RulePushMulti, RulePullsubIndirect, RulePullsubMulti, RuleTermOrder, RuleEquality, RuleOrPredicate, RuleIntLessEqual, RuleRightShiftAnd, RuleShiftBitops, RuleNegateIdentity, RuleAndOrLump, RuleOrCollapse, RuleOrConsume, RuleAndMask, RuleGeneric, RuleOrMask, RuleBxor2NotEqual, RulePiece2Sext, RulePiece2Zext, RuleSelectCse, RuleCollectTerms, and RuleEarlyRemoval.

◆ checkActionBreak()

bool Rule::checkActionBreak ( void  )

Check if an action breakpoint is turned on.

This method is called every time the Rule successfully applies. If it returns true, this indicates to the system that an action breakpoint has occurred.

Returns
true if an action breakpoint should occur because of this Rule

◆ clone()

virtual Rule* Rule::clone ( const ActionGroupList grouplist) const
pure virtual

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

Implemented in RuleXorSwap, RulePiecePathology, RulePopcountBoolXor, RuleThreeWayCompare, RuleFuncPtrEncoding, RuleIgnoreNan, RuleFloatCast, RuleConditionalMove, RuleNegateNegate, RuleSubfloatConvert, RuleSubvarSext, RuleSubvarZext, RuleSubvarShift, RuleSubvarCompZero, RulePtrFlow, RuleSplitFlow, RuleSubvarSubpiece, RuleSubvarAnd, RuleSegment, RuleModOpt, RuleSignNearMult, RuleSignForm, RuleSignDiv2, RuleDivOpt, RuleDivTermAdd2, RuleDivTermAdd, RulePositiveDiv, RuleSubNormal, RulePtrsubCharConstant, RuleSubRight, Rule2Comp2Sub, RuleAddUnsigned, RuleMultNegOne, RulePtrsubUndo, RulePtraddUndo, RulePushPtr, RuleStructOffset0, RulePtrArith, RuleEqual2Constant, RuleEqual2Zero, RuleSLess2Zero, RuleLessEqual2Zero, RuleLess2Zero, RuleBoolNegate, RuleCondNegate, RuleSwitchSingle, RuleEmbed, RuleHumptyOr, RuleDumptyHump, RuleHumptyDumpty, RuleShiftSub, RuleSubCancel, RuleSubZext, RuleConcatLeftShift, RuleConcatZero, RuleShiftAnd, RuleZextShiftZext, RuleZextCommute, RuleConcatZext, RuleConcatCommute, RuleSubCommute, RuleSubExtComm, RuleStoreVarnode, RuleLoadVarnode, RuleAddMultCollapse, RuleXorCollapse, RuleSub2Add, RuleCarryElim, Rule2Comp2Mult, RulePropagateCopy, RuleTransformCpool, RuleCollapseConstants, RuleShiftPiece, RuleShift2Mult, RuleIdentityEl, RuleTestSign, RuleSignShift, RuleTrivialShift, RuleSborrow, RuleMultiCollapse, RuleIndirectCollapse, RuleLogic2Bool, RuleBoolZext, RuleBooleanNegate, RuleBitUndistribute, RuleZextSless, RuleSlessToLess, RuleZextEliminate, RuleTrivialBool, RuleTrivialArith, RuleLessNotEqual, RuleLessEqual, RuleShiftCompare, RuleLeftRight, RuleConcatShift, RuleDoubleArithShift, RuleDoubleShift, RuleDoubleSub, RuleAndCompare, RuleAndPiece, RuleAndCommute, RuleFloatRange, RuleRangeMeld, RuleLessOne, RuleAndDistribute, RuleDoubleLoad, RuleHighOrderAnd, RuleNotDistribute, RuleDoubleIn, RulePushMulti, RulePullsubIndirect, RulePullsubMulti, RuleTermOrder, RuleEquality, RuleOrPredicate, RuleIntLessEqual, RuleRightShiftAnd, RuleShiftBitops, RuleNegateIdentity, RuleAndOrLump, RuleOrCollapse, RuleOrConsume, RuleAndMask, RuleGeneric, RuleOrMask, RuleBxor2NotEqual, RulePiece2Sext, RulePiece2Zext, RuleSelectCse, RuleCollectTerms, and RuleEarlyRemoval.

◆ getOpList()

void Rule::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 in RuleXorSwap, RulePiecePathology, RulePopcountBoolXor, RuleThreeWayCompare, RuleFuncPtrEncoding, RuleIgnoreNan, RuleFloatCast, RuleConditionalMove, RuleNegateNegate, RuleSubfloatConvert, RuleSubvarSext, RuleSubvarZext, RuleSubvarShift, RuleSubvarCompZero, RulePtrFlow, RuleSplitFlow, RuleSubvarSubpiece, RuleSubvarAnd, RuleSegment, RuleModOpt, RuleSignNearMult, RuleSignForm, RuleSignDiv2, RuleDivOpt, RuleDivTermAdd2, RuleDivTermAdd, RulePositiveDiv, RuleSubNormal, RulePtrsubCharConstant, RuleSubRight, Rule2Comp2Sub, RuleAddUnsigned, RuleMultNegOne, RulePtrsubUndo, RulePtraddUndo, RulePushPtr, RuleStructOffset0, RulePtrArith, RuleEqual2Constant, RuleEqual2Zero, RuleSLess2Zero, RuleLessEqual2Zero, RuleLess2Zero, RuleBoolNegate, RuleCondNegate, RuleSwitchSingle, RuleEmbed, RuleHumptyOr, RuleDumptyHump, RuleHumptyDumpty, RuleShiftSub, RuleSubCancel, RuleSubZext, RuleConcatLeftShift, RuleConcatZero, RuleShiftAnd, RuleZextShiftZext, RuleZextCommute, RuleConcatZext, RuleConcatCommute, RuleSubCommute, RuleSubExtComm, RuleStoreVarnode, RuleLoadVarnode, RuleAddMultCollapse, RuleXorCollapse, RuleSub2Add, RuleCarryElim, Rule2Comp2Mult, RuleTransformCpool, RuleShiftPiece, RuleShift2Mult, RuleIdentityEl, RuleTestSign, RuleSignShift, RuleTrivialShift, RuleSborrow, RuleMultiCollapse, RuleIndirectCollapse, RuleLogic2Bool, RuleBoolZext, RuleBooleanNegate, RuleBitUndistribute, RuleZextSless, RuleSlessToLess, RuleZextEliminate, RuleTrivialBool, RuleTrivialArith, RuleLessNotEqual, RuleLessEqual, RuleShiftCompare, RuleLeftRight, RuleConcatShift, RuleDoubleArithShift, RuleDoubleShift, RuleDoubleSub, RuleAndCompare, RuleAndPiece, RuleAndCommute, RuleFloatRange, RuleRangeMeld, RuleLessOne, RuleAndDistribute, RuleDoubleLoad, RuleHighOrderAnd, RuleDoubleIn, RuleNotDistribute, RulePushMulti, RulePullsubIndirect, RulePullsubMulti, RuleTermOrder, RuleEquality, RuleOrPredicate, RuleIntLessEqual, RuleRightShiftAnd, RuleShiftBitops, RuleNegateIdentity, RuleAndOrLump, RuleOrCollapse, RuleOrConsume, RuleAndMask, RuleGeneric, RuleOrMask, RuleBxor2NotEqual, RulePiece2Sext, RulePiece2Zext, RuleSelectCse, and RuleCollectTerms.

◆ printStatistics()

void Rule::printStatistics ( ostream &  s) const
virtual

Print statistics for this Rule.

Print the accumulated counts associated with applying this Rule to stream. This method is intended for console mode debugging. Derived Rules may override this to display their own statistics.

Parameters
sis the output stream

◆ reset()

void Rule::reset ( Funcdata data)
virtual

Reset this Rule.

Any state that is specific to a particular function is cleared by this method. This method can be used to initialize a Rule based on a new function it will apply to

Parameters
datais the new function about to be transformed

Reimplemented in RuleSubvarSext, and RuleDoubleIn.

◆ resetStats()

void Rule::resetStats ( void  )
virtual

Reset Rule statistics.

Counts of when this Rule has been attempted/applied are reset to zero. Derived Rules may reset their own statistics.


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