decompiler
1.0.0
|
Container class for all Datatype objects in an Architecture. More...
#include <type.hh>
Public Member Functions | |
TypeFactory (Architecture *g) | |
Construct a factory. More... | |
void | setupSizes (void) |
Derive some size information from Architecture. More... | |
void | clear (void) |
Clear out all types. More... | |
void | clearNoncore (void) |
Clear out non-core types. More... | |
virtual | ~TypeFactory (void) |
Destructor. | |
void | setStructAlign (int4 al) |
Set the default structure alignment. | |
int4 | getStructAlign (void) const |
Get the default structure alignment. | |
int4 | getSizeOfInt (void) const |
Get the size of the default "int". | |
int4 | getSizeOfLong (void) const |
Get the size of the default "long". | |
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. More... | |
Datatype * | setName (Datatype *ct, const string &n) |
Set the given types name. More... | |
void | setDisplayFormat (Datatype *ct, uint4 format) |
Set the display format associated with the given data-type. More... | |
bool | setFields (vector< TypeField > &fd, TypeStruct *ot, int4 fixedsize, uint4 flags) |
Set fields on a TypeStruct. More... | |
bool | setFields (vector< TypeField > &fd, TypeUnion *ot, int4 fixedsize, uint4 flags) |
Set fields on a TypeUnion. More... | |
void | setPrototype (const FuncProto *fp, TypeCode *newCode, uint4 flags) |
Set the prototype on a TypeCode. More... | |
bool | setEnumValues (const vector< string > &namelist, const vector< uintb > &vallist, const vector< bool > &assignlist, TypeEnum *te) |
Set named values for an enumeration. More... | |
Datatype * | decodeType (Decoder &decoder) |
Restore Datatype from a stream. More... | |
Datatype * | decodeTypeWithCodeFlags (Decoder &decoder, bool isConstructor, bool isDestructor) |
Restore data-type from an element and extra "code" flags. More... | |
TypeVoid * | getTypeVoid (void) |
Get the "void" data-type. More... | |
Datatype * | getBaseNoChar (int4 s, type_metatype m) |
Get atomic type excluding "char". More... | |
Datatype * | getBase (int4 s, type_metatype m) |
Get atomic type. More... | |
Datatype * | getBase (int4 s, type_metatype m, const string &n) |
Get named atomic type. More... | |
TypeCode * | getTypeCode (void) |
Get an "anonymous" function data-type. More... | |
TypePointer * | getTypePointerStripArray (int4 s, Datatype *pt, uint4 ws) |
Construct a pointer data-type, stripping an ARRAY level. More... | |
TypePointer * | getTypePointer (int4 s, Datatype *pt, uint4 ws) |
Construct an absolute pointer data-type. More... | |
TypePointer * | getTypePointer (int4 s, Datatype *pt, uint4 ws, const string &n) |
Construct a named pointer data-type. More... | |
TypePointer * | getTypePointerNoDepth (int4 s, Datatype *pt, uint4 ws) |
Construct a depth limited pointer data-type. More... | |
TypeArray * | getTypeArray (int4 as, Datatype *ao) |
Construct an array data-type. More... | |
TypeStruct * | getTypeStruct (const string &n) |
Create an (empty) structure. More... | |
TypePartialStruct * | getTypePartialStruct (Datatype *contain, int4 off, int4 sz) |
Create a partial structure. | |
TypeUnion * | getTypeUnion (const string &n) |
Create an (empty) union. More... | |
TypePartialUnion * | getTypePartialUnion (TypeUnion *contain, int4 off, int4 sz) |
Create a partial union. | |
TypeEnum * | getTypeEnum (const string &n) |
Create an (empty) enumeration. More... | |
TypeSpacebase * | getTypeSpacebase (AddrSpace *id, const Address &addr) |
Create a "spacebase" type. More... | |
TypeCode * | getTypeCode (ProtoModel *model, Datatype *outtype, const vector< Datatype *> &intypes, bool dotdotdot) |
Create a "function" datatype. More... | |
Datatype * | getTypedef (Datatype *ct, const string &name, uint8 id, uint4 format) |
Create a new typedef data-type. More... | |
TypePointerRel * | getTypePointerRel (TypePointer *parentPtr, Datatype *ptrTo, int4 off) |
Get pointer offset relative to a container. More... | |
TypePointerRel * | getTypePointerRel (int4 sz, Datatype *parent, Datatype *ptrTo, int4 ws, int4 off, const string &nm) |
Build a named pointer offset into a larger container. More... | |
TypePointer * | getTypePointerWithSpace (Datatype *ptrTo, AddrSpace *spc, const string &nm) |
Build a named pointer with an address space attribute. More... | |
TypePointer * | resizePointer (TypePointer *ptr, int4 newSize) |
Build a resized pointer based on the given pointer. More... | |
Datatype * | getExactPiece (Datatype *ct, int4 offset, int4 size) |
Get the data-type associated with piece of a structured data-type. More... | |
void | destroyType (Datatype *ct) |
Remove a data-type from this. More... | |
Datatype * | concretize (Datatype *ct) |
Convert given data-type to concrete form. More... | |
void | dependentOrder (vector< Datatype *> &deporder) const |
Place all data-types in dependency order. More... | |
void | encode (Encoder &encoder) const |
Encode this container to stream. More... | |
void | encodeCoreTypes (Encoder &encoder) const |
Encode core types to stream. More... | |
void | decode (Decoder &decoder) |
Decode this from a <typegrp> element. More... | |
void | decodeCoreTypes (Decoder &decoder) |
Initialize basic data-types from a stream. More... | |
void | decodeDataOrganization (Decoder &decoder) |
Parse a <data_organization> element. More... | |
void | parseEnumConfig (Decoder &decoder) |
Parse the <enum> tag. More... | |
void | setCoreType (const string &name, int4 size, type_metatype meta, bool chartp) |
Create a core data-type. More... | |
void | cacheCoreTypes (void) |
Cache common types. More... | |
Protected Member Functions | |
Datatype * | findByIdLocal (const string &nm, uint8 id) const |
Search locally by name and id. More... | |
virtual Datatype * | findById (const string &n, uint8 id, int4 sz) |
Search by name and/or id. More... | |
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. More... | |
void | insert (Datatype *newtype) |
Insert pointer into the cross-reference sets. More... | |
Datatype * | findAdd (Datatype &ct) |
Find data-type in this container or add it. More... | |
void | orderRecurse (vector< Datatype *> &deporder, DatatypeSet &mark, Datatype *ct) const |
Write out dependency list. More... | |
Datatype * | decodeTypedef (Decoder &decoder) |
Restore a <def> element describing a typedef. More... | |
Datatype * | decodeStruct (Decoder &decoder, bool forcecore) |
Restore a <type> element describing a structure. More... | |
Datatype * | decodeUnion (Decoder &decoder, bool forcecore) |
Restore a <type> element describing a union. More... | |
Datatype * | decodeCode (Decoder &decoder, bool isConstructor, bool isDestructor, bool forcecore) |
Restore an element describing a code object. More... | |
Datatype * | decodeTypeNoRef (Decoder &decoder, bool forcecore) |
Restore from a stream. More... | |
void | clearCache (void) |
Clear the common type cache. More... | |
TypeChar * | getTypeChar (const string &n) |
Create a default "char" type. More... | |
TypeUnicode * | getTypeUnicode (const string &nm, int4 sz, type_metatype m) |
Create a default "unicode" type. More... | |
TypeCode * | getTypeCode (const string &n) |
Create a default "code" type. More... | |
void | recalcPointerSubmeta (Datatype *base, sub_metatype sub) |
Recalculate submeta for pointers to given base data-type. More... | |
Private Attributes | |
int4 | sizeOfInt |
Size of the core "int" datatype. | |
int4 | sizeOfLong |
Size of the core "long" datatype. | |
int4 | sizeOfPointer |
Size of pointers (into default data address space) | |
int4 | sizeOfAltPointer |
Size of alternate pointers used by architecture (if not 0) | |
int4 | align |
Alignment of structures. | |
int4 | enumsize |
Size of an enumerated type. | |
type_metatype | enumtype |
Default enumeration meta-type (when parsing C) | |
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. | |
Container class for all Datatype objects in an Architecture.
ghidra::TypeFactory::TypeFactory | ( | Architecture * | g | ) |
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 ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::Datatype::isASCII(), ghidra::Datatype::isCharPrint(), ghidra::Datatype::isCoreType(), ghidra::Datatype::isEnumType(), ghidra::TYPE_BOOL, ghidra::TYPE_CODE, ghidra::TYPE_FLOAT, ghidra::TYPE_INT, ghidra::TYPE_UINT, ghidra::TYPE_UNKNOWN, and ghidra::TYPE_VOID.
Referenced by ghidra::ArchitectureGhidra::buildTypegrp().
void ghidra::TypeFactory::clear | ( | void | ) |
Clear out all types.
Remove all Datatype objects owned by this TypeFactory.
|
private |
Clear the common type cache.
Clear the matrix of commonly used atomic types.
void ghidra::TypeFactory::clearNoncore | ( | void | ) |
Clear out non-core types.
Delete anything that isn't a core type.
References ghidra::Datatype::isCoreType().
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 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(), ghidra::Datatype::enumtype, ghidra::Decoder::openElement(), ghidra::Decoder::peekElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readSignedInteger(), ghidra::TYPE_INT, and ghidra::TYPE_UINT.
|
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(), ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::id, ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, ghidra::TypeCode::proto, ghidra::TypeCode::setPrototype(), and ghidra::TYPE_CODE.
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 ghidra::Decoder::closeElement(), ghidra::Decoder::openElement(), and ghidra::Decoder::peekElement().
Referenced by ghidra::ArchitectureGhidra::buildTypegrp().
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(), ghidra::Decoder::openElement(), and ghidra::Decoder::readSignedInteger().
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::compareDependency(), ghidra::Datatype::coretype, ghidra::Datatype::decodeBasic(), ghidra::TypeStruct::decodeFields(), ghidra::TypeStruct::field, ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::id, ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, ghidra::Datatype::size, and ghidra::TYPE_STRUCT.
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(), 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::CPoolRecord::decode(), ghidra::TypePointer::decode(), ghidra::TypeArray::decode(), ghidra::TypePointerRel::decode(), ghidra::ProtoStoreInternal::decode(), 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::encodeIntegerFormat(), ghidra::TypeStruct::field, ghidra::TypeUnion::field, ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Decoder::getNextAttributeId(), ghidra::Datatype::getTypedef(), ghidra::Datatype::hashName(), ghidra::Datatype::hashSize(), ghidra::Datatype::isVariableLength(), ghidra::Datatype::name, ghidra::Decoder::readString(), ghidra::Decoder::readUnsignedInteger(), ghidra::Datatype::size, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
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::TypeUnicode::decode(), ghidra::TypePointer::decode(), ghidra::TypeArray::decode(), ghidra::TypeEnum::decode(), ghidra::TypePointerRel::decode(), ghidra::TypeSpacebase::decode(), ghidra::Datatype::decodeBasic(), ghidra::Datatype::flags, ghidra::Decoder::getNextAttributeId(), ghidra::Decoder::openElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readString(), ghidra::Decoder::rewindAttributes(), ghidra::TYPE_ARRAY, ghidra::TYPE_CODE, ghidra::TYPE_INT, ghidra::TYPE_PTR, ghidra::TYPE_PTRREL, ghidra::TYPE_SPACEBASE, ghidra::TYPE_STRUCT, ghidra::TYPE_UNION, and ghidra::TYPE_UNKNOWN.
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(), 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::compareDependency(), ghidra::Datatype::coretype, ghidra::Datatype::decodeBasic(), ghidra::TypeUnion::decodeFields(), ghidra::TypeUnion::field, ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::id, ghidra::Datatype::isIncomplete(), ghidra::Datatype::name, ghidra::Datatype::size, and ghidra::TYPE_UNION.
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 |
Referenced by ghidra::PrintC::docTypeDefinitions().
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::isCoreType().
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(), ghidra::Datatype::enumtype, ghidra::Encoder::openElement(), ghidra::TYPE_ARRAY, ghidra::TYPE_INT, ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, ghidra::TYPE_UNION, ghidra::Encoder::writeBool(), and ghidra::Encoder::writeSignedInteger().
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(), ghidra::TYPE_ARRAY, ghidra::TYPE_PTR, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
Referenced by ghidra::RawBinaryArchitecture::encode(), ghidra::XmlArchitecture::encode(), and ghidra::BfdArchitecture::encode().
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::clone(), ghidra::Datatype::compareDependency(), ghidra::Datatype::id, and ghidra::Datatype::name.
|
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 ghidra::Datatype::hashSize().
Referenced by ghidra::TypeFactoryGhidra::findById().
|
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, and ghidra::TYPE_UNKNOWN.
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 |
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 |
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 ghidra::TYPE_FLOAT, and ghidra::TYPE_UNKNOWN.
Referenced by ghidra::MapState::addGuard(), ghidra::RuleSubRight::applyOp(), ghidra::CastStrategyC::arithmeticOutputStandard(), ghidra::LabSymbol::buildType(), ghidra::EquateSymbol::decode(), ghidra::ScopeInternal::decodeCollision(), ghidra::EquateSymbol::EquateSymbol(), 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::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::TypeOpCopy::propagateType(), ghidra::TypeOpIntXor::propagateType(), ghidra::TypeOpIntAnd::propagateType(), ghidra::TypeOpIntOr::propagateType(), ghidra::TypeOpMulti::propagateType(), ghidra::TypeOpIndirect::propagateType(), ghidra::ParameterBasic::resetSizeLockType(), 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 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 ghidra::TYPE_INT.
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(), ghidra::Datatype::size, ghidra::TYPE_ARRAY, ghidra::TYPE_STRUCT, and ghidra::TYPE_UNION.
Referenced by ghidra::RulePieceStructure::applyOp(), ghidra::ActionInferTypes::buildLocaltypes(), ghidra::SymbolEntry::getSizedType(), ghidra::SplitDatatype::getValueDatatype(), and ghidra::ActionInferTypes::propagateRef().
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 ghidra::Datatype::getStripped(), and ghidra::Datatype::hasStripped().
Referenced by ghidra::ScopeLocal::createEntry().
|
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 ghidra::Datatype::hashName(), and ghidra::Datatype::id.
|
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, 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 ghidra::Datatype::markComplete(), ghidra::TYPE_CODE, and ghidra::TYPE_FLOAT.
TypeCode * ghidra::TypeFactory::getTypeCode | ( | ProtoModel * | model, |
Datatype * | outtype, | ||
const vector< Datatype *> & | intypes, | ||
bool | dotdotdot | ||
) |
Create a "function" datatype.
Creates a TypeCode object and associates a specific function prototype with it.
model | is the prototype model associated with the function |
outtype | is the return type of the function |
intypes | is the array of input parameters of the function |
dotdotdot | is true if the function takes variable arguments |
References ghidra::Datatype::markComplete(), and ghidra::TypeCode::setPrototype().
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, ghidra::Datatype::flags, ghidra::Datatype::getTypedef(), ghidra::Datatype::hashName(), ghidra::Datatype::id, ghidra::Datatype::name, ghidra::Datatype::setDisplayFormat(), and ghidra::Datatype::typedefImm.
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 ghidra::Datatype::enumtype, ghidra::Datatype::hashName(), and ghidra::Datatype::id.
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(), ghidra::Datatype::getStripped(), and ghidra::Datatype::hasStripped().
Referenced by ghidra::ParamListStandard::assignMap(), ghidra::ParamListStandardOut::assignMap(), ghidra::ExternRefSymbol::buildNameType(), 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::TypeOpCopy::propagateType(), ghidra::TypeOpIntXor::propagateType(), ghidra::TypeOpIntAnd::propagateType(), ghidra::TypeOpIntOr::propagateType(), ghidra::TypeOpMulti::propagateType(), ghidra::TypeOpIndirect::propagateType(), ghidra::ResolvedUnion::ResolvedUnion(), 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, ghidra::Datatype::getStripped(), ghidra::Datatype::hashName(), ghidra::Datatype::hasStripped(), ghidra::Datatype::id, and ghidra::Datatype::name.
TypePointer * ghidra::TypeFactory::getTypePointerNoDepth | ( | int4 | s, |
Datatype * | pt, | ||
uint4 | ws | ||
) |
Construct a depth limited pointer data-type.
s | is the size of the pointer |
pt | is the pointed-to data-type |
ws | is the wordsize associated with the pointer |
References ghidra::Datatype::getMetatype(), ghidra::Datatype::getSize(), ghidra::TYPE_PTR, and ghidra::TYPE_UNKNOWN.
Referenced by ghidra::TypeOpLoad::propagateType(), and ghidra::TypeOpStore::propagateType().
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 ghidra::TypePointerRel::markEphemeral(), ghidra::TypePointer::ptrto, ghidra::Datatype::size, and ghidra::TypePointer::wordsize.
Referenced by ghidra::TypeOpIntAdd::propagateAddIn2Out().
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, ghidra::Datatype::hashName(), ghidra::Datatype::id, and ghidra::Datatype::name.
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(), ghidra::Datatype::getMetatype(), ghidra::Datatype::getStripped(), ghidra::Datatype::hasStripped(), and ghidra::TYPE_ARRAY.
Referenced by 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, 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 |
Referenced by 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, 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 ghidra::Datatype::hashName(), and ghidra::Datatype::id.
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, 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, ghidra::TYPE_FLOAT, and ghidra::TYPE_VOID.
Referenced by ghidra::ActionDefaultParams::apply(), ghidra::PrintC::buildTypeStack(), ghidra::Override::decode(), ghidra::TypeCode::decodePrototype(), ghidra::FuncProto::paramShift(), ghidra::Funcdata::prepareThisPointer(), and ghidra::PrintJava::pushTypeStart().
|
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, ghidra::Datatype::printRaw(), and ghidra::TypeCode::printRaw().
|
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(), ghidra::Datatype::size, and ghidra::Datatype::typedefImm.
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(), ghidra::Datatype::enumtype, ghidra::Decoder::openElement(), ghidra::Decoder::readBool(), ghidra::Decoder::readSignedInteger(), ghidra::TYPE_INT, and ghidra::TYPE_UINT.
|
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, and ghidra::TYPE_PTR.
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 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().
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, ghidra::TYPE_CODE, and ghidra::TYPE_VOID.
Referenced by ghidra::ArchitectureGhidra::buildTypegrp().
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().
bool ghidra::TypeFactory::setEnumValues | ( | const vector< string > & | namelist, |
const vector< uintb > & | vallist, | ||
const vector< bool > & | assignlist, | ||
TypeEnum * | te | ||
) |
Set named values for an enumeration.
Set the list of enumeration values and identifiers for a TypeEnum Fill in any values for any names that weren't explicitly assigned and check for duplicates.
namelist | is the list of names in the enumeration |
vallist | is the corresponding list of values assigned to names in namelist |
assignlist | is true if the corresponding name in namelist has an assigned value |
te | is the enumeration object to modify |
References ghidra::calc_mask(), ghidra::Datatype::getSize(), and ghidra::TypeEnum::setNameMap().
bool ghidra::TypeFactory::setFields | ( | vector< TypeField > & | fd, |
TypeStruct * | ot, | ||
int4 | fixedsize, | ||
uint4 | flags | ||
) |
Set fields on a TypeStruct.
Make sure all the offsets are fully established then set fields of the structure If fixedsize is greater than 0, force the final structure to have that size. 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 |
fixedsize | is 0 or the forced size of the structure |
flags | are other flags to set on the structure |
References ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ghidra::Datatype::getSize(), ghidra::Datatype::isIncomplete(), ghidra::Datatype::opaque_string, ghidra::TypeStruct::setFields(), ghidra::Datatype::size, ghidra::SUB_PTR, ghidra::SUB_PTR_STRUCT, ghidra::Datatype::type_incomplete, ghidra::TYPE_VOID, and ghidra::Datatype::variable_length.
bool ghidra::TypeFactory::setFields | ( | vector< TypeField > & | fd, |
TypeUnion * | ot, | ||
int4 | fixedsize, | ||
uint4 | flags | ||
) |
Set fields on a TypeUnion.
If fixedsize is greater than 0, force the final structure to have that size. 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 |
fixedsize | is 0 or the forced size of the union |
flags | are other flags to set on the union |
References ghidra::Datatype::flags, ghidra::Datatype::getMetatype(), ghidra::Datatype::getName(), ghidra::Datatype::isIncomplete(), ghidra::TypeUnion::setFields(), ghidra::Datatype::size, ghidra::Datatype::type_incomplete, ghidra::TYPE_VOID, 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, and ghidra::Datatype::name.
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(), ghidra::Datatype::type_incomplete, and ghidra::Datatype::variable_length.
void ghidra::TypeFactory::setupSizes | ( | void | ) |
Derive some size information from Architecture.
Set up default values for size of "int", structure alignment, and enums.
References ghidra::Datatype::enumtype, ghidra::SegmentOp::getBaseSize(), ghidra::SegmentOp::getInnerSize(), ghidra::AddrSpace::getSpacebase(), ghidra::SegmentOp::hasFarPointerSupport(), ghidra::VarnodeData::size, and ghidra::TYPE_UINT.