Ghidra 11.3.2
Ghidra internal decompiler documentation.
|
Class for extracting primitive elements of a data-type. More...
#include <modelrules.hh>
Classes | |
class | Primitive |
A primitive data-type and its offset within the containing data-type. More... | |
Public Member Functions | |
PrimitiveExtractor (Datatype *dt, bool unionIllegal, int4 offset, int4 max) | |
Constructor. | |
int4 | size (void) const |
Return the number of primitives extracted. | |
const Primitive & | get (int4 i) const |
Get a particular primitive. | |
bool | isValid (void) const |
Return true if primitives were successfully extracted. | |
bool | containsUnknown (void) const |
Are there unknown elements. | |
bool | isAligned (void) const |
Are all elements aligned. | |
bool | containsHoles (void) const |
Is there empty space that is not padding. | |
Private Types | |
enum | { unknown_element = 1 , unaligned = 2 , extra_space = 4 , invalid = 8 , union_invalid = 16 } |
Private Member Functions | |
int4 | checkOverlap (vector< Primitive > &res, vector< Primitive > &small, int4 point, Primitive &big) |
Check that a big Primitive properly overlaps smaller Primitives. | |
bool | commonRefinement (vector< Primitive > &first, vector< Primitive > &second) |
Overwrite first list with common refinement of first and second. | |
bool | handleUnion (TypeUnion *dt, int4 max, int4 offset) |
Add primitives representing a union data-type. | |
bool | extract (Datatype *dt, int4 max, int4 offset) |
Extract list of primitives from given data-type. | |
Private Attributes | |
vector< Primitive > | primitives |
List of extracted primitives. | |
uint4 | flags |
Boolean properties of the data-type. | |
Class for extracting primitive elements of a data-type.
This recursively collects the formal primitive data-types of a composite data-type, laying them out with their offsets in an array. Other boolean properties are collected.
|
private |
ghidra::PrimitiveExtractor::PrimitiveExtractor | ( | Datatype * | dt, |
bool | unionIllegal, | ||
int4 | offset, | ||
int4 | max | ||
) |
dt | is data-type extract from |
unionIllegal | is true if unions encountered during extraction are considered illegal |
offset | is the starting offset to associate with the data-type |
max | is the maximum number of primitives to extract before giving up |
References extract(), flags, invalid, and union_invalid.
|
private |
Check that a big Primitive properly overlaps smaller Primitives.
If the big Primitive does not properly overlap the smaller Primitives starting at the given point, return -1. Otherwise, if the big Primitive is floating-point, add the overlapped primitives to the common refinement list, or if not a floating-point, add the big Primitive to the list. (Integer primitives are preferred over floating-point primitives in this way) Return the index of the next primitive after the overlap.
res | holds the common refinement list |
small | is the list of Primitives that are overlapped |
point | is the index of the first overlap |
big | is the big overlapping Primitive |
References ghidra::PrimitiveExtractor::Primitive::dt, ghidra::Datatype::getAlignSize(), ghidra::Datatype::getMetatype(), ghidra::PrimitiveExtractor::Primitive::offset, and ghidra::TYPE_FLOAT.
Referenced by commonRefinement().
|
private |
Overwrite first list with common refinement of first and second.
Given two sets of overlapping Primitives, find a common refinement of the lists. If there is any partial overlap of two Primitives, false is returned. If the same primitive data-type occurs at the same offset, it is included in the refinement. Otherwise an integer data-type is preferred over a floating-point data-type, or a bigger primitive is preferred over smaller overlapping primitives. The final refinement replaces the first list.
first | is the first list of Primitives |
second | is the second list |
References checkOverlap(), ghidra::PrimitiveExtractor::Primitive::dt, ghidra::Datatype::getAlignSize(), and ghidra::PrimitiveExtractor::Primitive::offset.
Referenced by handleUnion().
|
private |
Extract list of primitives from given data-type.
An array of the primitive data-types, with their associated offsets, is constructed. If the given data-type is already primitive it is put in the array by itself. Otherwise if it is composite, its components are recursively added to the array. Boolean properties about the primitives encountered are recorded:
If a maximum number of extracted primitives is exceeded, or if an illegal data-type is encountered (void or other internal data-type) false is returned.
dt | is the given data-type to extract primitives from |
max | is the maximum number of primitives to extract before giving up |
offset | is the starting offset to associate with the first primitive |
< Mark that the data-type contains an unknown primitive
References ghidra::TypeStruct::beginField(), ghidra::TypeStruct::endField(), extra_space, extract(), flags, ghidra::Datatype::getAlignment(), ghidra::Datatype::getAlignSize(), ghidra::Datatype::getMetatype(), handleUnion(), primitives, ghidra::TYPE_ARRAY, ghidra::TYPE_BOOL, ghidra::TYPE_CODE, ghidra::TYPE_FLOAT, ghidra::TYPE_INT, ghidra::TYPE_PTR, ghidra::TYPE_PTRREL, ghidra::TYPE_STRUCT, ghidra::TYPE_UINT, ghidra::TYPE_UNION, ghidra::TYPE_UNKNOWN, unaligned, and unknown_element.
Referenced by extract(), and PrimitiveExtractor().
|
private |
Add primitives representing a union data-type.
Form a primitive list for each field of the union. Then, if possible, form a common refinement of all the primitive lists and add to the end of this extractor's list.
dt | is the union data-type |
max | is the maximum number primitives allowed for this extraction |
offset | is the starting offset of the union within the parent |
References commonRefinement(), flags, ghidra::TypeUnion::getField(), isValid(), ghidra::TypeUnion::numDepend(), ghidra::TypeField::offset, primitives, ghidra::TypeField::type, and union_invalid.
Referenced by extract().