decompiler  1.0.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ghidra::Action Class Referenceabstract

Large scale transformations applied to the varnode/op graph. More...

#include <action.hh>

Inheritance diagram for ghidra::Action:
ghidra::ActionActiveParam ghidra::ActionActiveReturn ghidra::ActionAssignHigh ghidra::ActionBlockStructure ghidra::ActionConditionalConst ghidra::ActionConditionalExe ghidra::ActionConstantPtr ghidra::ActionConstbase ghidra::ActionCopyMarker ghidra::ActionDeadCode ghidra::ActionDefaultParams ghidra::ActionDeindirect ghidra::ActionDeterminedBranch ghidra::ActionDirectWrite ghidra::ActionDominantCopy ghidra::ActionDoNothing ghidra::ActionDynamicMapping ghidra::ActionDynamicSymbols ghidra::ActionExtraPopSetup ghidra::ActionFinalStructure ghidra::ActionForceGoto ghidra::ActionFuncLink ghidra::ActionFuncLinkOutOnly ghidra::ActionGroup ghidra::ActionHeritage ghidra::ActionHideShadow ghidra::ActionInferTypes ghidra::ActionInputPrototype ghidra::ActionLaneDivide ghidra::ActionLikelyTrash ghidra::ActionMapGlobals ghidra::ActionMarkExplicit ghidra::ActionMarkImplied ghidra::ActionMarkIndirectOnly ghidra::ActionMergeAdjacent ghidra::ActionMergeCopy ghidra::ActionMergeMultiEntry ghidra::ActionMergeRequired ghidra::ActionMergeType ghidra::ActionMultiCse ghidra::ActionNameVars ghidra::ActionNodeJoin ghidra::ActionNonzeroMask ghidra::ActionNormalizeBranches ghidra::ActionNormalizeSetup ghidra::ActionOutputPrototype ghidra::ActionParamDouble ghidra::ActionPool ghidra::ActionPreferComplement ghidra::ActionPrototypeTypes ghidra::ActionPrototypeWarnings ghidra::ActionRedundBranch ghidra::ActionRestrictLocal ghidra::ActionRestructureHigh ghidra::ActionRestructureVarnode ghidra::ActionReturnRecovery ghidra::ActionReturnSplit ghidra::ActionSegmentize ghidra::ActionSetCasts ghidra::ActionShadowVar ghidra::ActionSpacebase ghidra::ActionStackPtrFlow ghidra::ActionStart ghidra::ActionStartCleanUp ghidra::ActionStartTypes ghidra::ActionStop ghidra::ActionStructureTransform ghidra::ActionSwitchNorm ghidra::ActionUnjustifiedParams ghidra::ActionUnreachable ghidra::ActionVarnodeProps

Public Types

enum  ruleflags {
  rule_repeatapply = 4, rule_onceperfunc = 8, rule_oneactperfunc = 16, rule_debug = 32,
  rule_warnings_on = 64, rule_warnings_given = 128
}
 Boolean behavior properties governing this particular Action. More...
 
enum  statusflags {
  status_start =1, status_breakstarthit =2, status_repeat =4, status_mid =8,
  status_end =16, status_actionbreak =32
}
 Boolean properties describing the status of an action. More...
 
enum  breakflags { break_start = 1, tmpbreak_start = 2, break_action = 4, tmpbreak_action = 8 }
 Break points associated with an Action. More...
 

Public Member Functions

 Action (uint4 f, const string &nm, const string &g)
 Base constructor for an Action. More...
 
virtual ~Action (void)
 Destructor.
 
virtual void printStatistics (ostream &s) const
 Dump statistics to stream. More...
 
int4 perform (Funcdata &data)
 Perform this action (if necessary) More...
 
bool setBreakPoint (uint4 tp, const string &specify)
 Set a breakpoint on this action. More...
 
virtual void clearBreakPoints (void)
 Clear all breakpoints set on this Action.
 
bool setWarning (bool val, const string &specify)
 Set a warning on this action. More...
 
bool disableRule (const string &specify)
 Disable a specific Rule within this. More...
 
bool enableRule (const string &specify)
 Enable a specific Rule within this. More...
 
const string & getName (void) const
 Get the Action's name.
 
