Ghidra 11.3.2
Ghidra internal decompiler documentation.
Loading...
Searching...
No Matches
ghidra::Datatype Class Referenceabstract

The base datatype class for the decompiler. More...

#include <type.hh>

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

Public Member Functions

 Datatype (const Datatype &op)
 Construct the base data-type copying low-level properties of another.
 
 Datatype (int4 s, int4 align, type_metatype m)
 Construct the base data-type providing size and meta-type.
 
virtual ~Datatype (void)
 Destructor.
 
bool isCoreType (void) const
 Is this a core data-type.
 
bool isCharPrint (void) const
 Does this print as a 'char'.
 
bool isEnumType (void) const
 Is this an enumerated type.
 
bool isASCII (void) const
 Does this print as an ASCII 'char'.
 
bool isUTF16 (void) const
 Does this print as UTF16 'wchar'.
 
bool isUTF32 (void) const
 Does this print as UTF32 'wchar'.
 
bool isVariableLength (void) const
 Is this a variable length structure.
 
bool hasSameVariableBase (const Datatype *ct) const
 Are these the same variable length data-type.
 
bool isOpaqueString (void) const
 Is this an opaquely encoded string.
 
bool isPointerToArray (void) const
 Is this a pointer to an array.
 
bool isPointerRel (void) const
 Is this a TypePointerRel.
 
bool isFormalPointerRel (void) const
 Is this a non-ephemeral TypePointerRel.
 
bool hasStripped (void) const
 Return true if this has a stripped form.
 
bool isIncomplete (void) const
 Is this an incompletely defined data-type.
 
bool needsResolution (void) const
 Is this a union or a pointer to union.
 
bool hasWarning (void) const
 Has a warning been issued about this data-type.
 
uint4 getInheritable (void) const
 Get properties pointers inherit.
 
uint4 getDisplayFormat (void) const
 Get the display format for constants with this data-type.
 
type_metatype getMetatype (void) const
 Get the type meta-type.
 
sub_metatype getSubMeta (void) const
 Get the sub-metatype.
 
uint8 getId (void) const
 Get the type id.
 
uint8 getUnsizedId (void) const
 Get the type id, without variable length size adjustment.
 
int4 getSize (void) const
 Get the type size.
 
int4 getAlignSize (void) const
 Get size rounded up to multiple of alignment.
 
int4 getAlignment (void) const
 Get the expected byte alignment.
 
const string & getName (void) const
 Get the type name.
 
const string & getDisplayName (void) const
 Get string to use in display.
 
DatatypegetTypedef (void) const
 Get the data-type immediately typedefed by this (or null)
 
virtual void printRaw (ostream &s) const
 Print a description of the type to stream.
 
virtual const TypeFieldfindTruncation (int8 off, int4 sz, const PcodeOp *op, int4 slot, int8 &newoff) const
 Find an immediate subfield of this data-type.
 
virtual DatatypegetSubType (int8 off, int8 *newoff) const
 Recover component data-type one-level down.
 
virtual DatatypenearestArrayedComponentForward (int8 off, int8 *newoff, int8 *elSize) const
 
virtual DatatypenearestArrayedComponentBackward (int8 off, int8 *newoff, int8 *elSize) const
 
virtual int4 getHoleSize (int4 off) const
 Get number of bytes at the given offset that are padding.
 
virtual int4 numDepend (void) const
 Get the number of component sub-types making up this data-type.
 
virtual DatatypegetDepend (int4 index) const
 Get a specific component sub-type by index.
 
virtual void printNameBase (ostream &s) const
 Print (part of) the name of this data-type as short prefix for a label.
 
virtual int4 compare (const Datatype &op, int4 level) const
 Order types for propagation.
 
virtual int4 compareDependency (const Datatype &op) const
 Compare for storage in tree structure.
 
virtual void encode (Encoder &encoder) const
 Encode the data-type to a stream.
 
virtual bool isPtrsubMatching (int8 off, int8 extra, int8 multiplier) const
 Is this data-type suitable as input to a CPUI_PTRSUB op.
 
virtual DatatypegetStripped (void) const
 Get a stripped version of this for formal use in formal declarations.
 
virtual DatatyperesolveInFlow (PcodeOp *op, int4 slot)
 Tailor data-type propagation based on Varnode use.
 
virtual DatatypefindResolve (const PcodeOp *op, int4 slot)
 Find a previously resolved sub-type.
 
virtual int4 findCompatibleResolve (Datatype *ct) const
 Find a resolution compatible with the given data-type.
 
