Ghidra 11.3.2
Ghidra internal decompiler documentation.
|
A sequence of PcodeOps that move data in-to/out-of an array data-type. More...
#include <constseq.hh>
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 | |
Funcdata & | data |
The function containing the sequence. | |
PcodeOp * | rootOp |
The root PcodeOp. | |
Datatype * | charType |
Element data-type. | |
BlockBasic * | block |
Basic block containing all the COPY/STORE ops. | |
int4 | numElements |
Number of elements in the final sequence. | |
vector< WriteNode > | moveOps |
COPY/STORE into the array memory region. | |
vector< uint1 > | byteArray |
Constants collected in a single array. | |
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.
Initialize the sequence with the root operation which writes the earliest character in the memory region.
fdata | is the function containing the sequence |
ct | is the data-type of an element in the array |
root | is the PcodeOp to be interpreted as the root, copying the earliest element |
References block, charType, ghidra::PcodeOp::getParent(), numElements, and rootOp.
|
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.
References interfereBetween(), MINIMUM_SEQUENCE_LENGTH, moveOps, and rootOp.
Referenced by ghidra::HeapSequence::HeapSequence(), and ghidra::StringSequence::StringSequence().
|
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.
sz | is the maximum size of the byte array |
slot | is the slot to fetch input constants from |
rootOff | is the root offset |
bigEndian | is true if constant inputs have big endian encoding |
References byteArray, charType, ghidra::Datatype::getAlignSize(), ghidra::Datatype::getSize(), MINIMUM_SEQUENCE_LENGTH, and moveOps.
Referenced by ghidra::HeapSequence::HeapSequence(), and ghidra::StringSequence::StringSequence().
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.
startOp | is the starting op to check |
endOp | is the ending op |
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().
|
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.
index | will 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().
|
static |
Maximum number of characters in replacement string
Referenced by ghidra::HeapSequence::collectStoreOps().