Ghidra 11.3.2
Ghidra internal decompiler documentation.
|
Container class for all Datatype objects in an Architecture. More...
#include <type.hh>
Public Member Functions | |
TypeFactory (Architecture *g) | |
Construct a factory. | |
void | setupSizes (void) |
Derive some size information from Architecture. | |
void | clear (void) |
Clear out all types. | |
void | clearNoncore (void) |
Clear out non-core types. | |
virtual | ~TypeFactory (void) |
Destructor. | |
int4 | getAlignment (uint4 size) const |
Get data-type alignment based on size. | |
int4 | getPrimitiveAlignSize (uint4 size) const |
Get the aligned size of a primitive data-type. | |
int4 | getSizeOfInt (void) const |
Get the size of the default "int". | |
int4 | getSizeOfLong (void) const |
Get the size of the default "long". | |
int4 | getSizeOfChar (void) const |
Get the size of the default "char". | |
int4 | getSizeOfWChar (void) const |
Get the size of the default "wchar_t". | |
int4 | getSizeOfPointer (void) const |
Get the size of pointers. | |
int4 | getSizeOfAltPointer (void) const |
Get size of alternate pointers (or 0) | |
Architecture * | getArch (void) const |
Get the Architecture object. | |
Datatype * | findByName (const string &n) |
Return type of given name. | |
Datatype * | setName (Datatype *ct, const string &n) |
Set the given types name. | |
void | setDisplayFormat (Datatype *ct, uint4 format) |
Set the display format associated with the given data-type. | |
void | setFields (const vector< TypeField > &fd, TypeStruct *ot, int4 newSize, int4 newAlign, uint4 flags) |
Set fields on a TypeStruct. | |
void | setFields (const vector< TypeField > &fd, TypeUnion *ot, int4 newSize, int4 newAlign, uint4 flags) |
Set fields on a TypeUnion. | |
void | setPrototype (const FuncProto *fp, TypeCode *newCode, uint4 flags) |
Set the prototype on a TypeCode. | |
void | setEnumValues (const map< uintb, string > &nmap, TypeEnum *te) |
Set named values for an enumeration. | |
Datatype * | decodeType (Decoder &decoder) |
Restore Datatype from a stream. | |
Datatype * | decodeTypeWithCodeFlags (Decoder &decoder, bool isConstructor, bool isDestructor) |
Restore data-type from an element and extra "code" flags. | |
TypeVoid * | getTypeVoid (void) |
Get the "void" data-type. | |
Datatype * | getBaseNoChar (int4 s, type_metatype m) |
Get atomic type excluding "char". | |
Datatype * | getBase (int4 s, type_metatype m) |
Get atomic type. | |
Datatype * | getBase (int4 s, type_metatype m, const string &n) |
Get named atomic type. | |
Datatype * | getTypeChar (int4 s) |
Get a character data-type by size. | |
TypeCode * | getTypeCode (void) |
Get an "anonymous" function data-type. | |
TypePointer * | getTypePointerStripArray (int4 s, Datatype *pt, uint4 ws) |
Construct a pointer data-type, stripping an ARRAY level. | |
TypePointer * | getTypePointer (int4 s, Datatype *pt, uint4 ws) |
Construct an absolute pointer data-type. | |
TypePointer * | getTypePointer (int4 s, Datatype *pt, uint4 ws, const string &n) |
Construct a named pointer data-type. | |
TypeArray * | getTypeArray (int4 as, Datatype *ao) |
Construct an array data-type. | |
TypeStruct * | getTypeStruct (const string &n) |
Create an (empty) structure. | |
TypePartialStruct * | getTypePartialStruct (Datatype *contain, int4 off, int4 sz) |
Create a partial structure. | |
TypeUnion * | getTypeUnion (const string &n) |
Create an (empty) union. | |
TypePartialUnion * | getTypePartialUnion (TypeUnion *contain, int4 off, int4 sz) |
Create a partial union. | |
TypeEnum * | getTypeEnum (const string &n) |
Create an (empty) enumeration. | |
TypePartialEnum * | getTypePartialEnum (TypeEnum *contain, int4 off, int4 sz) |
Create a partial enumeration. | |
TypeSpacebase * | getTypeSpacebase (AddrSpace *id, const Address &addr) |
Create a "spacebase" type. | |
TypeCode * | getTypeCode (const PrototypePieces &proto) |
Create a "function" datatype. | |
Datatype * | getTypedef (Datatype *ct, const string &name, uint8 id, uint4 format) |
Create a new typedef data-type. | |
TypePointerRel * | getTypePointerRel (TypePointer *parentPtr, Datatype *ptrTo, int4 off) |
Get pointer offset relative to a container. | |
TypePointerRel * | getTypePointerRel (int4 sz, Datatype *parent, Datatype *ptrTo, int4 ws, int4 off, const string &nm) |
Build a named pointer offset into a larger container. | |
TypePointer * | getTypePointerWithSpace (Datatype *ptrTo, AddrSpace *spc, const string &nm) |
Build a named pointer with an address space attribute. | |
TypePointer * | resizePointer (TypePointer *ptr, int4 newSize) |
Build a resized pointer based on the given pointer. | |
Datatype * | getExactPiece (Datatype *ct, int4 offset, int4 size) |
Get the data-type associated with piece of a structured data-type. | |
void | destroyType (Datatype *ct) |
Remove a data-type from this. | |
Datatype * | concretize (Datatype *ct) |
Convert given data-type to concrete form. | |
void | dependentOrder (vector< Datatype * > &deporder) const |
Place all data-types in dependency order. | |
void | encode (Encoder &encoder) const |
Encode this container to stream. | |
void | encodeCoreTypes (Encoder &encoder) const |
Encode core types to stream. | |
void | decode (Decoder &decoder) |
Decode this from a <typegrp> element. | |
void | decodeCoreTypes (Decoder &decoder) |
Initialize basic data-types from a stream. | |
void | decodeDataOrganization (Decoder &decoder) |
Parse a <data_organization> element. | |
void | parseEnumConfig (Decoder &decoder) |
Parse the <enum> tag. | |
void | setCoreType (const string &name, int4 size, type_metatype meta, bool chartp) |
Create a core data-type. | |
void | cacheCoreTypes (void) |
Cache common types. | |
list< DatatypeWarning >::const_iterator | beginWarnings (void) const |
Start of data-type warnings. | |
list< DatatypeWarning >::const_iterator | endWarnings (void) const |
End of data-type warnings. | |
Protected Member Functions | |
Datatype * | findByIdLocal (const string &nm, uint8 id) const |
Search locally by name and id. | |
virtual Datatype * | findById (const string &n, uint8 id, int4 sz) |
Search by name and/or id. | |
Protected Attributes | |
Architecture * | glb |
The Architecture object that owns this TypeFactory. | |
Private Member Functions | |
Datatype * | findNoName (Datatype &ct) |
Find data-type (in this container) by function. | |
void | insert (Datatype *newtype) |
Insert pointer into the cross-reference sets. | |
Datatype * | findAdd (Datatype &ct) |
Find data-type in this container or add it. | |
void | orderRecurse (vector< Datatype * > &deporder, DatatypeSet &mark, Datatype *ct) const |
Write out dependency list. | |
void | decodeAlignmentMap (Decoder &decoder) |
Parse a <size_alignment_map> element. | |
void | setDefaultAlignmentMap (void) |
Provide default alignments for data-types. | |
Datatype * | decodeTypedef (Decoder &decoder) |
Restore a <def> element describing a typedef. | |
Datatype * | decodeEnum (Decoder &decoder, bool forcecore) |
Restore a <type> element describing an enumeration. | |
Datatype * | decodeStruct (Decoder &decoder, bool forcecore) |
Restore a <type> element describing a structure. | |
Datatype * | decodeUnion (Decoder &decoder, bool forcecore) |
Restore a <type> element describing a union. | |
Datatype * | decodeCode (Decoder &decoder, bool isConstructor, bool isDestructor, bool forcecore) |
Restore an element describing a code object. | |
Datatype * | decodeTypeNoRef (Decoder &decoder, bool forcecore) |
Restore from a stream. | |
void | clearCache (void) |
Clear the common type cache. | |
TypeChar * | getTypeChar (const string &n) |
Create a default "char" type. | |
TypeUnicode * | getTypeUnicode (const string &nm, int4 sz, type_metatype m) |
Create a default "unicode" type. | |
TypeCode * | getTypeCode (const string &n) |
Create a default "code" type. | |
void | recalcPointerSubmeta (Datatype *base, sub_metatype sub) |
Recalculate submeta for pointers to given base data-type. | |
void | insertWarning (Datatype *dt, string warn) |
Register a new data-type warning with this factory. | |
void | removeWarning (Datatype *dt) |
Remove the warning associated with the given data-type. | |
void | resolveIncompleteTypedefs (void) |
Redefine incomplete typedefs of data-types that are now complete. | |
Private Attributes | |
int4 | sizeOfInt |
Size of the core "int" data-type. | |
int4 | sizeOfLong |
Size of the core "long" data-type. | |
int4 | sizeOfChar |
Size of the core "char" data-type. | |
int4 | sizeOfWChar |
Size of the core "wchar_t" data-type. | |
int4 | sizeOfPointer |
Size of pointers (into default data address space) | |
int4 | sizeOfAltPointer |
Size of alternate pointers used by architecture (if not 0) | |
int4 | enumsize |
Size of an enumerated type. | |
type_metatype | enumtype |
Default enumeration meta-type (when parsing C) | |
vector< int4 > | alignMap |
Alignment of primitive data-types based on their size. | |
DatatypeSet | tree |
Datatypes within this factory (sorted by function) | |
DatatypeNameSet | nametree |
Cross-reference by name. | |
Datatype * | typecache [9][8] |
Matrix of the most common atomic data-types. | |
Datatype * | typecache10 |
Specially cached 10-byte float type. | |
Datatype * | typecache16 |
Specially cached 16-byte float type. | |
Datatype * | type_nochar |
Same dimensions as char but acts and displays as an INT. | |
Datatype * | charcache [5] |
Cached character data-types. | |
list< DatatypeWarning > | warnings |
Warnings for the user about data-types in this factory. | |
list< Datatype * > | incompleteTypedef |
Incomplete data-types defined as a typedef. | |
Container class for all Datatype objects in an Architecture.
ghidra::TypeFactory::TypeFactory | ( | Architecture * | g | ) |
Construct a factory.
Initialize an empty container
g | is the owning Architecture |
References clearCache(), enumsize, glb, sizeOfAltPointer, sizeOfChar, sizeOfInt, sizeOfLong, sizeOfPointer, and sizeOfWChar.
void ghidra::TypeFactory::cacheCoreTypes | ( | void | ) |
Cache common types.
Run through the list of "core" data-types and cache the most commonly accessed ones for quick access (avoiding the tree lookup). The "core" data-types must have been previously initialized.
References charcache, ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::Datatype::isASCII(), ghidra::Datatype::isCharPrint(), ghidra::Datatype::isCoreType(), ghidra::Datatype::isEnumType(), tree, ghidra::TYPE_BOOL, ghidra::TYPE_CODE, ghidra::TYPE_FLOAT, ghidra::TYPE_INT, type_nochar, ghidra::TYPE_UINT, ghidra::TYPE_UNKNOWN, ghidra::TYPE_VOID, typecache, typecache10, and typecache16.
Referenced by ghidra::ArchitectureGhidra::buildCoreTypes(), and decodeCoreTypes().
void ghidra::TypeFactory::clear | ( | void | ) |
Clear out all types.
Remove all Datatype objects owned by this TypeFactory.
References clearCache(), incompleteTypedef, nametree, tree, and warnings.
Referenced by decodeCoreTypes(), and ~TypeFactory().
|
private |
Clear the common type cache.
Clear the matrix of commonly used atomic types.
References charcache, type_nochar, typecache, typecache10, and typecache16.
Referenced by clear(), and TypeFactory().
void ghidra::TypeFactory::clearNoncore | ( | void | ) |
Clear out non-core types.
Delete anything that isn't a core type.
References incompleteTypedef, ghidra::Datatype::isCoreType(), nametree, tree, and warnings.
Referenced by ghidra::FlushNative::rawAction().
Convert given data-type to concrete form.
The data-type propagation system can push around data-types that are partial or are otherwise unrepresentable in the source language. This method substitutes those data-types with a concrete data-type that is representable, or returns the same data-type if is already concrete. Its important that the returned data-type have the same size as the original data-type regardless.
ct | is the given data-type |
References getBase(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::TYPE_CODE, and ghidra::TYPE_UNKNOWN.
Referenced by ghidra::ScopeLocal::createEntry().
void ghidra::TypeFactory::decode | ( | Decoder & | decoder | ) |
Decode this from a <typegrp> element.
Scan configuration parameters of the factory and parse elements describing data-types into this container.
decoder | is the stream decoder |
References ghidra::Decoder::closeElement(), decodeTypeNoRef(), ghidra::Decoder::openElement(), and ghidra::Decoder::peekElement().
Referenced by ghidra::Architecture::restoreXml().
|
private |
Parse a <size_alignment_map> element.
Recover the map from data-type size to preferred alignment.
decoder | is the stream decoder |
References alignMap, ghidra::Decoder::closeElement(), ghidra::Decoder::openElement(), and ghidra::Decoder::readSignedInteger().
Referenced by decodeDataOrganization().
|
private |
Restore an element describing a code object.
If necessary create a stub object before parsing the prototype description, to deal with recursive definitions
decoder | is the stream decoder |
isConstructor | is true if any prototype should be treated as a constructor |
isDestructor | is true if any prototype should be treated as a destructor |
forcecore | is true if the data-type is considered core |
References ghidra::Datatype::compareDependency(), ghidra::Datatype::coretype, ghidra::TypeCode::decodePrototype(), ghidra::TypeCode::decodeStub(), findAdd(), findByIdLocal(), ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::id, ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, ghidra::TypeCode::proto, resolveIncompleteTypedefs(), setPrototype(), and ghidra::TYPE_CODE.
Referenced by decodeTypeNoRef(), and decodeTypeWithCodeFlags().
void ghidra::TypeFactory::decodeCoreTypes | ( | Decoder & | decoder | ) |
Initialize basic data-types from a stream.
Parse data-type elements into this container. This stream is presumed to contain "core" datatypes and the cached matrix will be populated from this set.
decoder | is the stream decoder |
References cacheCoreTypes(), clear(), ghidra::Decoder::closeElement(), decodeTypeNoRef(), ghidra::Decoder::openElement(), and ghidra::Decoder::peekElement().
Referenced by ghidra::ArchitectureGhidra::buildCoreTypes().
void ghidra::TypeFactory::decodeDataOrganization | ( | Decoder & | decoder | ) |
Parse a <data_organization> element.
Recover various sizes relevant to this container, such as the default size of "int" and structure alignment, by parsing a <data_organization> element.
decoder | is the stream decoder |
References ghidra::Decoder::closeElement(), ghidra::Decoder::closeElementSkipping(), decodeAlignmentMap(), ghidra::Decoder::openElement(), ghidra::Decoder::readSignedInteger(), sizeOfChar, sizeOfInt, sizeOfLong, sizeOfPointer, and sizeOfWChar.
Referenced by ghidra::Architecture::parseCompilerConfig().
Restore a <type> element describing an enumeration.
decoder | is the stream decoder |
forcecore | is true if the data-type is considered core |
References ghidra::Datatype::coretype, ghidra::TypeEnum::decode(), findAdd(), ghidra::Datatype::flags, insertWarning(), and ghidra::TYPE_ENUM_INT.
Referenced by decodeTypeNoRef().
Restore a <type> element describing a structure.
If necessary create a stub object before parsing the field descriptions, to deal with recursive definitions
decoder | is the stream decoder |
forcecore | is true if the data-type is considered core |
References ghidra::Datatype::alignment, ghidra::Datatype::compareDependency(), ghidra::Datatype::coretype, ghidra::Datatype::decodeBasic(), ghidra::TypeStruct::decodeFields(), ghidra::TypeStruct::field, findAdd(), findByIdLocal(), ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::id, insertWarning(), ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, resolveIncompleteTypedefs(), setFields(), ghidra::Datatype::size, and ghidra::TYPE_STRUCT.
Referenced by decodeTypeNoRef().
Restore Datatype from a stream.
Restore a Datatype object from an element: either <type>, <typeref>, or <void>
decoder | is the stream decoder |
References ghidra::Decoder::closeElement(), decodeTypeNoRef(), findById(), ghidra::Decoder::getNextAttributeId(), ghidra::Datatype::hashName(), ghidra::Decoder::openElement(), ghidra::Decoder::peekElement(), ghidra::Decoder::readSignedInteger(), ghidra::Decoder::readString(), and ghidra::Decoder::readUnsignedInteger().
Referenced by ghidra::FuncProto::decode(), ghidra::ProtoStoreInternal::decode(), ghidra::CPoolRecord::decode(), ghidra::TypePointer::decode(), ghidra::TypeArray::decode(), ghidra::TypePointerRel::decode(), ghidra::Symbol::decodeBody(), decodeTypedef(), ghidra::TypeFactoryGhidra::findById(), and ghidra::TypeField::TypeField().
Restore a <def> element describing a typedef.
Scan the new id and name. A subtag references the data-type being typedefed. Construct the new data-type based on the referenced data-type but with new name and id.
decoder | is the stream decoder |
References ghidra::Datatype::alignment, decodeType(), ghidra::Datatype::encodeIntegerFormat(), ghidra::TypeStruct::field, ghidra::TypeUnion::field, findByIdLocal(), ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Decoder::getNextAttributeId(), getTypedef(), ghidra::Datatype::getTypedef(), ghidra::Datatype::hashName(), ghidra::Datatype::hashSize(), ghidra::Datatype::isVariableLength(), ghidra::Datatype::name, ghidra::Decoder::readString(), ghidra::Decoder::readUnsignedInteger(), setFields(), ghidra::Datatype::size, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
Referenced by decodeTypeNoRef().
Restore from a stream.
Restore a Datatype object from a <type> element. (Don't use for <typeref> elements) The new Datatype is added to this container.
decoder | is the stream decoder |
forcecore | is true if the new type should be labeled as a core type |
References ghidra::Decoder::closeElement(), ghidra::Datatype::coretype, ghidra::TypeChar::decode(), ghidra::TypeUnicode::decode(), ghidra::TypeVoid::decode(), ghidra::TypePointer::decode(), ghidra::TypeArray::decode(), ghidra::TypePointerRel::decode(), ghidra::TypeSpacebase::decode(), ghidra::Datatype::decodeBasic(), decodeCode(), decodeEnum(), decodeStruct(), decodeTypedef(), decodeUnion(), findAdd(), ghidra::Datatype::flags, ghidra::Decoder::getNextAttributeId(), getTypeVoid(), glb, ghidra::Decoder::openElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readString(), ghidra::Decoder::rewindAttributes(), ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, ghidra::TYPE_ENUM_INT, ghidra::TYPE_ENUM_UINT, ghidra::TYPE_PTR, ghidra::TYPE_PTRREL, ghidra::TYPE_SPACEBASE, ghidra::TYPE_STRUCT, ghidra::TYPE_UNION, ghidra::TYPE_UNKNOWN, and ghidra::TYPE_VOID.
Referenced by decode(), decodeCoreTypes(), and decodeType().
Datatype * ghidra::TypeFactory::decodeTypeWithCodeFlags | ( | Decoder & | decoder, |
bool | isConstructor, | ||
bool | isDestructor | ||
) |
Restore data-type from an element and extra "code" flags.
Kludge to get flags into code pointer types, when they can't come through the stream
decoder | is the stream decoder |
isConstructor | toggles "constructor" property on "function" datatypes |
isDestructor | toggles "destructor" property on "function" datatypes |
References ghidra::TypePointer::calcTruncate(), ghidra::Decoder::closeElement(), ghidra::Datatype::decodeBasic(), decodeCode(), findAdd(), ghidra::Datatype::getMetatype(), ghidra::Decoder::getNextAttributeId(), ghidra::Decoder::openElement(), ghidra::TypePointer::ptrto, ghidra::Decoder::readUnsignedInteger(), ghidra::TYPE_PTR, and ghidra::TypePointer::wordsize.
Referenced by ghidra::CPoolRecord::decode().
Restore a <type> element describing a union.
If necessary create a stub object before parsing the field descriptions, to deal with recursive definitions
decoder | is the stream decoder |
forcecore | is true if the data-type is considered core |
References ghidra::Datatype::alignment, ghidra::Datatype::compareDependency(), ghidra::Datatype::coretype, ghidra::Datatype::decodeBasic(), ghidra::TypeUnion::decodeFields(), ghidra::TypeUnion::field, findAdd(), findByIdLocal(), ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::id, ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, resolveIncompleteTypedefs(), setFields(), ghidra::Datatype::size, and ghidra::TYPE_UNION.
Referenced by decodeTypeNoRef().
void ghidra::TypeFactory::dependentOrder | ( | vector< Datatype * > & | deporder | ) | const |
Place all data-types in dependency order.
Place data-types in an order such that if the definition of data-type "a" depends on the definition of data-type "b", then "b" occurs earlier in the order
deporder | will hold the generated dependency list of data-types |
References orderRecurse(), and tree.
Referenced by ghidra::PrintC::docTypeDefinitions(), and encode().
void ghidra::TypeFactory::destroyType | ( | Datatype * | ct | ) |
Remove a data-type from this.
The indicated Datatype object is removed from this container. Indirect references (via TypeArray TypeStruct etc.) are not affected
ct | is the data-type to destroy |
References ghidra::Datatype::hasWarning(), ghidra::Datatype::isCoreType(), nametree, removeWarning(), and tree.
void ghidra::TypeFactory::encode | ( | Encoder & | encoder | ) | const |
Encode this container to stream.
All data-types, in dependency order, are encoded to a stream
encoder | is the stream encoder |
References ghidra::Encoder::closeElement(), dependentOrder(), ghidra::Encoder::openElement(), ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
Referenced by ghidra::Architecture::encode().
void ghidra::TypeFactory::encodeCoreTypes | ( | Encoder & | encoder | ) | const |
Encode core types to stream.
Any data-type within this container marked as core will be encodeded as a <coretypes> element.
encoder | is the stream encoder |
References ghidra::Encoder::closeElement(), ghidra::Datatype::encode(), ghidra::Datatype::getMetatype(), ghidra::Datatype::isCoreType(), ghidra::Encoder::openElement(), tree, ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
Find data-type in this container or add it.
Use quickest method (name or id is possible) to locate the matching data-type. If its not currently in this container, clone the data-type and add it to the container.
ct | is the data-type to match |
References ghidra::Datatype::alignment, ghidra::Datatype::alignSize, ghidra::Datatype::clone(), ghidra::Datatype::compareDependency(), findByIdLocal(), findNoName(), getAlignment(), getPrimitiveAlignSize(), ghidra::Datatype::id, insert(), ghidra::Datatype::name, and ghidra::Datatype::size.
Referenced by decodeCode(), decodeEnum(), decodeStruct(), decodeTypeNoRef(), decodeTypeWithCodeFlags(), decodeUnion(), getBase(), getBase(), getTypeArray(), getTypeChar(), getTypeCode(), getTypeCode(), getTypeCode(), getTypeEnum(), getTypePartialEnum(), getTypePartialStruct(), getTypePartialUnion(), getTypePointer(), getTypePointer(), getTypePointerRel(), getTypePointerRel(), getTypePointerStripArray(), getTypePointerWithSpace(), getTypeSpacebase(), getTypeStruct(), getTypeUnicode(), getTypeUnion(), and resizePointer().
|
protectedvirtual |
Search by name and/or id.
The id is expected to resolve uniquely. Internally, different length instances of a variable length data-type are stored as separate Datatype objects. A non-zero size can be given to distinguish these cases. Derived classes may search outside this container.
n | is the name of the data-type |
id | is the type id of the data-type |
sz | is the given distinguishing size if non-zero |
Reimplemented in ghidra::TypeFactoryGhidra.
References findByIdLocal(), and ghidra::Datatype::hashSize().
Referenced by decodeType(), ghidra::TypeFactoryGhidra::findById(), and findByName().
|
protected |
Search locally by name and id.
Looking just within this container, find a Datatype by name and/or id.
n | is the name of the data-type |
id | is the type id of the data-type |
References ghidra::Datatype::id, nametree, and ghidra::TYPE_UNKNOWN.
Referenced by decodeCode(), decodeStruct(), decodeTypedef(), decodeUnion(), findAdd(), findById(), and getTypedef().
Datatype * ghidra::TypeFactory::findByName | ( | const string & | n | ) |
Return type of given name.
Find type with given name. If there are more than, return first.
n | is the name to search for |
References findById().
Find data-type (in this container) by function.
Find data-type without reference to name, using the functional comparators For this to work, the type must be built out of dependencies that are already present in this type factory
ct | is the data-type to match |
References tree.
Referenced by findAdd().
int4 ghidra::TypeFactory::getAlignment | ( | uint4 | size | ) | const |
Get data-type alignment based on size.
Return the alignment associated with a primitive data-type of the given size
size | is the aligned size in bytes of the primitive |
References alignMap.
Referenced by findAdd(), and getPrimitiveAlignSize().
Datatype * ghidra::TypeFactory::getBase | ( | int4 | s, |
type_metatype | m | ||
) |
Get atomic type.
Get one of the "base" datatypes. This routine is called a lot, so we go through a cache first.
s | is the desired size |
m | is the desired meta-type |
References findAdd(), getTypeArray(), glb, ghidra::Architecture::max_basetype_size, ghidra::TYPE_FLOAT, ghidra::TYPE_UNKNOWN, typecache, typecache10, and typecache16.
Referenced by ghidra::MapState::addFixedType(), ghidra::MapState::addGuard(), ghidra::RuleSubRight::applyOp(), ghidra::RuleExpandLoad::applyOp(), ghidra::CastStrategyC::arithmeticOutputStandard(), ghidra::SplitDatatype::buildPointers(), ghidra::HeapSequence::buildStringCopy(), ghidra::LabSymbol::buildType(), concretize(), ghidra::EquateSymbol::decode(), ghidra::ScopeInternal::decodeCollision(), ghidra::TypePointer::downChain(), ghidra::EquateSymbol::EquateSymbol(), ghidra::ScopeLocal::fakeInputSymbols(), getBaseNoChar(), ghidra::SplitDatatype::getComponent(), ghidra::TypeOp::getInputLocal(), ghidra::TypeOpBinary::getInputLocal(), ghidra::TypeOpUnary::getInputLocal(), ghidra::TypeOpFunc::getInputLocal(), ghidra::TypeOpCbranch::getInputLocal(), ghidra::TypeOpPtradd::getInputLocal(), ghidra::TypeOpPtrsub::getInputLocal(), ghidra::TypeOpCpoolref::getInputLocal(), ghidra::TypeOpInsert::getInputLocal(), ghidra::TypeOpExtract::getInputLocal(), ghidra::TypeOp::getOutputLocal(), ghidra::TypeOpBinary::getOutputLocal(), ghidra::TypeOpUnary::getOutputLocal(), ghidra::TypeOpFunc::getOutputLocal(), ghidra::TypeOpPtradd::getOutputLocal(), ghidra::TypeOpPtrsub::getOutputLocal(), ghidra::TypeOpCpoolref::getOutputLocal(), ghidra::TypeOpIntLeft::getOutputToken(), ghidra::TypeOpIntRight::getOutputToken(), ghidra::TypeOpIntSright::getOutputToken(), ghidra::TypeOpPiece::getOutputToken(), ghidra::TypeOpSubpiece::getOutputToken(), ghidra::TypeOpPtrsub::getOutputToken(), ghidra::TypePointerRel::getPtrToFromParent(), ghidra::TypeCode::getSubType(), ghidra::TypeSpacebase::getSubType(), getTypePartialEnum(), getTypePartialStruct(), getTypePartialUnion(), ghidra::Funcdata::mapGlobals(), ghidra::RangeHint::merge(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::newUnique(), ghidra::Funcdata::newUniqueOut(), ghidra::Funcdata::newVarnode(), ghidra::Funcdata::newVarnodeCallSpecs(), ghidra::Funcdata::newVarnodeIop(), ghidra::Funcdata::newVarnodeOut(), ghidra::Funcdata::newVarnodeSpace(), ghidra::FuncProto::paramShift(), ghidra::TypeOpEqual::propagateAcrossCompare(), ghidra::TypeOpIntAdd::propagateAddIn2Out(), ghidra::TypeOp::propagateToPointer(), ghidra::TypeOpCopy::propagateType(), ghidra::TypeOpIntXor::propagateType(), ghidra::TypeOpIntAnd::propagateType(), ghidra::TypeOpIntOr::propagateType(), ghidra::TypeOpMulti::propagateType(), ghidra::TypeOpIndirect::propagateType(), ghidra::UserOpManage::registerBuiltin(), ghidra::Scope::resetSizeLockType(), ghidra::ParameterBasic::resetSizeLockType(), ghidra::ScopeLocal::restructureVarnode(), setCoreType(), ghidra::SplitDatatype::testDatatypeCompatibility(), ghidra::FuncProto::updateInputNoTypes(), ghidra::FuncProto::updateInputTypes(), and ghidra::FuncProto::updateOutputNoTypes().
Datatype * ghidra::TypeFactory::getBase | ( | int4 | s, |
type_metatype | m, | ||
const string & | n | ||
) |
Get named atomic type.
Get or create a "base" type with a specified name and properties
s | is the desired size |
m | is the desired meta-type |
n | is the desired name |
References findAdd(), ghidra::Datatype::hashName(), and ghidra::Datatype::id.
Datatype * ghidra::TypeFactory::getBaseNoChar | ( | int4 | s, |
type_metatype | m | ||
) |
Get atomic type excluding "char".
Get a "base" data-type, given its size and metatype. If a 1-byte integer is requested, do NOT return a TypeChar
s | is the size of the data-type |
m | is the meta-type of the data-type |
References getBase(), ghidra::TYPE_INT, and type_nochar.
Referenced by ghidra::TypeOpIntLeft::getInputLocal(), ghidra::TypeOpIntRight::getInputLocal(), and ghidra::TypeOpIntSright::getInputLocal().
Get the data-type associated with piece of a structured data-type.
Drill down into nested data-types until we get to a data-type that exactly matches the given offset and size, and return this data-type. Any union data-type encountered terminates the process and a partial union data-type is constructed and returned. If the range indicated by the offset and size contains only a partial field or crosses field boundaries, null is returned.
ct | is the structured data-type |
offset | is the starting byte offset for the piece |
size | is the number of bytes in the piece |
References ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::Datatype::getSubType(), getTypePartialEnum(), getTypePartialStruct(), getTypePartialUnion(), ghidra::Datatype::hasStripped(), ghidra::Datatype::isEnumType(), ghidra::TYPE_ARRAY, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
Referenced by ghidra::RulePieceStructure::applyOp(), ghidra::ActionInferTypes::buildLocaltypes(), ghidra::HighVariable::finalizeDatatype(), ghidra::SymbolEntry::getSizedType(), ghidra::SplitDatatype::getValueDatatype(), ghidra::TypeOp::propagateFromPointer(), and ghidra::ActionInferTypes::propagateRef().
int4 ghidra::TypeFactory::getPrimitiveAlignSize | ( | uint4 | size | ) | const |
Get the aligned size of a primitive data-type.
Return the amount of room a data-type takes up in memory, which may be larger than the raw number of bytes in the data-type. This is the size consistent with the sizeof operator in C.
size | is the raw number of bytes in the data-type |
References getAlignment().
Referenced by findAdd().
Construct an array data-type.
as | is the number of elements in the desired array |
ao | is the data-type of the array element |
References findAdd(), ghidra::Datatype::getStripped(), and ghidra::Datatype::hasStripped().
Referenced by ghidra::ScopeLocal::createEntry(), getBase(), and ghidra::SplitDatatype::getValueDatatype().
|
private |
Create a default "char" type.
This creates a 1-byte character datatype (assumed to use UTF8 encoding)
n | is the name to give the data-type |
References findAdd(), ghidra::Datatype::hashName(), and ghidra::Datatype::id.
Referenced by ghidra::UserOpManage::registerBuiltin(), ghidra::ArraySequence::selectStringCopyFunction(), and setCoreType().
Datatype * ghidra::TypeFactory::getTypeChar | ( | int4 | s | ) |
Get a character data-type by size.
If a core character data-type of the given size exists, it is returned. Otherwise an exception is thrown
s | is the size in bytes of the desired character data-type |
References charcache.
TypeCode * ghidra::TypeFactory::getTypeCode | ( | const PrototypePieces & | proto | ) |
Create a "function" datatype.
Creates a TypeCode object and associates a specific function prototype with it.
proto | is the list of names, data-types, and other attributes of the prototype |
References findAdd(), getTypeVoid(), ghidra::Datatype::markComplete(), and ghidra::TypeCode::setPrototype().
|
private |
Create a default "code" type.
Create a "function" or "executable" Datatype object This is used for anonymous function pointers with no prototype
nm | is the name of the data-type |
References ghidra::Datatype::displayName, findAdd(), getTypeCode(), ghidra::Datatype::hashName(), ghidra::Datatype::id, ghidra::Datatype::markComplete(), and ghidra::Datatype::name.
Referenced by ghidra::ExternRefSymbol::buildNameType(), ghidra::FunctionSymbol::buildType(), ghidra::TypeOpCbranch::getInputLocal(), ghidra::TypeOpCallind::getInputLocal(), ghidra::TypeOpIndirect::getInputLocal(), and ghidra::Funcdata::newCodeRef().
TypeCode * ghidra::TypeFactory::getTypeCode | ( | void | ) |
Get an "anonymous" function data-type.
Retrieve or create the core "code" Datatype object This has no prototype attached to it and is appropriate for anonymous function pointers.
References findAdd(), ghidra::Datatype::markComplete(), ghidra::TYPE_CODE, ghidra::TYPE_FLOAT, and typecache.
Referenced by getTypeCode(), and setCoreType().
Datatype * ghidra::TypeFactory::getTypedef | ( | Datatype * | ct, |
const string & | name, | ||
uint8 | id, | ||
uint4 | format | ||
) |
Create a new typedef data-type.
Find or create a data-type identical to the given data-type except for its name and id. If the name and id already describe an incompatible data-type, an exception is thrown.
ct | is the given data-type to clone |
name | is the new name for the clone |
id | is the new id for the clone (or 0) |
format | is a particular format to force when printing (or zero) |
References ghidra::Datatype::clone(), ghidra::Datatype::coretype, ghidra::Datatype::displayName, findByIdLocal(), ghidra::Datatype::flags, ghidra::Datatype::getTypedef(), ghidra::Datatype::hashName(), ghidra::Datatype::id, incompleteTypedef, insert(), ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, ghidra::Datatype::setDisplayFormat(), and ghidra::Datatype::typedefImm.
Referenced by decodeTypedef().
TypeEnum * ghidra::TypeFactory::getTypeEnum | ( | const string & | n | ) |
Create an (empty) enumeration.
The created enumeration will have no named values and a default configuration Named values must be added later.
n | is the name of the enumeration |
References enumsize, enumtype, findAdd(), ghidra::Datatype::hashName(), and ghidra::Datatype::id.
TypePartialEnum * ghidra::TypeFactory::getTypePartialEnum | ( | TypeEnum * | contain, |
int4 | off, | ||
int4 | sz | ||
) |
Create a partial enumeration.
Create a data-type representing storage of part of an enumeration.
contain | is the parent enumeration data-type that we are taking a part of. |
off | is the offset (in bytes) within the parent that the partial data-type starts at |
sz | is the number of bytes in the partial data-type |
References findAdd(), getBase(), and ghidra::TYPE_UNKNOWN.
Referenced by getExactPiece(), and ghidra::TypeOp::propagateFromPointer().
TypePartialStruct * ghidra::TypeFactory::getTypePartialStruct | ( | Datatype * | contain, |
int4 | off, | ||
int4 | sz | ||
) |
Create a partial structure.
Create a data-type representing storage of part of an array or structure.
contain | is the parent array or structure data-type that we are taking a part of. |
off | is the offset (in bytes) within the parent that the partial data-type starts at |
sz | is the number of bytes in the partial data-type |
References findAdd(), getBase(), and ghidra::TYPE_UNKNOWN.
Referenced by getExactPiece().
TypePartialUnion * ghidra::TypeFactory::getTypePartialUnion | ( | TypeUnion * | contain, |
int4 | off, | ||
int4 | sz | ||
) |
Create a partial union.
Create a data-type representing storage of part of a union data-type.
contain | is the parent union data-type that we are taking a part of. |
off | is the offset (in bytes) within the parent that the partial data-type starts at |
sz | is the number of bytes in the partial data-type |
References findAdd(), getBase(), and ghidra::TYPE_UNKNOWN.
Referenced by getExactPiece().
TypePointer * ghidra::TypeFactory::getTypePointer | ( | int4 | s, |
Datatype * | pt, | ||
uint4 | ws | ||
) |
Construct an absolute pointer data-type.
Allows "pointer to array" to be constructed
s | is the size of the pointer |
pt | is the pointed-to data-type |
ws | is the wordsize associated with the pointer |
References ghidra::TypePointer::calcTruncate(), findAdd(), ghidra::Datatype::getStripped(), and ghidra::Datatype::hasStripped().
Referenced by ghidra::ConvertToPointer::assignAddress(), ghidra::ParamListStandardOut::assignMap(), ghidra::ExternRefSymbol::buildNameType(), ghidra::StringSequence::buildStringCopy(), ghidra::Funcdata::constructConstSpacebase(), ghidra::Funcdata::constructSpacebaseInput(), ghidra::StringSequence::constructTypedPointer(), ghidra::TypePointer::downChain(), ghidra::TypePointerRel::downChain(), ghidra::Funcdata::forceFacingType(), ghidra::TypeOpLoad::getInputCast(), ghidra::TypeOpStore::getInputCast(), ghidra::TypeOpCbranch::getInputLocal(), ghidra::TypeOpCallind::getInputLocal(), ghidra::TypeOpIndirect::getInputLocal(), ghidra::TypeOpPtrsub::getOutputToken(), ghidra::TypePointerRel::markEphemeral(), ghidra::Funcdata::prepareThisPointer(), ghidra::TypeOpEqual::propagateAcrossCompare(), ghidra::TypeOpIntAdd::propagateAddIn2Out(), ghidra::TypeOp::propagateToPointer(), ghidra::TypeOpCopy::propagateType(), ghidra::TypeOpIntXor::propagateType(), ghidra::TypeOpIntAnd::propagateType(), ghidra::TypeOpIntOr::propagateType(), ghidra::TypeOpMulti::propagateType(), ghidra::TypeOpIndirect::propagateType(), ghidra::UserOpManage::registerBuiltin(), ghidra::ResolvedUnion::ResolvedUnion(), ghidra::ScoreUnionFields::scoreTrialUp(), ghidra::Funcdata::spacebase(), and ghidra::Funcdata::spacebaseConstant().
TypePointer * ghidra::TypeFactory::getTypePointer | ( | int4 | s, |
Datatype * | pt, | ||
uint4 | ws, | ||
const string & | n | ||
) |
Construct a named pointer data-type.
The given name is attached, which distinguishes the returned data-type from other unnamed (or differently named) pointers that otherwise have the same attributes.
s | is the size of the pointer |
pt | is the pointed-to data-type |
ws | is the wordsize associated with the pointer |
n | is the given name to attach to the pointer |
References ghidra::TypePointer::calcTruncate(), ghidra::Datatype::displayName, findAdd(), ghidra::Datatype::getStripped(), ghidra::Datatype::hashName(), ghidra::Datatype::hasStripped(), ghidra::Datatype::id, and ghidra::Datatype::name.
TypePointerRel * ghidra::TypeFactory::getTypePointerRel | ( | int4 | sz, |
Datatype * | parent, | ||
Datatype * | ptrTo, | ||
int4 | ws, | ||
int4 | off, | ||
const string & | nm | ||
) |
Build a named pointer offset into a larger container.
The resulting data-type is named and not ephemeral and will display as a formal data-type in decompiler output.
sz | is the size in bytes of the pointer |
parent | is data-type of the parent container being indirectly pointed to |
ptrTo | is the data-type being pointed directly to |
ws | is the addressable unit size of pointed to data |
off | is the offset of the pointed-to data-type relative to the container |
nm | is the name to associate with the pointer |
References ghidra::Datatype::displayName, findAdd(), ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.
TypePointerRel * ghidra::TypeFactory::getTypePointerRel | ( | TypePointer * | parentPtr, |
Datatype * | ptrTo, | ||
int4 | off | ||
) |
Get pointer offset relative to a container.
Find/create a pointer data-type that points at a known offset relative to a containing data-type. The resulting data-type is unnamed and ephemeral.
parentPtr | is a model pointer data-type, pointing to the containing data-type |
ptrTo | is the data-type being pointed directly to |
off | is the offset of the pointed-to data-type relative to the container |
References findAdd(), ghidra::TypePointerRel::markEphemeral(), ghidra::TypePointer::ptrto, ghidra::Datatype::size, and ghidra::TypePointer::wordsize.
Referenced by ghidra::TypeOpIntAdd::propagateAddIn2Out().
TypePointer * ghidra::TypeFactory::getTypePointerStripArray | ( | int4 | s, |
Datatype * | pt, | ||
uint4 | ws | ||
) |
Construct a pointer data-type, stripping an ARRAY level.
This creates a pointer to a given data-type. If the given data-type is an array, the TYPE_ARRAY property is stripped off, and a pointer to the array element data-type is returned.
s | is the size of the pointer |
pt | is the pointed-to data-type |
ws | is the wordsize associated with the pointer |
References ghidra::TypePointer::calcTruncate(), findAdd(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getStripped(), ghidra::Datatype::hasStripped(), and ghidra::TYPE_ARRAY.
Referenced by ghidra::SplitDatatype::buildPointers(), ghidra::StringSequence::constructTypedPointer(), ghidra::TypePointer::downChain(), ghidra::ScoreUnionFields::ScoreUnionFields(), and ghidra::Funcdata::spacebaseConstant().
TypePointer * ghidra::TypeFactory::getTypePointerWithSpace | ( | Datatype * | ptrTo, |
AddrSpace * | spc, | ||
const string & | nm | ||
) |
Build a named pointer with an address space attribute.
The new data-type acts like a typedef of a normal pointer but can affect the resolution of constants by the type propagation system.
ptrTo | is the data-type being pointed directly to |
spc | is the address space to associate with the pointer |
nm | is the name to associate with the pointer |
References ghidra::TypePointer::calcTruncate(), ghidra::Datatype::displayName, findAdd(), ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.
TypeSpacebase * ghidra::TypeFactory::getTypeSpacebase | ( | AddrSpace * | id, |
const Address & | addr | ||
) |
Create a "spacebase" type.
Creates the special TypeSpacebase with an associated address space and scope
id | is the address space |
addr | specifies the function scope, or isInvalid() for global scope |
References findAdd(), and glb.
Referenced by ghidra::Funcdata::constructConstSpacebase(), ghidra::Funcdata::constructSpacebaseInput(), ghidra::Funcdata::spacebase(), and ghidra::Funcdata::spacebaseConstant().
TypeStruct * ghidra::TypeFactory::getTypeStruct | ( | const string & | n | ) |
Create an (empty) structure.
The created structure will be incomplete and have no fields. They must be added later.
n | is the name of the structure |
References ghidra::Datatype::displayName, findAdd(), ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.
|
private |
Create a default "unicode" type.
This creates a multi-byte character data-type (using UTF16 or UTF32 encoding)
nm | is the name to give the data-type |
sz | is the size of the data-type in bytes |
m | is the presumed meta-type when treating the character as an integer |
References findAdd(), ghidra::Datatype::hashName(), and ghidra::Datatype::id.
Referenced by setCoreType().
TypeUnion * ghidra::TypeFactory::getTypeUnion | ( | const string & | n | ) |
Create an (empty) union.
The created union will be incomplete and have no fields. They must be added later.
n | is the name of the union |
References ghidra::Datatype::displayName, findAdd(), ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.
TypeVoid * ghidra::TypeFactory::getTypeVoid | ( | void | ) |
Get the "void" data-type.
There should be exactly one instance of the "void" Datatype object, which this fetches
References ghidra::TypeVoid::clone(), ghidra::Datatype::hashName(), ghidra::Datatype::id, ghidra::Datatype::name, nametree, tree, ghidra::TYPE_FLOAT, ghidra::TYPE_VOID, and typecache.
Referenced by ghidra::ActionDefaultParams::apply(), ghidra::ParamListStandardOut::assignMap(), ghidra::ProtoModel::assignParameterStorage(), ghidra::PrintC::buildTypeStack(), ghidra::ProtoStoreSymbol::clearOutput(), ghidra::Override::decode(), ghidra::TypeCode::decodePrototype(), decodeTypeNoRef(), getTypeCode(), ghidra::FuncProto::paramShift(), ghidra::Funcdata::prepareThisPointer(), ghidra::ProtoStoreSymbol::ProtoStoreSymbol(), ghidra::PrintJava::pushTypeStart(), ghidra::UserOpManage::registerBuiltin(), setCoreType(), and ghidra::FlowInfo::truncateIndirectJump().
|
private |
Insert pointer into the cross-reference sets.
Internal method for finally inserting a new Datatype pointer
newtype | is the new pointer |
References ghidra::Datatype::getId(), ghidra::Datatype::id, nametree, ghidra::Datatype::printRaw(), and tree.
Referenced by findAdd(), and getTypedef().
|
private |
Register a new data-type warning with this factory.
Add the data-type and string to the warnings container.
dt | is the data-type associated with the warning |
warn | is the warning string to be displayed to the user |
References ghidra::Datatype::flags, ghidra::Datatype::getId(), ghidra::Datatype::warning_issued, and warnings.
Referenced by decodeEnum(), and decodeStruct().
|
private |
Write out dependency list.
Recursively write out all the components of a data-type in dependency order Component data-types will come before the data-type containing them in the list.
deporder | holds the ordered list of data-types to construct |
mark | is a "marking" container to prevent cycles |
ct | is the data-type to have written out |
References ghidra::Datatype::getDepend(), ghidra::Datatype::numDepend(), orderRecurse(), and ghidra::Datatype::typedefImm.
Referenced by dependentOrder(), and orderRecurse().
void ghidra::TypeFactory::parseEnumConfig | ( | Decoder & | decoder | ) |
Parse the <enum> tag.
Recover default enumeration properties (size and meta-type) from an <enum> XML tag. Should probably consider this deprecated. These values are only used by the internal C parser. param el is the XML element
References ghidra::Decoder::closeElement(), enumsize, enumtype, ghidra::Decoder::openElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readSignedInteger(), ghidra::TYPE_ENUM_INT, and ghidra::TYPE_ENUM_UINT.
Referenced by ghidra::Architecture::parseCompilerConfig().
|
private |
Recalculate submeta for pointers to given base data-type.
Search for pointers that match the given ptrto and sub-metatype and change it to the current calculated sub-metatype. A change in the sub-metatype may involve reinserting the pointer data-type in the functional tree.
base | is the given base data-type |
sub | is the type of pointer to search for |
References ghidra::Datatype::getMetatype(), ghidra::TypePointer::ptrto, ghidra::Datatype::submeta, tree, and ghidra::TYPE_PTR.
Referenced by setFields().
|
private |
Remove the warning associated with the given data-type.
Run through the warnings and delete any matching the given data-type
dt | is the given data-type |
References ghidra::Datatype::getId(), ghidra::Datatype::getName(), and warnings.
Referenced by destroyType().
TypePointer * ghidra::TypeFactory::resizePointer | ( | TypePointer * | ptr, |
int4 | newSize | ||
) |
Build a resized pointer based on the given pointer.
All the properties of the original pointer are preserved, except the size is changed.
ptr | is the original pointer |
newSize | is the size of the new pointer in bytes |
References findAdd(), ghidra::Datatype::getStripped(), ghidra::Datatype::hasStripped(), ghidra::TypePointer::ptrto, and ghidra::TypePointer::wordsize.
Referenced by ghidra::TypePointer::calcTruncate(), ghidra::TypeOpPiece::propagateType(), ghidra::TypeOpSubpiece::propagateType(), and ghidra::TypeOpSegment::propagateType().
|
private |
Redefine incomplete typedefs of data-types that are now complete.
Run through typedefs that were initially defined on incomplete data-types. If the data-type is now complete, copy the fields or prototype into the typedef and remove it from the list.
References ghidra::Datatype::alignment, ghidra::TypeStruct::field, ghidra::TypeUnion::field, ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::getTypedef(), incompleteTypedef, ghidra::Datatype::isIncomplete(), ghidra::TypeCode::proto, setFields(), setPrototype(), ghidra::Datatype::size, ghidra::TYPE_CODE, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
Referenced by decodeCode(), decodeStruct(), and decodeUnion().
void ghidra::TypeFactory::setCoreType | ( | const string & | name, |
int4 | size, | ||
type_metatype | meta, | ||
bool | chartp | ||
) |
Create a core data-type.
Manually create a "base" core type. This currently must be called before any pointers or arrays are defined off of the type.
name | is the data-type name |
size | is the size of the data-type |
meta | is the meta-type of the data-type |
chartp | is true if a character type should be created |
References ghidra::Datatype::coretype, ghidra::Datatype::flags, getBase(), getTypeChar(), getTypeCode(), getTypeUnicode(), getTypeVoid(), ghidra::TYPE_CODE, and ghidra::TYPE_VOID.
Referenced by ghidra::ArchitectureGhidra::buildCoreTypes().
|
private |
Provide default alignments for data-types.
The default is used if the compiler spec does not contain a <size_alignment_map> element.
References alignMap.
Referenced by setupSizes().
void ghidra::TypeFactory::setDisplayFormat | ( | Datatype * | ct, |
uint4 | format | ||
) |
Set the display format associated with the given data-type.
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, 4=oct, 8=bin, 16=char
ct | is the given data-type to change |
format | is the given format |
References ghidra::Datatype::setDisplayFormat().
void ghidra::TypeFactory::setEnumValues | ( | const map< uintb, string > & | nmap, |
TypeEnum * | te | ||
) |
Set named values for an enumeration.
nmap | is the mapping from integer value to name string |
te | is the enumeration whose values/names are set |
References ghidra::TypeEnum::setNameMap(), and tree.
void ghidra::TypeFactory::setFields | ( | const vector< TypeField > & | fd, |
TypeStruct * | ot, | ||
int4 | newSize, | ||
int4 | newAlign, | ||
uint4 | flags | ||
) |
Set fields on a TypeStruct.
Set fields on a structure data-type, establishing its size, alignment, and other properties. This method should only be used on an incomplete structure. It will mark the structure as complete.
fd | is the list of fields to set |
ot | is the TypeStruct object to modify |
newSize | is the new size of the structure in bytes |
newAlign | is the new alignment of the structure |
flags | are other flags to set on the structure |
References ghidra::Datatype::flags, ghidra::Datatype::isIncomplete(), ghidra::Datatype::opaque_string, recalcPointerSubmeta(), ghidra::TypeStruct::setFields(), ghidra::SUB_PTR, ghidra::SUB_PTR_STRUCT, tree, ghidra::Datatype::type_incomplete, and ghidra::Datatype::variable_length.
Referenced by decodeStruct(), decodeTypedef(), decodeUnion(), and resolveIncompleteTypedefs().
void ghidra::TypeFactory::setFields | ( | const vector< TypeField > & | fd, |
TypeUnion * | ot, | ||
int4 | newSize, | ||
int4 | newAlign, | ||
uint4 | flags | ||
) |
Set fields on a TypeUnion.
This method should only be used on an incomplete union. It will mark the union as complete.
fd | is the list of fields to set |
ot | is the TypeUnion object to modify |
newSize | is the size to associate with the union in bytes |
newAlign | is the alignment to set |
flags | are other flags to set on the union |
References ghidra::Datatype::flags, ghidra::Datatype::isIncomplete(), ghidra::TypeUnion::setFields(), tree, ghidra::Datatype::type_incomplete, and ghidra::Datatype::variable_length.
Set the given types name.
This routine renames a Datatype object and fixes up cross-referencing
ct | is the data-type to rename |
n | is the new name |
References ghidra::Datatype::displayName, ghidra::Datatype::hashName(), ghidra::Datatype::id, ghidra::Datatype::name, nametree, and tree.
Set the prototype on a TypeCode.
The given prototype is copied into the given code data-type This method should only be used on an incomplete TypeCode. It will mark the TypeCode as complete.
fp | is the given prototype to copy |
newCode | is the given code data-type |
flags | are additional flags to transfer into the code data-type |
References ghidra::Datatype::flags, ghidra::Datatype::isIncomplete(), ghidra::TypeCode::setPrototype(), tree, ghidra::Datatype::type_incomplete, and ghidra::Datatype::variable_length.
Referenced by decodeCode(), and resolveIncompleteTypedefs().
void ghidra::TypeFactory::setupSizes | ( | void | ) |
Derive some size information from Architecture.
Set up default values for size of "int", structure alignment, and enums.
References alignMap, enumsize, enumtype, ghidra::AddrSpace::getAddrSize(), ghidra::SegmentOp::getBaseSize(), ghidra::AddrSpaceManager::getDefaultDataSpace(), ghidra::AddrSpaceManager::getDefaultSize(), ghidra::SegmentOp::getInnerSize(), ghidra::Architecture::getSegmentOp(), ghidra::AddrSpace::getSpacebase(), ghidra::AddrSpaceManager::getStackSpace(), glb, ghidra::SegmentOp::hasFarPointerSupport(), setDefaultAlignmentMap(), ghidra::VarnodeData::size, sizeOfAltPointer, sizeOfChar, sizeOfInt, sizeOfLong, sizeOfPointer, sizeOfWChar, and ghidra::TYPE_ENUM_UINT.
Referenced by ghidra::Architecture::parseCompilerConfig().