virtual const TypeFieldresolveTruncation (int8 offset, PcodeOp *op, int4 slot, int8 &newoff)
 Resolve which union field is being used for a given PcodeOp when a truncation is involved.
 
int4 typeOrder (const Datatype &op) const
 Order this with -op- datatype.
 
int4 typeOrderBool (const Datatype &op) const
 Order this with -op-, treating bool data-type as special.
 
void encodeRef (Encoder &encoder) const
 Encode a reference of this to a stream.
 
bool isPieceStructured (void) const
 Does this data-type consist of separate pieces?
 
bool isPrimitiveWhole (void) const
 Is this made up of a single primitive.
 

Static Public Member Functions

static uint4 encodeIntegerFormat (const string &val)
 Encode the format attribute from an XML element.
 
static string decodeIntegerFormat (uint4 val)
 Decode the given format value into an XML attribute string.
 

Protected Types

enum  {
  coretype = 1 , chartype = 2 , enumtype = 4 , poweroftwo = 8 ,
  utf16 = 16 , utf32 = 32 , opaque_string = 64 , variable_length = 128 ,
  has_stripped = 0x100 , is_ptrrel = 0x200 , type_incomplete = 0x400 , needs_resolution = 0x800 ,
  force_format = 0x7000 , truncate_bigendian = 0x8000 , pointer_to_array = 0x10000 , warning_issued = 0x20000
}
 Boolean properties of datatypes. More...
 

Protected Member Functions

void decodeBasic (Decoder &decoder)
 Recover basic data-type properties.
 
void encodeBasic (type_metatype meta, int4 align, Encoder &encoder) const
 Encode basic data-type properties.
 
void encodeTypedef (Encoder &encoder) const
 Encode this as a typedef element to a stream.
 
void markComplete (void)
 Mark this data-type as completely defined.
 
void setDisplayFormat (uint4 format)
 Set a specific display format.
 
virtual Datatypeclone (void) const =0
 Clone the data-type.
 

Static Protected Member Functions

static uint8 hashName (const string &nm)
 Produce a data-type id by hashing the type name.
 
static uint8 hashSize (uint8 id, int4 size)
 Reversibly hash size into id.
 
static int4 calcAlignSize (int4 sz, int4 align)
 Calculate aligned size, given size and alignment of data-type.
 

Protected Attributes

uint8 id
 A unique id for the type (or 0 if an id is not assigned)
 
int4 size
 Size (of variable holding a value of this type)
 
uint4 flags
 Boolean properties of the type.
 
string name
 Name of type.
 
string displayName
 Name to display in output.
 
type_metatype metatype
 Meta-type - type disregarding size.
 
sub_metatype submeta
 Sub-type of of the meta-type, for comparisons.
 
DatatypetypedefImm
 The immediate data-type being typedefed by this.
 
int4 alignment
 Byte alignment expected for this data-type in addressable memory.
 
int4 alignSize
 Size of data-type rounded up to a multiple of alignment.
 

Static Protected Attributes

static sub_metatype base2sub [18]
 

Friends

class TypeFactory
 
struct DatatypeCompare
 

Detailed Description

The base datatype class for the decompiler.

Used for symbols, function prototypes, type propagation etc.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected

Boolean properties of datatypes.

Enumerator
coretype 

This is a basic type which will never be redefined.

chartype 

ASCII character data.

enumtype 

An enumeration type (as well as an integer)

poweroftwo 

An enumeration type where all values are of 2^^n form.

utf16 

16-bit wide chars in unicode UTF16

utf32 

32-bit wide chars in unicode UTF32

opaque_string 

Structure that should be treated as a string.

variable_length 

May be other structures with same name different lengths.

has_stripped 

Datatype has a stripped form for formal declarations.

is_ptrrel 

Datatype is a TypePointerRel.

type_incomplete 

Set if this (recursive) data-type has not been fully defined yet.

needs_resolution 

Datatype (union, pointer to union) needs resolution before propagation.

force_format 

3-bits encoding display format, 0=none, 1=hex, 2=dec, 3=oct, 4=bin, 5=char

truncate_bigendian 

Pointer can be truncated and is big endian.

pointer_to_array 

Data-type is a pointer to an array.

warning_issued 

Data-type has an associated warning string.

Member Function Documentation

◆ calcAlignSize()

int4 ghidra::Datatype::calcAlignSize ( int4  sz,
int4  align 
)
staticprotected

Calculate aligned size, given size and alignment of data-type.

Calculate size rounded up to be a multiple of align.

