Ghidra 11.3.2
Ghidra internal decompiler documentation.
Loading...
Searching...
No Matches
ghidra::SplitDatatype::RootPointer Class Reference

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

Collaboration diagram for ghidra::SplitDatatype::RootPointer:
[legend]

Public Member Functions

bool find (PcodeOp *op, Datatype *valueType)
 Locate root pointer for underlying LOAD or STORE.
 
void duplicateToTemp (Funcdata &data, PcodeOp *followOp)
 COPY the root varnode into a temp register.
 
void freePointerChain (Funcdata &data)
 Remove unused pointer calculations.
 

Private Member Functions

bool backUpPointer (Datatype *impliedBase)
 Follow flow of pointer back thru INT_ADD or PTRSUB.
 

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 ( Datatype impliedBase)
private

Follow flow of pointer back thru INT_ADD or PTRSUB.

If pointer Varnode is written by a COPY, INT_ADD, PTRSUB, or PTRADD from another pointer to a

  • structure
  • array OR
  • to an implied array with the given base type

then update pointer Varnode, baseOffset, and ptrType to this.

Parameters
impliedBaseif non-null is the allowed element data-type for an implied array
Returns
true if pointer was successfully updated

References ghidra::AddrSpace::addressToByteInt(), baseOffset, ghidra::PcodeOp::code(), ghidra::CPUI_COPY, ghidra::CPUI_INT_ADD, ghidra::CPUI_PTRADD, ghidra::CPUI_PTRSUB, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::Datatype::getMetatype(), ghidra::Varnode::getOffset(), ghidra::Varnode::getTypeReadFacing(), ghidra::TypePointer::getWordSize(), ghidra::Varnode::isConstant(), ghidra::Varnode::isWritten(), pointer, ptrType, ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, and ghidra::TYPE_STRUCT.

◆ duplicateToTemp()

void ghidra::SplitDatatype::RootPointer::duplicateToTemp ( Funcdata data,
PcodeOp followOp 
)

COPY the root varnode into a temp register.

Add a COPY op from the pointer Varnode to temporary register and make it the new root pointer. This guarantees that the pointer Varnode will not be modified by subsequent STOREs and can be implicit in the expressions.

Parameters
datais the containing function
followOpis the point where the COPY should be inserted

References ghidra::Funcdata::buildCopyTemp(), ghidra::SplitDatatype::data, and ghidra::Varnode::updateType().

Referenced by ghidra::SplitDatatype::splitStore().

◆ find()

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

Locate root pointer for underlying LOAD or STORE.

We search for a pointer to the specified data-type starting with the LOAD/STORE. If we don't immediately find it, we back up one level (through a PTRSUB, PTRADD, or INT_ADD). If it isn't found after 1 hop, false is returned. Once this pointer is found, we back up through any single path of nested TYPE_STRUCT and TYPE_ARRAY offsets to establish the final root pointer, and true is returned. Any accumulated offset, relative to the original LOAD or STORE pointer is recorded in the baseOffset.

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_ARRAY, 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::SplitDatatype::data, 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: