decompiler
1.0.0
|
Choose names for all high-level variables (HighVariables) More...
#include <coreaction.hh>
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 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... | |
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. | |
Choose names for all high-level variables (HighVariables)
|
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::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().
|
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 |
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
vn | is the given spacebase Varnode |
data | is the function containing the Varnode |
namerec | is 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().
|
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.
data | is the given function |
namerec | is the container for collecting Symbols with a name |
References ghidra::Funcdata::beginLoc(), ghidra::Funcdata::endLoc(), ghidra::Funcdata::getArch(), ghidra::AddrSpaceManager::getConstantSpace(), ghidra::Varnode::getHigh(), ghidra::HighVariable::getNameRepresentative(), ghidra::Symbol::getScope(), ghidra::Varnode::getSize(), ghidra::Datatype::getSize(), ghidra::AddrSpaceManager::getSpace(), ghidra::Varnode::getSymbolEntry(), ghidra::HighVariable::getSymbolOffset(), ghidra::HighVariable::getType(), ghidra::Symbol::getType(), ghidra::HighVariable::hasName(), ghidra::Varnode::isFree(), ghidra::Symbol::isNameUndefined(), ghidra::Symbol::isSizeTypeLocked(), ghidra::Varnode::isSpacebase(), ghidra::Funcdata::linkSymbol(), ghidra::AddrSpaceManager::numSpaces(), and ghidra::Scope::overrideSizeLockType().
|
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.
data | is the function being analyzed |
References ghidra::PcodeOp::code(), ghidra::CPUI_CAST, ghidra::Funcdata::getCallSpecs(), ghidra::Varnode::getDef(), ghidra::Varnode::getHigh(), ghidra::PcodeOp::getIn(), ghidra::FuncCallSpecs::getOp(), ghidra::Symbol::getScope(), ghidra::Funcdata::getScopeLocal(), ghidra::HighVariable::getSymbol(), ghidra::FuncCallSpecs::isBadJumpTable(), ghidra::Varnode::isFree(), ghidra::Varnode::isImplied(), ghidra::Symbol::isNameLocked(), ghidra::Varnode::isWritten(), ghidra::ScopeInternal::makeNameUnique(), ghidra::Funcdata::numCalls(), and ghidra::Scope::renameSymbol().
|
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.
data | is the function being analyzed |
varlist | is 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().
|
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.
param | is function prototype symbol |
vn | is the Varnode associated with the parameter |
recmap | is 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().