Parameters
szis the number of bytes in the data-type before padding
alignis the alignment of the data-type
Returns
the aligned size

Referenced by ghidra::TypeStruct::assignFieldOffsets(), ghidra::TypeStruct::decodeFields(), ghidra::TypeUnion::decodeFields(), ghidra::TypeStruct::setFields(), and ghidra::TypeUnion::setFields().

◆ clone()

◆ compare()

int4 ghidra::Datatype::compare ( const Datatype op,
int4  level 
) const
virtual

Order types for propagation.

Order this with another data-type, in a way suitable for the type propagation algorithm. Bigger types come earlier. More specific types come earlier.

Parameters
opis the data-type to compare with this
levelis maximum level to descend when recursively comparing
Returns
negative, 0, positive depending on ordering of types

Reimplemented in ghidra::TypePointer, ghidra::TypeArray, ghidra::TypeEnum, ghidra::TypeStruct, ghidra::TypeUnion, ghidra::TypePartialEnum, ghidra::TypePartialStruct, ghidra::TypePartialUnion, ghidra::TypePointerRel, ghidra::TypeCode, and ghidra::TypeSpacebase.

References size, and submeta.

Referenced by ghidra::TypePointer::compare(), ghidra::TypeArray::compare(), ghidra::TypeStruct::compare(), ghidra::TypeUnion::compare(), ghidra::TypePartialEnum::compare(), ghidra::TypePartialStruct::compare(), ghidra::TypePartialUnion::compare(), ghidra::TypeCode::compare(), typeOrder(), and typeOrderBool().

◆ compareDependency()

int4 ghidra::Datatype::compareDependency ( const Datatype op) const
virtual

Compare for storage in tree structure.

Sort data-types for the main TypeFactory container. The sort needs to be based on the data-type structure so that an example data-type, constructed outside the factory, can be used to find the equivalent object inside the factory. This means the comparison should not examine the data-type id. In practice, the comparison only needs to go down one level in the component structure before just comparing component pointers.

Parameters
opis the data-type to compare with this
Returns
negative, 0, positive depending on ordering of types

Reimplemented in ghidra::TypePointer, ghidra::TypeArray, ghidra::TypeEnum, ghidra::TypeStruct, ghidra::TypeUnion, ghidra::TypePartialEnum, ghidra::TypePartialStruct, ghidra::TypePartialUnion, ghidra::TypePointerRel, ghidra::TypeCode, and ghidra::TypeSpacebase.

References size, and submeta.

Referenced by ghidra::TypeEnum::compareDependency(), ghidra::TypeStruct::compareDependency(), ghidra::TypeUnion::compareDependency(), ghidra::TypeCode::compareDependency(), ghidra::TypeSpacebase::compareDependency(), ghidra::TypeFactory::decodeCode(), ghidra::TypeFactory::decodeStruct(), ghidra::TypeFactory::decodeUnion(), ghidra::TypeFactory::findAdd(), and ghidra::DatatypeCompare::operator()().

◆ decodeBasic()

◆ decodeIntegerFormat()

string ghidra::Datatype::decodeIntegerFormat ( uint4  val)
static

Decode the given format value into an XML attribute string.

Possible encoded values are 1-5 corresponding to "hex", "dec", "oct", "bin", "char"

Parameters
valis the value to decode
Returns
the decoded string

Referenced by encodeBasic(), ghidra::Symbol::encodeHeader(), and encodeTypedef().

◆ encode()

void ghidra::Datatype::encode ( Encoder encoder) const
virtual

Encode the data-type to a stream.

Encode a formal description of the data-type as a <type> element. For composite data-types, the description goes down one level, describing the component types only by reference.

Parameters
encoderis the stream encoder

Reimplemented in ghidra::TypeChar, ghidra::TypeUnicode, ghidra::TypeVoid, ghidra::TypePointer, ghidra::TypeArray, ghidra::TypeEnum, ghidra::TypeStruct, ghidra::TypeUnion, ghidra::TypePartialEnum, ghidra::TypePartialUnion, ghidra::TypePointerRel, ghidra::TypeCode, and ghidra::TypeSpacebase.

References ghidra::Encoder::closeElement(), encodeBasic(), metatype, and ghidra::Encoder::openElement().

Referenced by ghidra::TypePointerRel::encode(), ghidra::TypeFactory::encodeCoreTypes(), and encodeRef().

◆ encodeBasic()

void ghidra::Datatype::encodeBasic ( type_metatype  meta,
int4  align,
Encoder encoder 
) const
protected

Encode basic data-type properties.

