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

A sequence of PcodeOps that move data in-to/out-of an array data-type. More...

#include <constseq.hh>

Inheritance diagram for ghidra::ArraySequence:
[legend]
Collaboration diagram for ghidra::ArraySequence:
[legend]

Classes

class  WriteNode
 Helper class holding a data-flow edge and optionally a memory offset being COPYed into or from. More...
 

Public Member Functions

 ArraySequence (Funcdata &fdata, Datatype *ct, PcodeOp *root)
 Constructor.
 
bool isValid (void) const
 Return true if sequence is found.
 

Static Public Attributes

static const int4 MINIMUM_SEQUENCE_LENGTH = 4
 Minimum number of sequential characters to trigger replacement with CALLOTHER.
 
static const int4 MAXIMUM_SEQUENCE_LENGTH = 0x20000
 

Protected Member Functions

bool checkInterference (void)
 Find maximal set of ops containing the root with no interfering ops in between.
 
int4 formByteArray (int4 sz, int4 slot, uint8 rootOff, bool bigEndian)
 Put constant values from COPYs into a single byte array.
 
uint4 selectStringCopyFunction (int4 &index)
 Pick either strncpy, wcsncpy, or memcpy function used to copy string.
 

Static Protected Member Functions

static bool interfereBetween (PcodeOp *startOp, PcodeOp *endOp)
 Check for interfering ops between the two given ops.
 

Protected Attributes

Funcdatadata
 The function containing the sequence.
 
PcodeOprootOp
 The root PcodeOp.
 
DatatypecharType
 Element data-type.
 
BlockBasicblock
 Basic block containing all the COPY/STORE ops.
 
int4 numElements
 Number of elements in the final sequence.
 
vector< WriteNodemoveOps
 COPY/STORE into the array memory region.
 
vector< uint1 > byteArray
 Constants collected in a single array.
 

Detailed Description

A sequence of PcodeOps that move data in-to/out-of an array data-type.

A container for a sequence of PcodeOps within a basic block where we are trying to determine if the sequence can be replaced with a single memcpy style user-op.

Constructor & Destructor Documentation

◆ ArraySequence()

ghidra::ArraySequence::ArraySequence ( Funcdata fdata,
Datatype ct,
PcodeOp root 
)

Constructor.

Initialize the sequence with the root operation which writes the earliest character in the memory region.

Parameters
fdatais the function containing the sequence
ctis the data-type of an element in the array
rootis the PcodeOp to be interpreted as the root, copying the earliest element

References block, charType, ghidra::PcodeOp::getParent(), numElements, and rootOp.

Member Function Documentation

◆ checkInterference()

bool ghidra::ArraySequence::checkInterference ( void  )
protected

Find maximal set of ops containing the root with no interfering ops in between.

Sort the ops based on block order. Starting with the root op, walk backward until an interfering gap is found or until the earliest op is reached. Similarly, walk forward until an interfering gap is found. Truncate the op array to be this smaller set. If too many were truncated, return false.

Returns
true if a maximal set of ops is found containing at the least the minimum number required

References interfereBetween(), MINIMUM_SEQUENCE_LENGTH, moveOps, and rootOp.

Referenced by ghidra::HeapSequence::HeapSequence(), and ghidra::StringSequence::StringSequence().

◆ formByteArray()

int4 ghidra::ArraySequence::formByteArray ( int4  sz,
int4  slot,
uint8  rootOff,
bool  bigEndian 
)
protected

Put constant values from COPYs into a single byte array.

Create an array of bytes being written into the memory region. Run through the ops and place their constant input (at given slot) into the array based on their offset, relative to the given root offset. If there are gaps in the byte array, remove any op that doesn't write to the contiguous region in front of the root. Return 0 if the contiguous region is too small.

Parameters
szis the maximum size of the byte array
slotis the slot to fetch input constants from
rootOffis the root offset
bigEndianis true if constant inputs have big endian encoding
Returns
the number of characters in the contiguous region

References byteArray, charType, ghidra::Datatype::getAlignSize(), ghidra::Datatype::getSize(), MINIMUM_SEQUENCE_LENGTH, and moveOps.

Referenced by ghidra::HeapSequence::HeapSequence(), and ghidra::StringSequence::StringSequence().

◆ interfereBetween()

bool ghidra::ArraySequence::interfereBetween ( PcodeOp startOp,
PcodeOp endOp 
)
staticprotected

Check for interfering ops between the two given ops.

The output Varnodes themselves should be verified to only be read outside of the basic block. So effectively only LOADs, STOREs, and CALLs can really interfere. Check for these between the given ops.

Parameters
startOpis the starting op to check
endOpis the ending op
Returns
true if there is no interference, false if there is possible interference

References ghidra::PcodeOp::code(), ghidra::CPUI_CALLOTHER, ghidra::CPUI_CPOOLREF, ghidra::CPUI_INDIRECT, ghidra::CPUI_NEW, ghidra::CPUI_SEGMENTOP, ghidra::PcodeOp::getEvalType(), ghidra::PcodeOp::nextOp(), and ghidra::PcodeOp::special.

Referenced by checkInterference().

◆ selectStringCopyFunction()

uint4 ghidra::ArraySequence::selectStringCopyFunction ( int4 &  index)
protected

Pick either strncpy, wcsncpy, or memcpy function used to copy string.

Use the charType to select the appropriate string copying function. If a match to the charType doesn't exist, use a built-in memcpy function. The id of the selected built-in function is returned. The value indicating either the number of characters or number of bytes being copied is also passed back.

Parameters
indexwill hold the number of elements being copied

References ghidra::UserPcodeOp::BUILTIN_MEMCPY, ghidra::UserPcodeOp::BUILTIN_STRNCPY, ghidra::UserPcodeOp::BUILTIN_WCSNCPY, charType, data, ghidra::Datatype::getAlignSize(), ghidra::Funcdata::getArch(), ghidra::TypeFactory::getSizeOfChar(), ghidra::TypeFactory::getSizeOfWChar(), ghidra::TypeFactory::getTypeChar(), numElements, and ghidra::Architecture::types.

Referenced by ghidra::StringSequence::buildStringCopy(), and ghidra::HeapSequence::buildStringCopy().

Member Data Documentation

◆ MAXIMUM_SEQUENCE_LENGTH

const int4 ghidra::ArraySequence::MAXIMUM_SEQUENCE_LENGTH = 0x20000
static

Maximum number of characters in replacement string

Referenced by ghidra::HeapSequence::collectStoreOps().


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