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

Propagate conditional constants. More...

#include <coreaction.hh>

Inheritance diagram for ghidra::ActionConditionalConst:
ghidra::Action

Public Member Functions

 ActionConditionalConst (const string &g)
 Constructor.
 
virtual Actionclone (const ActionGroupList &grouplist) const
 Clone the Action. More...
 
virtual int4 apply (Funcdata &data)
 Make a single attempt to apply this Action. More...
 
- Public Member Functions inherited from ghidra::Action
 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 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 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...
 

Private Member Functions

void handlePhiNodes (Varnode *varVn, Varnode *constVn, vector< PcodeOpNode > &phiNodeEdges, Funcdata &data)
 Replace MULTIEQUAL edges with constant if there is no alternate flow. More...
 
void propagateConstant (Varnode *varVn, Varnode *constVn, FlowBlock *constBlock, bool useMultiequal, Funcdata &data)
 Replace reads of a given Varnode with a constant. More...
 

Static Private Member Functions

static void clearMarks (const vector< PcodeOp *> &opList)
 Clear all marks on the given list of PcodeOps. More...
 
static void collectReachable (Varnode *vn, vector< PcodeOpNode > &phiNodeEdges, vector< PcodeOp *> &reachable)
 Collect COPY, INDIRECT, and MULTIEQUAL ops reachable from the given Varnode, without going thru excised edges. More...
 
static bool flowToAlternatePath (PcodeOp *op)
 Does the output of the given op reunite with the alternate flow. More...
 
static bool flowTogether (const vector< PcodeOpNode > &edges, int4 i, vector< int4 > &result)
 Test if flow from a specific edge is disjoint from other edges. More...
 
static VarnodeplaceCopy (PcodeOp *op, BlockBasic *bl, Varnode *constVn, Funcdata &data)
 Place a COPY of a constant at the end of a basic block. More...
 
static void placeMultipleConstants (vector< PcodeOpNode > &phiNodeEdges, vector< int4 > &marks, Varnode *constVn, Funcdata &data)
 Place a single COPY assignment shared by multiple MULTIEQUALs. More...
 

Additional Inherited Members

- Public Types inherited from ghidra::Action
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...
 
- Protected Member Functions inherited from ghidra::Action
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 inherited from ghidra::Action
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

Propagate conditional constants.

Member Function Documentation

◆ apply()

int4 ghidra::ActionConditionalConst::apply ( Funcdata data)
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)

Implements ghidra::Action.

References ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_CBRANCH, ghidra::CPUI_INT_EQUAL, ghidra::CPUI_INT_NOTEQUAL, ghidra::Funcdata::getArch(), ghidra::Funcdata::getBasicBlocks(), ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::FlowBlock::getOut(), ghidra::AddrSpaceManager::getStackSpace(), ghidra::PcodeOp::isBooleanFlip(), ghidra::Varnode::isConstant(), ghidra::Varnode::isWritten(), ghidra::FlowBlock::lastOp(), ghidra::Funcdata::numHeritagePasses(), and ghidra::FlowBlock::restrictedByConditional().

◆ clearMarks()

void ghidra::ActionConditionalConst::clearMarks ( const vector< PcodeOp *> &  opList)
staticprivate

Clear all marks on the given list of PcodeOps.

Parameters
opListis the given list

◆ clone()

virtual Action* ghidra::ActionConditionalConst::clone ( const ActionGroupList grouplist) const
inlinevirtual

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

Implements ghidra::Action.

References ghidra::ActionStart::apply(), ghidra::ActionGroupList::contains(), and ghidra::Action::getGroup().

◆ collectReachable()

void ghidra::ActionConditionalConst::collectReachable ( Varnode vn,
vector< PcodeOpNode > &  phiNodeEdges,
vector< PcodeOp *> &  reachable 
)
staticprivate

Collect COPY, INDIRECT, and MULTIEQUAL ops reachable from the given Varnode, without going thru excised edges.

If data-flow from the Varnode does not go through excised edges and reaches the op via other MULTIEQUALs, INDIRECTs, and COPYs, the op is put in a list, and its mark is set

Parameters
vnis the given Varnode
phiNodeEdgesis the list of edges to excise
reachablewill hold the list ops that have been reached

References ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INDIRECT, ghidra::CPUI_MULTIEQUAL, ghidra::Varnode::endDescend(), ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::isMark(), ghidra::Varnode::isWritten(), ghidra::PcodeOp::numInput(), ghidra::PcodeOp::setMark(), and ghidra::PcodeOpNode::slot.

◆ flowToAlternatePath()

bool ghidra::ActionConditionalConst::flowToAlternatePath ( PcodeOp op)
staticprivate

Does the output of the given op reunite with the alternate flow.

Assuming alternate flows have been marked, follow the flow of the given op forward through MULTIEQUAL, INDIRECT, and COPY ops. If it hits the alternate flow, return true.