Encode basic data-type properties (name,size,id) as attributes. This routine presumes the initial element is already written to the stream.

Parameters
metais the metatype attribute to encode
alignis the byte alignment to encode (-1 to not encode alignment)
encoderis the stream encoder

References coretype, decodeIntegerFormat(), flags, getDisplayFormat(), getUnsizedId(), isVariableLength(), name, opaque_string, size, ghidra::Encoder::writeBool(), ghidra::Encoder::writeSignedInteger(), ghidra::Encoder::writeString(), and ghidra::Encoder::writeUnsignedInteger().

Referenced by encode(), ghidra::TypeChar::encode(), ghidra::TypeUnicode::encode(), ghidra::TypePointer::encode(), ghidra::TypeArray::encode(), ghidra::TypeEnum::encode(), ghidra::TypeStruct::encode(), ghidra::TypeUnion::encode(), ghidra::TypePartialEnum::encode(), ghidra::TypePartialUnion::encode(), ghidra::TypePointerRel::encode(), ghidra::TypeCode::encode(), and ghidra::TypeSpacebase::encode().

◆ encodeIntegerFormat()

uint4 ghidra::Datatype::encodeIntegerFormat ( const string &  val)
static

Encode the format attribute from an XML element.

Possible values are:

  • 1 - hex
  • 2 - dec
  • 3 - oct
  • 4 - bin
  • 5 - char
Parameters
valis the string to encode
Returns
the encoded value

Referenced by decodeBasic(), ghidra::Symbol::decodeHeader(), and ghidra::TypeFactory::decodeTypedef().

◆ encodeRef()

◆ encodeTypedef()

void ghidra::Datatype::encodeTypedef ( Encoder encoder) const
protected

Encode this as a typedef element to a stream.

Called only if the typedefImm field is non-null. Encode the data-type to the stream as a simple <typedef> element including only the names and ids of this and the data-type it typedefs.

Parameters
encoderis the stream encoder

References ghidra::Encoder::closeElement(), decodeIntegerFormat(), encodeRef(), getDisplayFormat(), name, ghidra::Encoder::openElement(), typedefImm, ghidra::Encoder::writeString(), and ghidra::Encoder::writeUnsignedInteger().

Referenced by ghidra::TypeChar::encode(), ghidra::TypeUnicode::encode(), ghidra::TypeVoid::encode(), ghidra::TypePointer::encode(), ghidra::TypeArray::encode(), ghidra::TypeEnum::encode(), ghidra::TypeStruct::encode(), ghidra::TypeUnion::encode(), ghidra::TypeCode::encode(), and ghidra::TypeSpacebase::encode().

◆ findCompatibleResolve()

int4 ghidra::Datatype::findCompatibleResolve ( Datatype ct) const
virtual

Find a resolution compatible with the given data-type.

If this data-type has an alternate data-type form that matches the given data-type, return an index indicating this form, otherwise return -1.

Parameters
ctis the given data-type
Returns
the index of the matching form or -1

Reimplemented in ghidra::TypeArray, ghidra::TypeStruct, ghidra::TypeUnion, and ghidra::TypePartialUnion.

Referenced by ghidra::TypeArray::findCompatibleResolve(), ghidra::TypeStruct::findCompatibleResolve(), ghidra::TypeUnion::findCompatibleResolve(), and ghidra::ActionSetCasts::tryResolutionAdjustment().

◆ findResolve()

Datatype * ghidra::Datatype::findResolve ( const PcodeOp op,
int4  slot 
)
virtual

Find a previously resolved sub-type.

This is the constant version of resolveInFlow. If a resulting subtype has already been calculated, for the particular read (slot >= 0) or write (slot == -1), then return it. Otherwise return the original data-type.

Parameters
opis the PcodeOp using the Varnode assigned with this data-type
slotis the slot reading or writing the Varnode
Returns
the resolved subtype or the original data-type

Reimplemented in ghidra::TypePointer, ghidra::TypeArray, ghidra::TypeStruct, ghidra::TypeUnion, and ghidra::TypePartialUnion.

Referenced by ghidra::ActionSetCasts::castOutput(), ghidra::TypePartialUnion::findResolve(), ghidra::Varnode::getHighTypeDefFacing(), ghidra::Varnode::getHighTypeReadFacing(), ghidra::Varnode::getTypeDefFacing(), ghidra::Varnode::getTypeReadFacing(), and ghidra::PrintC::pushPartialSymbol().

◆ findTruncation()

const TypeField * ghidra::Datatype::findTruncation ( int8  off,
int4  sz,
const PcodeOp op,
int4  slot,
int8 &  newoff 
) const
virtual

