decompiler  1.0.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ghidra::SplitDatatype::RootPointer Class Reference

A helper class describing the pointer being passed to a LOAD or STORE. More...

Public Member Functions

bool find (PcodeOp *op, Datatype *valueType)
 Locate root pointer for underlying LOAD or STORE. More...
 
void freePointerChain (Funcdata &data)
 Remove unused pointer calculations. More...
 

Private Member Functions

bool backUpPointer (void)
 Follow flow of pointer back thru INT_ADD or PTRSUB. More...
 

Private Attributes

PcodeOploadStore
 LOAD or STORE op.
 
TypePointerptrType
 Base pointer data-type of LOAD or STORE.
 
VarnodefirstPointer
 Direct pointer input for LOAD or STORE.
 
Varnodepointer
 The root pointer.
 
int4 baseOffset
 Offset of the LOAD or STORE relative to root pointer.
 

Friends

class SplitDatatype
 

Detailed Description

A helper class describing the pointer being passed to a LOAD or STORE.

It makes distinction between the immediate pointer to the LOAD or STORE and a root pointer to the main structure or array, which the immediate pointer may be at an offset from.

Member Function Documentation

◆ backUpPointer()

bool ghidra::SplitDatatype::RootPointer::backUpPointer ( void  )
private

Follow flow of pointer back thru INT_ADD or PTRSUB.

If pointer Varnode is written by an INT_ADD, PTRSUB, or PTRADD from a another pointer to a structure or array, update pointer Varnode, baseOffset, and ptrType to this.

Returns
true if pointer was successfully updated

References ghidra::SplitFlow::addOp(), ghidra::AddrSpace::addressToByteInt(), ghidra::PcodeOp::code(), ghidra::CPUI_INT_ADD, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::Varnode::getOffset(), ghidra::Varnode::getTypeReadFacing(), ghidra::Varnode::isConstant(), ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, and ghidra::TYPE_STRUCT.

◆ find()

bool ghidra::SplitDatatype::RootPointer::find ( PcodeOp op,
Datatype valueType 
)

Locate root pointer for underlying LOAD or STORE.

The LOAD or STORE pointer Varnode is examined. If it is a pointer to the given data-type, the root pointer is returned. If not, we try to recursively walk back through either PTRSUB or INT_ADD instructions, until a pointer Varnode matching the data-type is found. Any accumulated offset, relative to the original LOAD or STORE pointer is recorded in the baseOffset. If a matching pointer is not found, false is returned.

Parameters
opis the LOAD or STORE
valueTypeis the specific data-type to match
Returns
true if the root pointer is found

References ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::TYPE_PARTIALSTRUCT, and ghidra::TYPE_PTR.

Referenced by ghidra::SplitDatatype::splitLoad(), and ghidra::SplitDatatype::splitStore().

◆ freePointerChain()

void ghidra::SplitDatatype::RootPointer::freePointerChain ( Funcdata data)

Remove unused pointer calculations.

If the pointer Varnode is no longer used, recursively check and remove the op producing it, which will be either an INT_ADD or PTRSUB, until the root pointer is reached or a Varnode still being used is encountered.

Parameters
datais the containing function

References ghidra::PcodeOp::getIn(), and ghidra::Funcdata::opDestroy().

Referenced by ghidra::SplitDatatype::splitLoad(), and ghidra::SplitDatatype::splitStore().


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