Parameters
opis the given PcodeOp
Returns
true is there is an alternate path

References ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INDIRECT, ghidra::CPUI_MULTIEQUAL, ghidra::Varnode::endDescend(), ghidra::PcodeOp::getOut(), ghidra::PcodeOp::isMark(), ghidra::Varnode::isMark(), and ghidra::Varnode::setMark().

◆ flowTogether()

bool ghidra::ActionConditionalConst::flowTogether ( const vector< PcodeOpNode > &  edges,
int4  i,
vector< int4 > &  result 
)
staticprivate

Test if flow from a specific edge is disjoint from other edges.

All MULTIEQUAL and COPY ops reachable from the edge are marked. If any other edge is in this marked set, mark both edges in the result set.

Parameters
edgesis the set of edges
iis the index of the specific edge to test
resultis the array of marks to be returned
Returns
true if the selected edge flows together with any other edge

◆ handlePhiNodes()

void ghidra::ActionConditionalConst::handlePhiNodes ( Varnode varVn,
Varnode constVn,
vector< PcodeOpNode > &  phiNodeEdges,
Funcdata data 
)
private

Replace MULTIEQUAL edges with constant if there is no alternate flow.

A given Varnode is known to be constant along a set of MULTIEQUAL edges. If these edges are excised from the data-flow, and the output of a MULTIEQUAL does not rejoin with the Varnode along an alternate path, then that edge is replaced with a constant.

Parameters
varVnis the given Varnode
constVnis the constant to replace it with
phiNodeEdgesis the set of edges the Varnode is known to be constant on
datais the function containing this data-flow

References ghidra::FlowBlock::getIn(), ghidra::PcodeOp::getParent(), and ghidra::Funcdata::opSetInput().

◆ placeCopy()

Varnode * ghidra::ActionConditionalConst::placeCopy ( PcodeOp op,
BlockBasic bl,
Varnode constVn,
Funcdata data 
)
staticprivate

Place a COPY of a constant at the end of a basic block.

Parameters
opis an alternate "last" op
blis the basic block
constVnis the constant to be assigned
datais the function containing the block
Returns
the new output Varnode of the COPY

References ghidra::CPUI_COPY, ghidra::BlockBasic::endOp(), ghidra::PcodeOp::getAddr(), ghidra::PcodeOp::getBasicIter(), ghidra::Varnode::getSize(), ghidra::PcodeOp::isBranch(), ghidra::BlockBasic::lastOp(), ghidra::Funcdata::newOp(), ghidra::Funcdata::newUniqueOut(), ghidra::Funcdata::opInsert(), ghidra::Funcdata::opSetInput(), and ghidra::Funcdata::opSetOpcode().

◆ placeMultipleConstants()

void ghidra::ActionConditionalConst::placeMultipleConstants ( vector< PcodeOpNode > &  phiNodeEdges,
vector< int4 > &  marks,
Varnode constVn,
Funcdata data 
)
staticprivate

Place a single COPY assignment shared by multiple MULTIEQUALs.

Find the common ancestor block among all MULTIEQUALs marked as flowing together. Place a COPY assigning a constant at the bottom of this block. Replace all the input edge Varnodes on the MULTIEQUALs with the output of this COPY.

Parameters
phiNodeEdgesis the list of MULTIEQUALs and their incoming edges
marksare the marks applied to the MULTIEQUALs (2 == flowtogether)
constVnis the constant being assigned by the COPY
datais the function

References ghidra::FlowBlock::findCommonBlock(), ghidra::FlowBlock::getIn(), ghidra::PcodeOp::getParent(), and ghidra::Funcdata::opSetInput().

◆ propagateConstant()

void ghidra::ActionConditionalConst::propagateConstant ( Varnode varVn,
Varnode constVn,
FlowBlock constBlock,
bool  useMultiequal,
Funcdata data 
)
private

Replace reads of a given Varnode with a constant.

For each read op, check that is in or dominated by a specific block we known the Varnode is constant in.

Parameters
varVnis the given Varnode
constVnis the constant Varnode to replace with
constBlockis the block which dominates ops reading the constant value
useMultiequalis true if conditional constants can be applied to MULTIEQUAL ops
datais the function being analyzed

References ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INDIRECT, ghidra::CPUI_MULTIEQUAL, ghidra::FlowBlock::dominates(), ghidra::Varnode::endDescend(), ghidra::Varnode::getAddr(), ghidra::PcodeOp::getIn(), ghidra::FlowBlock::getIn(), ghidra::PcodeOp::getOut(), ghidra::PcodeOp::getParent(), ghidra::PcodeOp::getSlot(), ghidra::Varnode::isAddrTied(), ghidra::PcodeOp::isMarker(), ghidra::Varnode::loneDescend(), ghidra::PcodeOp::numInput(), and ghidra::Funcdata::opSetInput().


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