Find an immediate subfield of this data-type.

Given a byte range within this data-type, determine the field it is contained in and pass back the renormalized offset. This method applies to TYPE_STRUCT, TYPE_UNION, and TYPE_PARTIALUNION, data-types that have field components. For TYPE_UNION and TYPE_PARTIALUNION, the field may depend on the p-code op extracting or writing the value.

Parameters
offis the byte offset into this
szis the size of the byte range
opis the PcodeOp reading/writing the data-type
slotis the index of the Varnode being accessed, -1 for the output, >=0 for an input
newoffpoints to the renormalized offset to pass back
Returns
the containing field or NULL if the range is not contained

Reimplemented in ghidra::TypeStruct, ghidra::TypePartialUnion, and ghidra::TypeUnion.

Referenced by ghidra::TypeOpSubpiece::getOutputToken(), ghidra::PrintC::opPtrsub(), ghidra::PrintC::opSubpiece(), and ghidra::PrintC::pushPartialSymbol().

◆ getDepend()

virtual Datatype * ghidra::Datatype::getDepend ( int4  index) const
inlinevirtual

Get a specific component sub-type by index.

Parameters
indexis the index specifying which sub-type to return
Returns
the i-th component sub-type

Reimplemented in ghidra::TypePointer, ghidra::TypeArray, ghidra::TypeStruct, ghidra::TypeUnion, and ghidra::TypePartialUnion.

Referenced by isPrimitiveWhole(), ghidra::TypeFactory::orderRecurse(), ghidra::ResolvedUnion::ResolvedUnion(), ghidra::ScoreUnionFields::ScoreUnionFields(), and ghidra::ActionSetCasts::tryResolutionAdjustment().

◆ getDisplayFormat()

uint4 ghidra::Datatype::getDisplayFormat ( void  ) const
inline

Get the display format for constants with this data-type.

A non-zero result indicates the type of formatting that is forced on the constant. One of the following values is returned.

  • 1 for hexadecimal
  • 2 for decimal
  • 3 for octal
  • 4 for binary
  • 5 for char
Returns
the forced encoding type or zero

References flags, and force_format.

Referenced by encodeBasic(), encodeTypedef(), ghidra::PrintC::push_integer(), and ghidra::PrintC::pushCharConstant().

◆ getHoleSize()

virtual int4 ghidra::Datatype::getHoleSize ( int4  off) const
inlinevirtual

Get number of bytes at the given offset that are padding.

For the given offset into this data-type, determine if the byte at that offset is considered padding, and if so, return the number of bytes in the padding. Otherwise, return 0.

Returns
the number of bytes of padding or 0

Reimplemented in ghidra::TypeArray, ghidra::TypeStruct, and ghidra::TypePartialStruct.

Referenced by ghidra::SplitDatatype::getComponent(), ghidra::TypeArray::getHoleSize(), ghidra::TypeStruct::getHoleSize(), and ghidra::TypePartialStruct::getHoleSize().

◆ getStripped()

Datatype * ghidra::Datatype::getStripped ( void  ) const
virtual

Get a stripped version of this for formal use in formal declarations.

Some data-types are ephemeral, and, in the final decompiler output, get replaced with a formal version that is a stripped down version of the original. This method returns this stripped down version, if it exists, or null otherwise. A non-null return should correspond with hasStripped returning true.

Returns
the stripped version or null

Reimplemented in ghidra::TypePartialEnum, ghidra::TypePartialStruct, ghidra::TypePartialUnion, and ghidra::TypePointerRel.

Referenced by ghidra::Scope::addSymbol(), ghidra::TypeFactory::getTypeArray(), ghidra::TypeFactory::getTypePointer(), ghidra::TypeFactory::getTypePointer(), ghidra::TypeFactory::getTypePointerStripArray(), ghidra::TypeFactory::resizePointer(), and ghidra::ScopeInternal::retypeSymbol().

◆ getSubType()

Datatype * ghidra::Datatype::getSubType ( int8  off,
int8 *  newoff 
) const
virtual

Recover component data-type one-level down.

Given an offset into this data-type, return the component data-type at that offset. Also, pass back a "renormalized" offset suitable for recursize getSubType() calls: i.e. if the original offset hits the exact start of the sub-type, 0 is passed back. If there is no valid component data-type at the offset, return NULL and pass back the original offset

Parameters
offis the offset into this data-type
newoffis a pointer to the passed-back offset
Returns
a pointer to the component data-type or NULL

