decompiler  1.0.0
Classes | Public Member Functions | Static Private Member Functions | List of all members
ActionMarkExplicit Class Reference

Find explicit Varnodes: Varnodes that have an explicit token representing them in the output. More...

#include <coreaction.hh>

Inheritance diagram for ActionMarkExplicit:
Action

Classes

struct  OpStackElement
 This class holds a single entry in a stack used to traverse Varnode expressions. More...
 

Public Member Functions

 ActionMarkExplicit (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 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 void saveXml (ostream &s) const
 Save specifics of this action to stream.
 
virtual void restoreXml (const Element *el, Funcdata *fd)
 Load specifics of action from XML.
 
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...
 

Static Private Member Functions

static int4 baseExplicit (Varnode *vn, int4 maxref)
 Make initial determination if a Varnode should be explicit. More...
 
static int4 multipleInteraction (vector< Varnode * > &multlist)
 Find multiple descendant chains. More...
 
static void processMultiplier (Varnode *vn, int4 max)
 For a given multi-descendant Varnode, decide if it should be explicit. More...
 
static void checkNewToConstructor (Funcdata &data, Varnode *vn)
 Set special properties on output of CPUI_NEW. More...
 

Additional Inherited Members

- Public Types inherited from 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 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 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

Find explicit Varnodes: Varnodes that have an explicit token representing them in the output.

In the final output of the syntax tree as source code, all variables are characterized as either

This Action does preliminary scanning of Varnodes to determine which should be explicit in the final output. Basically, if there is symbol information associated, the possibility of aliasing, or if there are too many reads of a Varnode, it should be considered explicit.

Member Function Documentation

int4 ActionMarkExplicit::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 Action.

References Funcdata::beginDef(), Funcdata::getArch(), Varnode::isMark(), Architecture::max_implied_ref, Architecture::max_term_duplication, Varnode::setExplicit(), and Varnode::setMark().

int4 ActionMarkExplicit::baseExplicit ( Varnode vn,
int4  maxref 
)
staticprivate

Make initial determination if a Varnode should be explicit.

If the given Varnode is defined by CPUI_NEW, return -2 indicating it should be explicit and that it needs special printing.

Parameters
vnis the given Varnode
maxrefis the maximum number of references to consider before forcing explicitness
Returns
-1 if given Varnode should be marked explicit, the number of descendants otherwise

References Varnode::beginDescend(), PcodeOp::code(), Varnode::contains(), CPUI_INT_ZEXT, CPUI_NEW, CPUI_PIECE, CPUI_PTRSUB, CPUI_SUBPIECE, Varnode::endDescend(), Varnode::getDef(), Varnode::getHigh(), PcodeOp::getIn(), Varnode::getOffset(), PcodeOp::getOut(), Varnode::hasNoDescend(), Varnode::isAddrTied(), PcodeOp::isCall(), Varnode::isConstant(), Varnode::isInput(), Varnode::isMapped(), PcodeOp::isMarker(), Varnode::isSpacebase(), PcodeOp::numInput(), HighVariable::numInstances(), and Varnode::overlap().

void ActionMarkExplicit::checkNewToConstructor ( Funcdata data,
Varnode vn 
)
staticprivate

Set special properties on output of CPUI_NEW.

Assume vn is produced via a CPUI_NEW operation. If it is immediately fed to a constructor, set special printing flags on the Varnode.

Parameters
datais the function being analyzed
vnis the given Varnode

References Varnode::beginDescend(), PcodeOp::code(), CPUI_CALLIND, Varnode::endDescend(), Varnode::getDef(), PcodeOp::getIn(), SeqNum::getOrder(), PcodeOp::getOut(), PcodeOp::getParent(), PcodeOp::getSeqNum(), PcodeOp::isCall(), Varnode::isWritten(), PcodeOp::numInput(), Funcdata::opMarkNonPrinting(), and Funcdata::opMarkSpecialPrint().

virtual Action* ActionMarkExplicit::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 Action.

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

int4 ActionMarkExplicit::multipleInteraction ( vector< Varnode * > &  multlist)
staticprivate

Find multiple descendant chains.

Look for certain situations where one Varnode with multiple descendants has one descendant who also has multiple descendants. This routine is handed the list of Varnodes with multiple descendants; These all must already have their mark set. For the situations we can find with one flowing into another, mark the top Varnode as explicit.

Parameters
multlistis the list Varnodes with multiple descendants
Returns
the number Varnodes that were marked as explicit

References Varnode::clearImplied(), Varnode::clearMark(), PcodeOp::code(), CPUI_COPY, CPUI_INT_SEXT, CPUI_INT_ZEXT, CPUI_PTRADD, Varnode::getDef(), PcodeOp::getIn(), PcodeOp::isBoolOutput(), Varnode::isMark(), Varnode::isWritten(), PcodeOp::numInput(), and Varnode::setExplicit().

void ActionMarkExplicit::processMultiplier ( Varnode vn,
int4  max 
)
staticprivate

For a given multi-descendant Varnode, decide if it should be explicit.

Count the number of terms in the expression making up vn. If there are more than max terms, mark vn as explicit. The given Varnode is already assumed to have multiple descendants. We do a depth first traversal along op inputs, to recursively calculate the number of explicit terms in an expression.

Parameters
vnis the given Varnode
maxis the maximum number of terms to allow

References Varnode::clearImplied(), Varnode::getDef(), PcodeOp::getIn(), Varnode::isExplicit(), Varnode::isMark(), Varnode::isSpacebase(), Varnode::isWritten(), and Varnode::setExplicit().


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