decompiler
1.0.0
|
Dead code removal. Eliminate dead p-code ops. More...
#include <coreaction.hh>
Public Member Functions | |
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... | |
![]() | |
Action (uint4 f, const string &nm, const string &g) | |
Base constructor for an Action. More... | |
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... | |
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... | |
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... | |
Static Private Member Functions | |
static void | pushConsumed (uintb val, Varnode *vn, vector< Varnode * > &worklist) |
static void | propagateConsumed (vector< Varnode * > &worklist) |
Propagate the consumed value for one Varnode. More... | |
static bool | neverConsumed (Varnode *vn, Funcdata &data) |
Deal with unconsumed Varnodes. More... | |
static void | markConsumedParameters (FuncCallSpecs *fc, vector< Varnode * > &worklist) |
Determine how the given sub-function parameters are consumed. More... | |
static uintb | gatherConsumedReturn (Funcdata &data) |
Determine how the return values for the given function are consumed. More... | |
Additional Inherited Members | |
![]() | |
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... | |
![]() | |
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... | |
![]() | |
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. | |
Dead code removal. Eliminate dead p-code ops.
This is a very fine grained algorithm, it detects usage of individual bits within the Varnode, not just use of the Varnode itself. Each Varnode has a consumed word, which indicates if a bit in the Varnode is being used, and it has two flags layed out as follows:
The algorithm works by back propagating the consumed value up from the output of the op to its inputs, starting with a set of seed Varnodes which are marked as completely used (function inputs, branch conditions, ...) For each propagation the particular op being passed through can transform the "bit usage" vector of the output to obtain the input.
|
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 Action.
References Funcdata::beginLoc(), Funcdata::beginOpAlive(), Funcdata::clearDeadVarnodes(), CPUI_BRANCHIND, CPUI_CALLOTHER, CPUI_RETURN, Funcdata::deadRemovalAllowed(), AddrSpace::doesDeadcode(), Funcdata::endLoc(), Funcdata::endOpAlive(), Funcdata::findJumpTable(), Funcdata::getCallSpecs(), AddrSpaceManager::getSpace(), AddrSpaceManager::numSpaces(), Funcdata::opDestroy(), Funcdata::opUnsetOutput(), and Funcdata::seenDeadcode().
|
inlinevirtual |
|
staticprivate |
Determine how the return values for the given function are consumed.
Examine each CPUI_RETURN to see how the Varnode input is consumed. If the function's prototype is locked, assume the Varnode is entirely consumed. If there are no CPUI_RETURN ops, return 0
data | is the given function |
References Funcdata::beginOp(), calc_mask(), CPUI_RETURN, Funcdata::endOp(), and minimalmask().
|
staticprivate |
Determine how the given sub-function parameters are consumed.
Set the consume property for each input Varnode of a CPUI_CALL or CPUI_CALLIND. If the prototype is locked, assume parameters are entirely consumed.
fc | is the call specification for the given sub-function |
worklist | will hold input Varnodes that can propagate their consume property |
References calc_mask(), FuncCallSpecs::getInputBytesConsumed(), FuncProto::isInputLocked(), and minimalmask().
Deal with unconsumed Varnodes.
For a Varnode, none of whose bits are consumed, eliminate the PcodeOp defining it and replace Varnode inputs to ops that officially read it with zero constants.
vn | is the Varnode |
data | is the function being analyzed |
References PcodeOp::getSlot(), Funcdata::newConstant(), Funcdata::opDestroy(), Funcdata::opSetInput(), and Funcdata::opUnsetOutput().
|
staticprivate |
Propagate the consumed value for one Varnode.
The Varnode at the top of the stack is popped off, and its current consumed value is propagated backward to the inputs of the op that produced it.
worklist | is the current stack of dirty Varnodes |
References calc_mask(), coveringmask(), CPUI_CALL, CPUI_CALLIND, CPUI_COPY, CPUI_EXTRACT, CPUI_INDIRECT, CPUI_INSERT, CPUI_INT_ADD, CPUI_INT_AND, CPUI_INT_EQUAL, CPUI_INT_LEFT, CPUI_INT_LESS, CPUI_INT_LESSEQUAL, CPUI_INT_MULT, CPUI_INT_NEGATE, CPUI_INT_NOTEQUAL, CPUI_INT_OR, CPUI_INT_RIGHT, CPUI_INT_SEXT, CPUI_INT_SUB, CPUI_INT_XOR, CPUI_INT_ZEXT, CPUI_MULTIEQUAL, CPUI_PIECE, CPUI_POPCOUNT, CPUI_SUBPIECE, PcodeOp::getOpFromConst(), IPTR_IOP, and leastsigbit_set().
|
inlinestaticprivate |
Given a new consume value to push to a Varnode, determine if this changes the Varnodes consume value and whether to push the Varnode onto the work-list.
val | is the new consume value |
vn | is the Varnode to push to |
worklist | is the current work-list |
References calc_mask().