Reimplemented in ghidra::TypePointer, ghidra::TypeArray, ghidra::TypeStruct, ghidra::TypePartialStruct, ghidra::TypeCode, and ghidra::TypeSpacebase.

Referenced by ghidra::RuleStructOffset0::applyOp(), ghidra::SplitDatatype::buildPointers(), ghidra::PrintC::checkAddressOfCast(), ghidra::StringSequence::constructTypedPointer(), ghidra::RulePieceStructure::convertZextToPiece(), ghidra::ScoreUnionFields::derefPointer(), ghidra::RulePieceStructure::determineDatatype(), ghidra::TypePointer::downChain(), ghidra::TypePartialUnion::findResolve(), ghidra::SplitDatatype::getComponent(), ghidra::TypeFactory::getExactPiece(), ghidra::TypePointerRel::getPtrToFromParent(), ghidra::TypePointer::getSubType(), ghidra::TypeArray::getSubType(), ghidra::TypeStruct::getSubType(), ghidra::TypePartialStruct::getSubType(), ghidra::AddTreeState::hasMatchingSubType(), ghidra::TypePointer::isPtrsubMatching(), ghidra::TypeOpPiece::propagateType(), ghidra::TypeOpSubpiece::propagateType(), ghidra::RangeHint::reconcile(), ghidra::TypePartialUnion::resolveInFlow(), ghidra::ScoreUnionFields::scoreTruncation(), ghidra::RulePieceStructure::spanningRange(), and ghidra::StringSequence::StringSequence().

◆ getUnsizedId()

uint8 ghidra::Datatype::getUnsizedId ( void  ) const
inline

Get the type id, without variable length size adjustment.

If the data-type is variable length, the working id for the data-type has a contribution based on the specific size of this instance. This contribution is removed, and the base id is returned. If the data-type is not variable length, the unaltered id is returned.

Returns
the base id of the data-type

References flags, hashSize(), id, size, and variable_length.

Referenced by encodeBasic(), ghidra::ArchitectureGhidra::getStringData(), ghidra::EmitMarkup::tagField(), and ghidra::EmitMarkup::tagType().

◆ hashName()

uint8 ghidra::Datatype::hashName ( const string &  nm)
staticprotected

◆ hashSize()

uint8 ghidra::Datatype::hashSize ( uint8  id,
int4  size 
)
staticprotected

Reversibly hash size into id.

This allows IDs for variable length structures to be uniquefied based on size. A base ID is given and a size of the specific instance. A unique ID is returned. The hashing is reversible by feeding the output ID back into this function with the same size.

Parameters
idis the given ID to (de)uniquify
sizeis the instance size of the structure
Returns
the (de)uniquified id

References id, and size.

Referenced by decodeBasic(), ghidra::TypeFactory::decodeTypedef(), encodeRef(), ghidra::TypeFactory::findById(), getUnsizedId(), and hasSameVariableBase().

◆ hasSameVariableBase()

bool ghidra::Datatype::hasSameVariableBase ( const Datatype ct) const

Are these the same variable length data-type.

If this and the other given data-type are both variable length and come from the the same base data-type, return true.

Parameters
ctis the other given data-type to compare with this
Returns
true if they are the same variable length data-type.

References hashSize(), id, isVariableLength(), and size.

Referenced by ghidra::CastStrategyC::castStandard().

◆ isPieceStructured()

bool ghidra::Datatype::isPieceStructured ( void  ) const
inline

Does this data-type consist of separate pieces?

If a value with this data-type is put together from multiple pieces, is it better to display this construction as a sequence of separate assignments or as a single concatenation. Generally a TYPE_STRUCT or TYPE_ARRAY should be represented with separate assignments.

Returns
true if the data-type is put together with multiple assignments

References metatype, and ghidra::TYPE_ARRAY.

Referenced by ghidra::RuleSubRight::applyOp(), ghidra::RulePieceStructure::determineDatatype(), ghidra::Varnode::getStructuredType(), isPrimitiveWhole(), ghidra::PrintC::opSubpiece(), ghidra::RulePieceStructure::separateSymbol(), and ghidra::RulePieceStructure::spanningRange().

◆ isPrimitiveWhole()

bool ghidra::Datatype::isPrimitiveWhole ( void  ) const

Is this made up of a single primitive.

If this has no component data-types, return true. If this has only a single primitive component filling the whole data-type, also return true.

Returns
true if this data-type is made up of a single primitive

References getDepend(), getSize(), isPieceStructured(), isPrimitiveWhole(), metatype, numDepend(), ghidra::TYPE_ARRAY, and ghidra::TYPE_STRUCT.

