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

Check for constants, with pointer type, that correspond to global symbols. More...

#include <coreaction.hh>

Inheritance diagram for ghidra::ActionConstantPtr:
ghidra::Action

Public Member Functions

 ActionConstantPtr (const string &g)
 Constructor.
 
virtual void reset (Funcdata &data)
 Reset the Action for a new function. More...
 
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 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 AddrSpacesearchForSpaceAttribute (Varnode *vn, PcodeOp *op)
 Search for address space annotations in the path of a pointer constant. More...
 
static AddrSpaceselectInferSpace (Varnode *vn, PcodeOp *op, const vector< AddrSpace *> &spaceList)
 Select the AddrSpace in which we infer with the given constant is a pointer. More...
 
static SymbolEntryisPointer (AddrSpace *spc, Varnode *vn, PcodeOp *op, int4 slot, Address &rampoint, uintb &fullEncoding, Funcdata &data)
 Determine if given Varnode might be a pointer constant. More...
 

Private Attributes

int4 localcount
 Number of passes made for this function.
 

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

Check for constants, with pointer type, that correspond to global symbols.

Member Function Documentation

◆ apply()

int4 ghidra::ActionConstantPtr::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::Funcdata::beginLoc(), ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::Funcdata::endLoc(), ghidra::Funcdata::getArch(), ghidra::AddrSpaceManager::getConstantSpace(), ghidra::PcodeOp::getIn(), ghidra::Varnode::getOffset(), ghidra::Varnode::getSize(), ghidra::PcodeOp::getSlot(), ghidra::Varnode::hasNoDescend(), ghidra::Funcdata::hasTypeRecoveryStarted(), ghidra::Architecture::inferPtrSpaces, ghidra::Varnode::isConstant(), ghidra::Varnode::isPtrCheck(), ghidra::Varnode::isSpacebase(), ghidra::Varnode::loneDescend(), ghidra::Funcdata::opSwapInput(), ghidra::Varnode::setPtrCheck(), and ghidra::Funcdata::spacebaseConstant().

◆ clone()

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

◆ isPointer()

SymbolEntry * ghidra::ActionConstantPtr::isPointer ( AddrSpace spc,
Varnode vn,
PcodeOp op,
int4  slot,
Address rampoint,
uintb &  fullEncoding,
Funcdata data 
)
staticprivate

Determine if given Varnode might be a pointer constant.

If it is a pointer, return the symbol it points to, or NULL otherwise. If it is determined that the Varnode is a pointer to a specific symbol, the encoding of the full pointer is passed back. Usually this is just the constant value of the Varnode, but in this case of partial pointers (like near pointers) the full pointer may contain additional information.

Parameters
spcis the address space being pointed to
vnis the given Varnode
opis the lone descendant of the Varnode
slotis the slot index of the Varnode
rampointwill hold the Address of the resolved symbol
fullEncodingwill hold the full pointer encoding being passed back
datais the function being analyzed
Returns
the recovered symbol or NULL

References ghidra::PcodeOp::code(), ghidra::CPUI_CALL, ghidra::CPUI_CALLIND, ghidra::CPUI_COPY, ghidra::CPUI_INT_ADD, ghidra::CPUI_INT_EQUAL, ghidra::CPUI_INT_LESS, ghidra::CPUI_INT_LESSEQUAL, ghidra::CPUI_INT_NOTEQUAL, ghidra::CPUI_PIECE, ghidra::CPUI_RETURN, ghidra::CPUI_STORE, ghidra::SymbolEntry::getAddr(), ghidra::PcodeOp::getAddr(), ghidra::Funcdata::getArch(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::Varnode::getOffset(), ghidra::PcodeOp::getOut(), ghidra::Scope::getParent(), ghidra::AddrSpace::getPointerLowerBound(), ghidra::AddrSpace::getPointerUpperBound(), ghidra::Funcdata::getScopeLocal(), ghidra::Varnode::getSize(), ghidra::SymbolEntry::getSymbol(), ghidra::Symbol::getType(), ghidra::Varnode::getTypeDefFacing(), ghidra::Varnode::getTypeReadFacing(), ghidra::Architecture::infer_pointers, ghidra::Datatype::isCharPrint(), ghidra::Address::isInvalid(), ghidra::Varnode::isTypeLock(), ghidra::Scope::queryContainer(), ghidra::AddrSpaceManager::resolveConstant(), ghidra::TYPE_ARRAY, and ghidra::TYPE_PTR.

◆ reset()

virtual void ghidra::ActionConstantPtr::reset ( Funcdata data)
inlinevirtual

Reset the Action for a new function.

Parameters
datais the new function this Action may affect

Reimplemented from ghidra::Action.

◆ searchForSpaceAttribute()

AddrSpace * ghidra::ActionConstantPtr::searchForSpaceAttribute ( Varnode vn,
PcodeOp op 
)
staticprivate

Search for address space annotations in the path of a pointer constant.

From a constant, search forward in its data-flow either for a LOAD or STORE operation where we can see the address space being accessed, or search for a pointer data-type with an address space attribute. We make a limited traversal through the op reading the constant, through INT_ADD, INDIRECT, COPY, and MULTIEQUAL until we hit a LOAD or STORE.

Parameters
vnis the constant we are searching from
opis the PcodeOp reading the constant
Returns
the discovered AddrSpace or null

References ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INDIRECT, ghidra::CPUI_INT_ADD, ghidra::CPUI_LOAD, ghidra::CPUI_MULTIEQUAL, ghidra::CPUI_STORE, ghidra::Varnode::endDescend(), ghidra::AddrSpace::getAddrSize(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::PcodeOp::getOut(), ghidra::Varnode::getSize(), ghidra::Varnode::getSpaceFromConst(), ghidra::Varnode::getType(), ghidra::Varnode::loneDescend(), and ghidra::TYPE_PTR.

◆ selectInferSpace()

AddrSpace * ghidra::ActionConstantPtr::selectInferSpace ( Varnode vn,
PcodeOp op,
const vector< AddrSpace *> &  spaceList 
)
staticprivate

Select the AddrSpace in which we infer with the given constant is a pointer.

The constant must match the AddrSpace address size. If there is more than one possible match, search for more information in the syntax tree.

Parameters
vnis the given constant Varnode
opis the PcodeOp which uses the constant
spaceListis the list of address spaces to select from
Returns
the selected address space or null

References ghidra::AddrSpace::getAddrSize(), ghidra::Datatype::getMetatype(), ghidra::AddrSpace::getMinimumPtrSize(), ghidra::Varnode::getSize(), ghidra::Varnode::getType(), and ghidra::TYPE_PTR.


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