const string & getGroup (void) const
 Get the Action's group.
 
uint4 getStatus (void) const
 Get the current status of this Action.
 
uint4 getNumTests (void)
 Get the number of times apply() was invoked.
 
uint4 getNumApply (void)
 
virtual Actionclone (const ActionGroupList &grouplist) const =0
 Clone the Action. More...
 
virtual void reset (Funcdata &data)
 Reset the Action for a new function. More...
 
virtual void resetStats (void)
 Reset all the counts to zero. More...
 
virtual int4 apply (Funcdata &data)=0
 Make a single attempt to apply this Action. More...
 
virtual int4 print (ostream &s, int4 num, int4 depth) const
 Print a description of this Action to stream. More...
 
virtual void printState (ostream &s) const
 Print status to stream. More...
 
virtual ActiongetSubAction (const string &specify)
 Retrieve a specific sub-action by name. More...
 
virtual RulegetSubRule (const string &specify)
 Retrieve a specific sub-rule by name. More...
 

Protected Member Functions

void issueWarning (Architecture *glb)
 Warn that this Action has applied. More...
 
bool checkStartBreak (void)
 Check start breakpoint. More...
 
bool checkActionBreak (void)
 Check action breakpoint. More...
 
void turnOnWarnings (void)
 Enable warnings for this Action.
 
void turnOffWarnings (void)
 Disable warnings for this Action.
 

Protected Attributes

int4 lcount
 Changes not including last call to apply()
 
int4 count
 Number of changes made by this action so far.
 
uint4 status
 Current status.
 
uint4 breakpoint
 Breakpoint properties.
 
uint4 flags
 Behavior properties.
 
uint4 count_tests
 Number of times apply() has been called.
 
uint4 count_apply
 Number of times apply() made changes.
 
string name
 Name of the action.
 
string basegroup
 Base group this action belongs to.
 

Detailed Description

Large scale transformations applied to the varnode/op graph.

The base for objects that make changes to the syntax tree of a Funcdata The action is invoked through the apply(Funcdata &data) method. This base class keeps track of basic statistics about how the action is being applied. Derived classes indicate that a change has been applied by incrementing the count field. With OPACTION_DEBUG macro defined, actions support a break point debugging in console mode.

Member Enumeration Documentation

◆ breakflags

Break points associated with an Action.

Enumerator
break_start 

Break at beginning of action.

tmpbreak_start 

Temporary break at start of action.

break_action 

Break if a change has been made.

◆ ruleflags

Boolean behavior properties governing this particular Action.

Enumerator
rule_repeatapply 

Apply rule repeatedly until no change.

rule_onceperfunc 

Apply rule once per function.

rule_oneactperfunc 

Makes a change only once per function.

rule_debug 

Print debug messages specifically for this action.

rule_warnings_on 

If this action makes a change, issue a warning.

rule_warnings_given 

A warning has been issued for this action.

◆ statusflags

Boolean properties describing the status of an action.

Enumerator
status_start 

At start of action.

status_breakstarthit 

At start after breakpoint.

status_repeat 

Repeating the same action.

status_mid 

In middle of action (use subclass status)

status_end 

getFuncdata has completed once (for onceperfunc)

status_actionbreak 

Completed full action last time but indicated action break.

Constructor & Destructor Documentation

◆ Action()

ghidra::Action::Action ( uint4  f,
const string &  nm,
const string &  g 
)

Base constructor for an Action.

Specify the name, group, and properties of the Action

Parameters
fis the collection of property flags
nmis the Action name
gis the Action group

References basegroup, breakpoint, count_apply, count_tests, flags, name, status, and status_start.

Member Function Documentation

◆ apply()

virtual int4 ghidra::Action::apply ( Funcdata data)
pure virtual

Make a single attempt to apply this Action.

This is the main entry point for applying changes to a function that are specific to this Action. The method can inspect whatever it wants to decide if the Action does or does not apply. Changes are indicated by incrementing the count field.

Parameters
datais the function to inspect/modify
Returns
0 for a complete application, -1 for a partial completion (due to breakpoint)

