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

Choose names for all high-level variables (HighVariables) More...

#include <coreaction.hh>

Inheritance diagram for ActionNameVars:
Action

Classes

struct  OpRecommend
 This class is a record in a database used to store and lookup potential names. More...
 

Public Member Functions

 ActionNameVars (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 void makeRec (ProtoParameter *param, Varnode *vn, map< HighVariable *, OpRecommend > &recmap)
 Add a recommendation to the database based on a particular sub-function parameter. More...
 
static void lookForBadJumpTables (Funcdata &data)
 Mark the switch variable for bad jump-tables. More...
 
static void lookForFuncParamNames (Funcdata &data, const vector< Varnode * > &varlist)
 Collect potential variable names from sub-function parameters. More...
 
static void linkSpacebaseSymbol (Varnode *vn, Funcdata &data, vector< Varnode * > &namerec)
 Link symbols associated with a given spacebase Varnode. More...
 
static void linkSymbols (Funcdata &data, vector< Varnode * > &namerec)
 Link formal Symbols to their HighVariable representative in the given Function. 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

Choose names for all high-level variables (HighVariables)

Member Function Documentation

int4 ActionNameVars::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 ScopeInternal::assignDefaultNames(), Scope::buildDefaultName(), Varnode::getHigh(), Symbol::getScope(), Funcdata::getScopeLocal(), HighVariable::getSymbol(), Symbol::isNameUndefined(), ScopeLocal::recoverNameRecommendationsForSymbols(), and Scope::renameSymbol().

virtual Action* ActionNameVars::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().

void ActionNameVars::linkSpacebaseSymbol ( Varnode vn,
Funcdata data,
vector< Varnode * > &  namerec 
)
staticprivate

Link symbols associated with a given spacebase Varnode.

Look for PTRSUB ops which indicate a symbol reference within the address space referred to by the spacebase Varnode. Decode any symbol reference and link it to the appropriate HighVariable

Parameters
vnis the given spacebase Varnode
datais the function containing the Varnode
namerecis used to store any recovered Symbol without a name

References Varnode::beginDescend(), PcodeOp::code(), CPUI_PTRSUB, Varnode::endDescend(), PcodeOp::getIn(), Varnode::isConstant(), Varnode::isInput(), Symbol::isNameUndefined(), and Funcdata::linkSymbolReference().

void ActionNameVars::linkSymbols ( Funcdata data,
vector< Varnode * > &  namerec 
)
staticprivate

Link formal Symbols to their HighVariable representative in the given Function.

Run through all HighVariables for the given function and set up the explicit mapping with existing Symbol objects. If there is no matching Symbol for a given HighVariable, a new Symbol is created. Any Symbol that does not have a name is added to a list for further name resolution.

Parameters
datais the given function
namerecis the container for collecting Symbols with a name

References Funcdata::beginLoc(), Funcdata::endLoc(), Funcdata::getArch(), AddrSpaceManager::getConstantSpace(), Varnode::getHigh(), HighVariable::getNameRepresentative(), Symbol::getScope(), Datatype::getSize(), Varnode::getSize(), AddrSpaceManager::getSpace(), Varnode::getSymbolEntry(), HighVariable::getSymbolOffset(), HighVariable::getType(), Symbol::getType(), HighVariable::hasName(), Varnode::isFree(), Symbol::isNameUndefined(), Symbol::isSizeTypeLocked(), Varnode::isSpacebase(), Funcdata::linkSymbol(), AddrSpaceManager::numSpaces(), and Scope::overrideSizeLockType().

void ActionNameVars::lookForBadJumpTables ( Funcdata data)
staticprivate

Mark the switch variable for bad jump-tables.

Name the Varnode which seems to be the putative switch variable for an unrecovered jump-table with a special name.

Parameters
datais the function being analyzed

References PcodeOp::code(), CPUI_CAST, Funcdata::getCallSpecs(), Varnode::getDef(), Varnode::getHigh(), PcodeOp::getIn(), FuncCallSpecs::getOp(), Symbol::getScope(), Funcdata::getScopeLocal(), HighVariable::getSymbol(), FuncCallSpecs::isBadJumpTable(), Varnode::isFree(), Varnode::isImplied(), Symbol::isNameLocked(), Varnode::isWritten(), ScopeInternal::makeNameUnique(), Funcdata::numCalls(), and Scope::renameSymbol().

void ActionNameVars::lookForFuncParamNames ( Funcdata data,
const vector< Varnode * > &  varlist 
)
staticprivate

Collect potential variable names from sub-function parameters.

Run through all sub-functions with a known prototype and collect potential names for current Varnodes used to pass the parameters. For these Varnodes, select from among these names.

Parameters
datais the function being analyzed
varlistis a list of Varnodes representing HighVariables that need names

References Funcdata::getCallSpecs(), Varnode::getHigh(), PcodeOp::getIn(), HighVariable::getNumMergeClasses(), FuncCallSpecs::getOp(), FuncProto::getParam(), Symbol::getScope(), Funcdata::getScopeLocal(), HighVariable::getSymbol(), Varnode::isFree(), Varnode::isInput(), FuncProto::isInputLocked(), Symbol::isNameUndefined(), ScopeInternal::makeNameUnique(), Funcdata::numCalls(), PcodeOp::numInput(), FuncProto::numParams(), and Scope::renameSymbol().

void ActionNameVars::makeRec ( ProtoParameter param,
Varnode vn,
map< HighVariable *, OpRecommend > &  recmap 
)
staticprivate

Add a recommendation to the database based on a particular sub-function parameter.

We know vn holds data-flow for parameter param, try to attach its name to vn's symbol. We update map from vn to a name recommendation record. If vn is input to multiple functions, the one whose parameter has the most specified type will be preferred. If vn is passed to the function via a cast, this name will only be used if there is no other function that takes vn as a parameter.

Parameters
paramis function prototype symbol
vnis the Varnode associated with the parameter
recmapis the recommendation map

References PcodeOp::code(), CPUI_CAST, ActionNameVars::OpRecommend::ct, Varnode::getDef(), Varnode::getHigh(), PcodeOp::getIn(), ProtoParameter::getName(), Varnode::getSize(), ProtoParameter::getSize(), ProtoParameter::getType(), HighVariable::isAddrTied(), Varnode::isImplied(), ProtoParameter::isNameLocked(), ProtoParameter::isNameUndefined(), Varnode::isWritten(), ActionNameVars::OpRecommend::namerec, and Datatype::typeOrder().


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