Referenced by ghidra::ActionParamDouble::apply(), ghidra::RuleDoubleIn::attemptMarking(), ghidra::RuleDoubleOut::attemptMarking(), isPrimitiveWhole(), ghidra::Heritage::splitJoinRead(), and ghidra::Heritage::splitJoinWrite().

◆ isPtrsubMatching()

bool ghidra::Datatype::isPtrsubMatching ( int8  off,
int8  extra,
int8  multiplier 
) const
virtual

Is this data-type suitable as input to a CPUI_PTRSUB op.

A CPUI_PTRSUB must act on a pointer data-type where the given offset addresses a component. Perform this check.

Parameters
offis the given offset
extrais any additional constant being added to the pointer
multiplieris the size of any index multiplier being added to the pointer
Returns
true if this is a suitable PTRSUB data-type

Reimplemented in ghidra::TypePointer, and ghidra::TypePointerRel.

Referenced by ghidra::ActionSetCasts::apply(), and ghidra::RulePtrsubUndo::applyOp().

◆ nearestArrayedComponentBackward()

Datatype * ghidra::Datatype::nearestArrayedComponentBackward ( int8  off,
int8 *  newoff,
int8 *  elSize 
) const
virtual

Find the last component data-type that is (or contains) an array starting before the given offset, and pass back the difference between the component's start and the given offset. Return the component data-type or null if no array is found.

Parameters
offis the given offset into this data-type
newoffis used to pass back the offset difference
elSizeis used to pass back the array element size
Returns
the component data-type or null

Reimplemented in ghidra::TypeStruct, and ghidra::TypeSpacebase.

Referenced by ghidra::AddTreeState::hasMatchingSubType(), ghidra::TypeStruct::nearestArrayedComponentBackward(), ghidra::TypeSpacebase::nearestArrayedComponentBackward(), and ghidra::TypePointer::testForArraySlack().

◆ nearestArrayedComponentForward()

Datatype * ghidra::Datatype::nearestArrayedComponentForward ( int8  off,
int8 *  newoff,
int8 *  elSize 
) const
virtual

Find the first component data-type that is (or contains) an array starting after the given offset, and pass back the difference between the component's start and the given offset. Return the component data-type or null if no array is found.

Parameters
offis the given offset into this data-type
newoffis used to pass back the offset difference
elSizeis used to pass back the array element size
Returns
the component data-type or null

Reimplemented in ghidra::TypeStruct, and ghidra::TypeSpacebase.

Referenced by ghidra::AddTreeState::hasMatchingSubType(), ghidra::TypeStruct::nearestArrayedComponentForward(), ghidra::TypeSpacebase::nearestArrayedComponentForward(), and ghidra::TypePointer::testForArraySlack().

◆ numDepend()

virtual int4 ghidra::Datatype::numDepend ( void  ) const
inlinevirtual

◆ printNameBase()

virtual void ghidra::Datatype::printNameBase ( ostream &  s) const
inlinevirtual

Print (part of) the name of this data-type as short prefix for a label.

This is used for building variable names to give some indication of the variable's underlying data-type

Parameters
sis the stream write the name prefix to

Reimplemented in ghidra::TypePointer, and ghidra::TypeArray.

References name.

Referenced by ghidra::ScopeInternal::buildVariableName(), ghidra::ScopeLocal::buildVariableName(), ghidra::TypePointer::printNameBase(), and ghidra::TypeArray::printNameBase().

◆ printRaw()

void ghidra::Datatype::printRaw ( ostream &  s) const
virtual

◆ resolveInFlow()

Datatype * ghidra::Datatype::resolveInFlow ( PcodeOp op,
int4  slot 
)
virtual

Tailor data-type propagation based on Varnode use.

For certain data-types, particularly union, variables of that data-type are transformed into a subtype depending on the particular use. Each read or write of the variable may use a different subtype. This method returns the particular subtype required based on a specific PcodeOp. A slot index >=0 indicates which operand reads the variable, or if the index is -1, the variable is written.

Parameters
opis the specific PcodeOp
slotindicates the input operand, or the output
Returns
the resolved sub-type

Reimplemented in ghidra::TypePointer, ghidra::TypeArray, ghidra::TypeStruct, ghidra::TypeUnion, and ghidra::TypePartialUnion.

Referenced by ghidra::RulePieceStructure::applyOp(), ghidra::ActionSetCasts::castOutput(), ghidra::ActionInferTypes::propagateTypeEdge(), and ghidra::ActionSetCasts::resolveUnion().