Implemented in ghidra::ActionPrototypeWarnings, ghidra::ActionDynamicSymbols, ghidra::ActionDynamicMapping, ghidra::ActionCopyMarker, ghidra::ActionDominantCopy, ghidra::ActionHideShadow, ghidra::ActionInferTypes, ghidra::ActionUnjustifiedParams, ghidra::ActionOutputPrototype, ghidra::ActionInputPrototype, ghidra::ActionMapGlobals, ghidra::ActionRestructureHigh, ghidra::ActionRestructureVarnode, ghidra::ActionLikelyTrash, ghidra::ActionRestrictLocal, ghidra::ActionReturnRecovery, ghidra::ActionActiveReturn, ghidra::ActionActiveParam, ghidra::ActionParamDouble, ghidra::ActionFuncLinkOutOnly, ghidra::ActionFuncLink, ghidra::ActionExtraPopSetup, ghidra::ActionDefaultParams, ghidra::ActionPrototypeTypes, ghidra::ActionNormalizeSetup, ghidra::ActionSwitchNorm, ghidra::ActionConditionalConst, ghidra::ActionDeadCode, ghidra::ActionDeterminedBranch, ghidra::ActionRedundBranch, ghidra::ActionDoNothing, ghidra::ActionUnreachable, ghidra::ActionNameVars, ghidra::ActionMarkImplied, ghidra::ActionMarkExplicit, ghidra::ActionMergeType, ghidra::ActionMergeMultiEntry, ghidra::ActionMergeCopy, ghidra::ActionMergeAdjacent, ghidra::ActionMergeRequired, ghidra::ActionNodeJoin, ghidra::ActionMarkIndirectOnly, ghidra::ActionReturnSplit, ghidra::ActionAssignHigh, ghidra::ActionSetCasts, ghidra::ActionFinalStructure, ghidra::ActionBlockStructure, ghidra::ActionPreferComplement, ghidra::ActionNonzeroMask, ghidra::ActionNormalizeBranches, ghidra::ActionHeritage, ghidra::ActionStructureTransform, ghidra::ActionPool, ghidra::ActionSpacebase, ghidra::ActionConstbase, ghidra::ActionDirectWrite, ghidra::ActionVarnodeProps, ghidra::ActionDeindirect, ghidra::ActionConstantPtr, ghidra::ActionShadowVar, ghidra::ActionRestartGroup, ghidra::ActionConditionalExe, ghidra::ActionMultiCse, ghidra::ActionGroup, ghidra::ActionForceGoto, ghidra::ActionSegmentize, ghidra::ActionLaneDivide, ghidra::ActionStackPtrFlow, ghidra::ActionStartTypes, ghidra::ActionStartCleanUp, ghidra::ActionStop, and ghidra::ActionStart.

Referenced by perform().

◆ checkActionBreak()

bool ghidra::Action::checkActionBreak ( void  )
protected

Check action breakpoint.

Check if there was an active action breakpoint on this Action

Returns
true if there was an action breakpoint

References break_action, and breakpoint.

Referenced by ghidra::ActionGroup::apply(), and perform().

◆ checkStartBreak()

bool ghidra::Action::checkStartBreak ( void  )
protected

Check start breakpoint.

Check if there was an active start break point on this action

Returns
true if there was a start breakpoint

References break_start, breakpoint, flags, name, rule_debug, and tmpbreak_start.

Referenced by perform().

◆ clone()

virtual Action* ghidra::Action::clone ( const ActionGroupList grouplist) const
pure virtual

Clone the Action.

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

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

