decompiler
1.0.0
|
Propagate conditional constants. More...
#include <coreaction.hh>
Public Member Functions | |
ActionConditionalConst (const string &g) | |
Constructor. | |
virtual Action * | clone (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 Action * | getSubAction (const string &specify) |
Retrieve a specific sub-action by name. More... | |
virtual Rule * | getSubRule (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 Varnode * | placeCopy (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. | |
Propagate conditional constants.
|
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.
data | is the function to inspect/modify |
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().
|
staticprivate |
Clear all marks on the given list of PcodeOps.
opList | is the given list |
|
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.
grouplist | is the list of groups being cloned |
Implements ghidra::Action.
References ghidra::ActionStart::apply(), ghidra::ActionGroupList::contains(), and ghidra::Action::getGroup().
|
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
vn | is the given Varnode |
phiNodeEdges | is the list of edges to excise |
reachable | will 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.
|
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.
op | is the given PcodeOp |
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().
|
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.
edges | is the set of edges |
i | is the index of the specific edge to test |
result | is the array of marks to be returned |
|
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.
varVn | is the given Varnode |
constVn | is the constant to replace it with |
phiNodeEdges | is the set of edges the Varnode is known to be constant on |
data | is the function containing this data-flow |
References ghidra::FlowBlock::getIn(), ghidra::PcodeOp::getParent(), and ghidra::Funcdata::opSetInput().
|
staticprivate |
Place a COPY of a constant at the end of a basic block.
op | is an alternate "last" op |
bl | is the basic block |
constVn | is the constant to be assigned |
data | is the function containing the block |
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().
|
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.
phiNodeEdges | is the list of MULTIEQUALs and their incoming edges |
marks | are the marks applied to the MULTIEQUALs (2 == flowtogether) |
constVn | is the constant being assigned by the COPY |
data | is the function |
References ghidra::FlowBlock::findCommonBlock(), ghidra::FlowBlock::getIn(), ghidra::PcodeOp::getParent(), and ghidra::Funcdata::opSetInput().
|
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.
varVn | is the given Varnode |
constVn | is the constant Varnode to replace with |
constBlock | is the block which dominates ops reading the constant value |
useMultiequal | is true if conditional constants can be applied to MULTIEQUAL ops |
data | is 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().