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

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

#include <coreaction.hh>

Inheritance diagram for ghidra::ActionNameVars:
ghidra::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 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...
 

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 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

Choose names for all high-level variables (HighVariables)

Member Function Documentation

◆ apply()

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

References ghidra::ScopeInternal::assignDefaultNames(), ghidra::Scope::buildDefaultName(), ghidra::Varnode::getHigh(), ghidra::Symbol::getScope(), ghidra::Funcdata::getScopeLocal(), ghidra::HighVariable::getSymbol(), ghidra::Symbol::isNameUndefined(), ghidra::ScopeLocal::recoverNameRecommendationsForSymbols(), and ghidra::Scope::renameSymbol().

◆ clone()

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

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

◆ linkSpacebaseSymbol()

void ghidra::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 ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_PTRSUB, ghidra::Varnode::endDescend(), ghidra::PcodeOp::getIn(), ghidra::Varnode::isConstant(), ghidra::Varnode::isInput(), ghidra::Symbol::isNameUndefined(), and ghidra::Funcdata::linkSymbolReference().

◆ linkSymbols()

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

◆ lookForBadJumpTables()

void ghidra::ActionNameVars::lookForBadJumpTables ( Funcdata data)
staticprivate

◆ lookForFuncParamNames()

void ghidra::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 ghidra::Funcdata::getCallSpecs(), ghidra::Varnode::getHigh(), ghidra::PcodeOp::getIn(), ghidra::HighVariable::getNumMergeClasses(), ghidra::FuncCallSpecs::getOp(), ghidra::FuncProto::getParam(), ghidra::Symbol::getScope(), ghidra::Funcdata::getScopeLocal(), ghidra::HighVariable::getSymbol(), ghidra::Varnode::isFree(), ghidra::Varnode::isInput(), ghidra::FuncProto::isInputLocked(), ghidra::Symbol::isNameUndefined(), ghidra::ScopeInternal::makeNameUnique(), ghidra::Funcdata::numCalls(), ghidra::PcodeOp::numInput(), ghidra::FuncProto::numParams(), and ghidra::Scope::renameSymbol().

◆ makeRec()

void ghidra::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 ghidra::PcodeOp::code(), ghidra::CPUI_CAST, ghidra::ActionNameVars::OpRecommend::ct, ghidra::Varnode::getDef(), ghidra::Varnode::getHigh(), ghidra::PcodeOp::getIn(), ghidra::ProtoParameter::getName(), ghidra::Varnode::getSize(), ghidra::ProtoParameter::getSize(), ghidra::ProtoParameter::getType(), ghidra::HighVariable::isAddrTied(), ghidra::Varnode::isImplied(), ghidra::ProtoParameter::isNameLocked(), ghidra::ProtoParameter::isNameUndefined(), ghidra::Varnode::isWritten(), ghidra::ActionNameVars::OpRecommend::namerec, and ghidra::Datatype::typeOrder().


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