Implemented in ghidra::ActionPrototypeWarnings, ghidra::ActionDynamicSymbols, ghidra::ActionDynamicMapping, ghidra::ActionCopyMarker, ghidra::ActionDominantCopy, ghidra::ActionHideShadow, ghidra::ActionInferTypes, ghidra::ActionUnjustifiedParams, ghidra::ActionOutputPrototype, ghidra::ActionInputPrototype, ghidra::ActionMapGlobals, ghidra::ActionRestructureHigh, ghidra::ActionRestructureVarnode, ghidra::ActionLikelyTrash, ghidra::ActionRestrictLocal, ghidra::ActionReturnRecovery, ghidra::ActionActiveReturn, ghidra::ActionActiveParam, ghidra::ActionParamDouble, ghidra::ActionFuncLinkOutOnly, ghidra::ActionFuncLink, ghidra::ActionExtraPopSetup, ghidra::ActionDefaultParams, ghidra::ActionPrototypeTypes, ghidra::ActionNormalizeSetup, ghidra::ActionSwitchNorm, ghidra::ActionConditionalConst, ghidra::ActionDeadCode, ghidra::ActionDeterminedBranch, ghidra::ActionRedundBranch, ghidra::ActionDoNothing, ghidra::ActionUnreachable, ghidra::ActionNameVars, ghidra::ActionMarkImplied, ghidra::ActionMarkExplicit, ghidra::ActionMergeType, ghidra::ActionMergeMultiEntry, ghidra::ActionMergeCopy, ghidra::ActionMergeAdjacent, ghidra::ActionMergeRequired, ghidra::ActionNodeJoin, ghidra::ActionMarkIndirectOnly, ghidra::ActionReturnSplit, ghidra::ActionAssignHigh, ghidra::ActionSetCasts, ghidra::ActionFinalStructure, ghidra::ActionBlockStructure, ghidra::ActionPreferComplement, ghidra::ActionNonzeroMask, ghidra::ActionNormalizeBranches, ghidra::ActionHeritage, ghidra::ActionPool, ghidra::ActionStructureTransform, ghidra::ActionSpacebase, ghidra::ActionConstbase, ghidra::ActionDirectWrite, ghidra::ActionVarnodeProps, ghidra::ActionDeindirect, ghidra::ActionConstantPtr, ghidra::ActionShadowVar, ghidra::ActionRestartGroup, ghidra::ActionConditionalExe, ghidra::ActionMultiCse, ghidra::ActionGroup, ghidra::ActionForceGoto, ghidra::ActionSegmentize, ghidra::ActionLaneDivide, ghidra::ActionStackPtrFlow, ghidra::ActionStartTypes, ghidra::ActionStartCleanUp, ghidra::ActionStop, and ghidra::ActionStart.

Referenced by ghidra::ActionGroup::clone(), ghidra::ActionRestartGroup::clone(), ghidra::ActionDatabase::deriveAction(), and ghidra::ActionDatabase::toggleAction().

◆ disableRule()

bool ghidra::Action::disableRule ( const string &  specify)

Disable a specific Rule within this.

An individual Rule can be disabled by name, within this Action. It must be specified by a ':' separated name path, from the root Action down to the specific Rule.

Parameters
specifyis the name path
Returns
true if the Rule is successfully disabled

References getSubRule(), and ghidra::Rule::setDisable().

Referenced by ghidra::OptionToggleRule::apply().

◆ enableRule()

bool ghidra::Action::enableRule ( const string &  specify)

Enable a specific Rule within this.

An individual Rule can be enabled by name, within this Action. It must be specified by a ':' separated name path, from the root Action down to the specific Rule.

Parameters
specifyis the name path
Returns
true if the Rule is successfully enabled

References ghidra::Rule::clearDisable(), and getSubRule().

Referenced by ghidra::OptionToggleRule::apply().

◆ getNumApply()

uint4 ghidra::Action::getNumApply ( void  )
inline

Get the number of times apply() made changes

◆ getSubAction()

Action * ghidra::Action::getSubAction ( const string &  specify)
virtual

Retrieve a specific sub-action by name.

If this Action matches the given name, it is returned. If the name matches a sub-action, this is returned.

Parameters
specifyis the action name to match
Returns
the matching Action or sub-action

Reimplemented in ghidra::ActionGroup.

References name.

Referenced by ghidra::ActionGroup::getSubAction(), setBreakPoint(), and setWarning().

◆ getSubRule()

Rule * ghidra::Action::getSubRule ( const string &  specify)
virtual

Retrieve a specific sub-rule by name.

Find a Rule, as a component of this Action, with the given name.

Parameters
specifyis the name of the rule
Returns
the matching sub-rule

Reimplemented in ghidra::ActionPool, and ghidra::ActionGroup.

Referenced by disableRule(), enableRule(), setBreakPoint(), and setWarning().

◆ issueWarning()

void ghidra::Action::issueWarning ( Architecture glb)
protected

Warn that this Action has applied.

If enabled, issue a warning that this Action has been applied