◆ resolveTruncation()

const TypeField * ghidra::Datatype::resolveTruncation ( int8  offset,
PcodeOp op,
int4  slot,
int8 &  newoff 
)
virtual

Resolve which union field is being used for a given PcodeOp when a truncation is involved.

This method applies to the TYPE_UNION and TYPE_PARTIALUNION data-types, when a Varnode is backed by a larger Symbol with a union data-type, or if the Varnode is produced by a CPUI_SUBPIECE where the input Varnode has a union data-type. Scoring is done to compute the best field and the result is cached with the function. The record of the best field is returned or null if there is no appropriate field

Parameters
offsetis the byte offset into the union we are truncating to
opis either the PcodeOp reading the truncated Varnode or the CPUI_SUBPIECE doing the truncation
slotis either the input slot of the reading PcodeOp or the artificial SUBPIECE slot: 1
newoffis used to pass back how much offset is left to resolve
Returns
the field of the union best associated with the truncation or null

Reimplemented in ghidra::TypePartialUnion, and ghidra::TypeUnion.

Referenced by ghidra::TypeOpSubpiece::propagateType(), and ghidra::TypePartialUnion::resolveInFlow().

◆ setDisplayFormat()

void ghidra::Datatype::setDisplayFormat ( uint4  format)
inlineprotected

Set a specific display format.

The display format for the data-type is changed based on the given format. A value of zero clears any preexisting format. Otherwise the value can be one of: 1=hex, 2=dec, 3=oct, 4=bin, 5=char

Parameters
formatis the given format

References flags, and force_format.

Referenced by decodeBasic(), ghidra::TypeFactory::getTypedef(), and ghidra::TypeFactory::setDisplayFormat().

◆ typeOrderBool()

int4 ghidra::Datatype::typeOrderBool ( const Datatype op) const
inline

Order this with -op-, treating bool data-type as special.

Order data-types, with special handling of the bool data-type. Data-types are compared using the normal ordering, but bool is ordered after all other data-types. A return value of 0 indicates the data-types are the same, -1 indicates that this is prefered (ordered earlier), and 1 indicates this is ordered later.

Parameters
opis the other data-type to compare with this
Returns
-1, 0, or 1

References compare(), metatype, and ghidra::TYPE_BOOL.

Referenced by ghidra::HighVariable::getTypeRepresentative().

Member Data Documentation

◆ base2sub

sub_metatype ghidra::Datatype::base2sub
staticprotected
Initial value:
= {
}
@ SUB_BOOL
Compare as TYPE_BOOL.
Definition type.hh:117
@ SUB_FLOAT
Compare as TYPE_FLOAT.
Definition type.hh:119
@ SUB_CODE
Compare as TYPE_CODE.
Definition type.hh:118
@ SUB_UNION
Compare as TYPE_UNION.
Definition type.hh:126
@ SUB_PARTIALSTRUCT
Compare as TYPE_PARTIALSTRUCT.
Definition type.hh:107
@ SUB_ARRAY
Compare as TYPE_ARRAY.
Definition type.hh:124
@ SUB_PARTIALUNION
Compare as a TYPE_PARTIALUNION.
Definition type.hh:127
@ SUB_UNKNOWN
Compare as a TYPE_UNKNOWN.
Definition type.hh:106
@ SUB_UINT_ENUM
Unsigned enum, sub-type of TYPE_UINT.
Definition type.hh:114
@ SUB_INT_PLAIN
Compare as a plain TYPE_INT.
Definition type.hh:110
@ SUB_VOID
Compare as a TYPE_VOID.
Definition type.hh:104
@ SUB_INT_ENUM
Signed enum, sub-type of TYPE_INT.
Definition type.hh:112
@ SUB_UINT_PARTIALENUM
Unsigned partial enum, sub-type of TYPE_UINT.
Definition type.hh:113
@ SUB_STRUCT
Compare as TYPE_STRUCT.
Definition type.hh:125
@ SUB_UINT_PLAIN
Compare as a plain TYPE_UINT.
Definition type.hh:111
@ SUB_SPACEBASE
Compare as a TYPE_SPACEBASE.
Definition type.hh:105
@ SUB_PTRREL
Pointer relative to another data-type, sub-type of TYPE_PTR.
Definition type.hh:122
@ SUB_PTR
Compare as TYPE_PTR.
Definition type.hh:121

The base propagation ordering associated with each meta-type. The array elements correspond to the ordering of type_metatype.

Referenced by Datatype(), and decodeBasic().


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