Parameters
glbis the controlling Architecture

References flags, name, ghidra::Architecture::printMessage(), rule_warnings_given, and rule_warnings_on.

Referenced by perform().

◆ perform()

int4 ghidra::Action::perform ( Funcdata data)

Perform this action (if necessary)

Run this Action until completion or a breakpoint occurs. Depending on the behavior properties of this instance, the apply() method may get called many times or none. Generally the number of changes made by the action is returned, but if a breakpoint occurs -1 is returned. A successive call to perform() will "continue" from the break point.

Parameters
datais the function being acted on
Returns
the number of changes or -1

References apply(), checkActionBreak(), checkStartBreak(), count, count_apply, count_tests, flags, ghidra::Funcdata::getArch(), getName(), issueWarning(), lcount, rule_onceperfunc, rule_oneactperfunc, rule_repeatapply, status, status_actionbreak, status_breakstarthit, status_end, status_mid, status_repeat, and status_start.

Referenced by ghidra::IfcExecuteTestCommand::execute(), and ghidra::Funcdata::stageJumpTable().

◆ print()

int4 ghidra::Action::print ( ostream &  s,
int4  num,
int4  depth 
) const
virtual

Print a description of this Action to stream.

The description is suitable for a console mode listing of actions

Parameters
sis the output stream
numis a starting index to associate with the action (and its sub-actions)
depthis amount of indent necessary before printing
Returns
the next available index

Reimplemented in ghidra::ActionPool, and ghidra::ActionGroup.

References break_action, break_start, breakpoint, flags, name, rule_onceperfunc, rule_repeatapply, and tmpbreak_start.

Referenced by ghidra::ActionGroup::print(), and ghidra::ActionPool::print().

◆ printState()

void ghidra::Action::printState ( ostream &  s) const
virtual

Print status to stream.

This will the Action name and the next step to execute

Parameters
sis the output stream

Reimplemented in ghidra::ActionPool, and ghidra::ActionGroup.

References name, status, status_breakstarthit, status_end, status_mid, status_repeat, and status_start.

Referenced by ghidra::ActionGroup::printState(), and ghidra::ActionPool::printState().

◆ printStatistics()

void ghidra::Action::printStatistics ( ostream &  s) const
virtual

Dump statistics to stream.

Print out the collected statistics for the Action to stream

Parameters
sis the output stream

Reimplemented in ghidra::ActionPool, and ghidra::ActionGroup.

References count_apply, count_tests, and name.

Referenced by ghidra::ActionGroup::printStatistics(), and ghidra::ActionPool::printStatistics().

◆ reset()

void ghidra::Action::reset ( Funcdata data)
virtual

◆ resetStats()

void ghidra::Action::resetStats ( void  )
virtual

Reset all the counts to zero.

Reset the statistics

Reimplemented in ghidra::ActionPool, and ghidra::ActionGroup.

References count_apply, and count_tests.

Referenced by ghidra::ActionGroup::resetStats(), and ghidra::ActionPool::resetStats().

◆ setBreakPoint()

bool ghidra::Action::setBreakPoint ( uint4  tp,
const string &  specify 
)

Set a breakpoint on this action.

A breakpoint can be placed on this Action or some sub-action by properly specifying the (sub)action name.

Parameters
tpis the type of breakpoint (break_start, break_action, etc.)
specifyis the (possibly sub)action to apply the break point to
Returns
true if a breakpoint was successfully set

References breakpoint, getSubAction(), getSubRule(), and ghidra::Rule::setBreak().

Referenced by ghidra::IfcExecuteTestCommand::execute().

◆ setWarning()

bool ghidra::Action::setWarning ( bool  val,
const string &  specify 
)

Set a warning on this action.

If enabled, a warning will be printed whenever this action applies. The warning can be toggled for this Action or some sub-action by specifying its name.

Parameters
valis the toggle value for the warning
specifyis the name of the action or sub-action to toggle
Returns
true if the warning was successfully toggled

References getSubAction(), getSubRule(), turnOffWarnings(), ghidra::Rule::turnOffWarnings(), turnOnWarnings(), and ghidra::Rule::turnOnWarnings().

Referenced by ghidra::OptionWarning::apply().


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