Class UnionDataType
- All Implemented Interfaces:
Composite
,CompositeInternal
,DataType
,Union
,UnionInternal
-
Nested Class Summary
Nested classes/interfaces inherited from interface ghidra.program.model.data.CompositeInternal
CompositeInternal.ComponentComparator, CompositeInternal.OffsetComparator, CompositeInternal.OrdinalComparator
-
Field Summary
Fields inherited from class ghidra.program.model.data.CompositeDataTypeImpl
minimumAlignment, packing
Fields inherited from class ghidra.program.model.data.DataTypeImpl
defaultSettings
Fields inherited from class ghidra.program.model.data.AbstractDataType
categoryPath, dataMgr, name
Fields inherited from interface ghidra.program.model.data.CompositeInternal
ALIGN_NAME, DEFAULT_ALIGNMENT, DEFAULT_PACKING, DEFAULT_PACKING_NAME, DISABLED_PACKING_NAME, MACHINE_ALIGNMENT, NO_PACKING, PACKING_NAME
Fields inherited from interface ghidra.program.model.data.DataType
CONFLICT_SUFFIX, DEFAULT, NO_LAST_CHANGE_TIME, NO_SOURCE_SYNC_TIME, TYPEDEF_ATTRIBUTE_PREFIX, TYPEDEF_ATTRIBUTE_SUFFIX, VOID
-
Constructor Summary
ConstructorDescriptionUnionDataType
(CategoryPath path, String name) Construct a new empty union with the given name within the specified categry path.UnionDataType
(CategoryPath path, String name, DataTypeManager dtm) Construct a new empty union with the given name and datatype manager within the specified categry path.UnionDataType
(CategoryPath path, String name, UniversalID universalID, SourceArchive sourceArchive, long lastChangeTime, long lastChangeTimeInSourceArchive, DataTypeManager dtm) Construct a new empty union with the given name within the specified categry path.UnionDataType
(String name) Construct a new UnionDataType. -
Method Summary
Modifier and TypeMethodDescriptionAdds a new datatype to the end of this composite.addBitField
(DataType baseDataType, int bitSize, String componentName, String comment) Adds a new bitfield to the end of this composite.clone
(DataTypeManager dtm) Returns an instance of this DataType using the specifiedDataTypeManager
to allow its use of the correspondingDataOrganization
while retaining its unique identity (seeDataType.getUniversalID()
and archive association (seeDataType.getSourceArchive()
) if applicable.copy
(DataTypeManager dtm) Returns a new instance (shallow copy) of this DataType with a new identity and no source archive association.void
Notification that the given datatype's alignment has changed.void
Informs this datatype that the given datatype has been deleted.void
dataTypeReplaced
(DataType oldDt, DataType newDt) Informs this datatype that the given oldDT has been replaced with newDTvoid
Notification that the given datatype's size has changed.void
delete
(int ordinal) Deletes the component at the given ordinal position.void
Deletes the specified set of components at the given ordinal positions.boolean
Check if this datatype depends on the existence of the given datatype.int
Gets the alignment to be used when aligning this datatype within another datatype.getComponent
(int ordinal) Returns the component of this data type with the indicated ordinal.Returns an array of Data Type Components that make up this composite including undefined filler components which may be present within a Structure which has packing disabled.Returns the appropriate string to use as the default label prefix in the absence of any data.Returns an array of Data Type Components that make up this composite excluding undefined filler components which may be present within Structures where packing is disabled.int
Get the length of this DataType as a number of 8-bit bytes.int
Gets the number of component data types in this composite.int
Returns the number of explicitly defined components in this composite.getRepresentation
(MemBuffer buf, Settings settings, int length) Get bytes from memory in a printable format for this type.boolean
Indicates if the length of this data-type is determined based upon theDataOrganization
obtained from the associatedDataTypeManager
.Inserts a new datatype at the specified ordinal position in this composite.insertBitField
(int ordinal, DataType baseDataType, int bitSize, String componentName, String comment) Inserts a new bitfield at the specified ordinal position in this union.boolean
isEquivalent
(DataType dt) Check if the given datatype is equivalent to this datatype.boolean
Indicates this datatype is defined with a zero length.boolean
repack
(boolean notify) Repack components within this composite based on the current packing, alignment andDataOrganization
settings.void
replaceWith
(DataType dataType) For datatypes that support change, this method replaces the internals of this datatype with the internals of the given datatype.Methods inherited from class ghidra.program.model.data.CompositeDataTypeImpl
add, add, add, checkAncestry, dataTypeNameChanged, getAlignedLength, getAlignmentType, getDescription, getExplicitMinimumAlignment, getExplicitPackingValue, getMnemonic, getNonPackedAlignment, getPackingType, getPreferredComponentLength, getPreferredComponentLength, getStoredMinimumAlignment, getStoredPackingValue, getValue, insert, insert, isNotYetDefined, isPartOf, repack, setDescription, setExplicitMinimumAlignment, setExplicitPackingValue, setName, setPackingEnabled, setToDefaultAligned, setToDefaultPacking, setToMachineAligned, setValue, toString, updateBitFieldDataType, validateDataType
Methods inherited from class ghidra.program.model.data.GenericDataType
setCategoryPath, setNameAndCategory
Methods inherited from class ghidra.program.model.data.DataTypeImpl
addParent, equals, getDefaultSettings, getLastChangeTime, getLastChangeTimeInSourceArchive, getParents, getPathName, getSettingsDefinitions, getSourceArchive, getUniversalID, getValueClass, hashCode, notifyAlignmentChanged, notifyDeleted, notifyNameChanged, notifyParents, notifyReplaced, notifySizeChanged, removeParent, setLastChangeTime, setLastChangeTimeInSourceArchive, setSourceArchive
Methods inherited from class ghidra.program.model.data.AbstractDataType
encodeRepresentation, encodeValue, getCategoryPath, getDataOrganization, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDisplayName, getDocs, getName, getTypeDefSettingsDefinitions, isDeleted, isEncodable
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ghidra.program.model.data.Composite
add, add, add, align, getAlignmentType, getExplicitMinimumAlignment, getExplicitPackingValue, getPackingType, hasDefaultPacking, hasExplicitMinimumAlignment, hasExplicitPackingValue, insert, insert, isDefaultAligned, isMachineAligned, isPackingEnabled, isPartOf, pack, repack, setDescription, setExplicitMinimumAlignment, setExplicitPackingValue, setPackingEnabled, setToDefaultAligned, setToDefaultPacking, setToMachineAligned
Methods inherited from interface ghidra.program.model.data.CompositeInternal
getStoredMinimumAlignment, getStoredPackingValue
Methods inherited from interface ghidra.program.model.data.DataType
addParent, dataTypeNameChanged, encodeRepresentation, encodeValue, getAlignedLength, getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDefaultSettings, getDescription, getDisplayName, getDocs, getLastChangeTime, getLastChangeTimeInSourceArchive, getMnemonic, getName, getParents, getPathName, getSettingsDefinitions, getSourceArchive, getTypeDefSettingsDefinitions, getUniversalID, getValue, getValueClass, isDeleted, isEncodable, isNotYetDefined, removeParent, setCategoryPath, setLastChangeTime, setLastChangeTimeInSourceArchive, setName, setNameAndCategory, setSourceArchive
-
Constructor Details
-
UnionDataType
Construct a new empty union with the given name within the specified categry path. An empty union will report its length as 1 andCompositeDataTypeImpl.isNotYetDefined()
will return true. NOTE: A constructor form which accepts aDataTypeManager
should be used when possible since there may be performance benefits during datatype resolution.- Parameters:
path
- the category path indicating where this data type is located.name
- the name of the new union
-
UnionDataType
Construct a new empty union with the given name and datatype manager within the specified categry path. An empty union will report its length as 1 andCompositeDataTypeImpl.isNotYetDefined()
will return true.- Parameters:
path
- the category path indicating where this data type is located.name
- the name of the new uniondtm
- the data type manager associated with this data type. This can be null. Also, the data type manager may not yet contain this actual data type.
-
UnionDataType
public UnionDataType(CategoryPath path, String name, UniversalID universalID, SourceArchive sourceArchive, long lastChangeTime, long lastChangeTimeInSourceArchive, DataTypeManager dtm) Construct a new empty union with the given name within the specified categry path. An empty union will report its length as 1 andCompositeDataTypeImpl.isNotYetDefined()
will return true.- Parameters:
path
- the category path indicating where this data type is located.name
- the name of the new structureuniversalID
- the id for the data typesourceArchive
- the source archive for this data typelastChangeTime
- the last time this data type was changedlastChangeTimeInSourceArchive
- the last time this data type was changed in its source archive.dtm
- the data type manager associated with this data type. This can be null. Also, the data type manager may not contain this actual data type.
-
UnionDataType
Construct a new UnionDataType. NOTE: A constructor form which accepts aDataTypeManager
should be used when possible since there may be performance benefits during datatype resolution.- Parameters:
name
- the name of this dataType
-
-
Method Details
-
getRepresentation
Description copied from interface:DataType
Get bytes from memory in a printable format for this type.- Specified by:
getRepresentation
in interfaceDataType
- Parameters:
buf
- the data.settings
- the settings to use for the representation.length
- the number of bytes to represent.- Returns:
- the representation of the data in this format, never null.
-
getComponent
Description copied from interface:Composite
Returns the component of this data type with the indicated ordinal.- Specified by:
getComponent
in interfaceComposite
- Parameters:
ordinal
- the component's ordinal (numbering starts at 0).- Returns:
- the data type component.
-
getComponents
Description copied from interface:Composite
Returns an array of Data Type Components that make up this composite including undefined filler components which may be present within a Structure which has packing disabled. The number of components corresponds toComposite.getNumComponents()
.- Specified by:
getComponents
in interfaceComposite
- Returns:
- array all components
-
getDefinedComponents
Description copied from interface:Composite
Returns an array of Data Type Components that make up this composite excluding undefined filler components which may be present within Structures where packing is disabled. The number of components corresponds toComposite.getNumDefinedComponents()
. For Unions and packed Structures this is equivalent toComposite.getComponents()
since they do not contain undefined filler components.- Specified by:
getDefinedComponents
in interfaceComposite
- Returns:
- array all explicitly defined components
-
getNumComponents
public int getNumComponents()Description copied from interface:Composite
Gets the number of component data types in this composite. If this is Structure with packing disabled, the count will include all undefined filler components which may be present.- Specified by:
getNumComponents
in interfaceComposite
- Returns:
- the number of components that make up this composite
-
getNumDefinedComponents
public int getNumDefinedComponents()Description copied from interface:Composite
Returns the number of explicitly defined components in this composite. For Unions and packed Structures this is equivalent toComposite.getNumComponents()
since they do not contain undefined components. This count will always exclude all undefined filler components which may be present within a Structure whose packing is disabled (seeComposite.isPackingEnabled()
).- Specified by:
getNumDefinedComponents
in interfaceComposite
- Returns:
- the number of explicitly defined components in this composite
-
add
public DataTypeComponent add(DataType dataType, int length, String componentName, String comment) throws IllegalArgumentException Description copied from interface:Composite
Adds a new datatype to the end of this composite. This is the preferred method to use for adding components to an aligned structure for dynamic dataTypes such as strings whose length must be specified.- Specified by:
add
in interfaceComposite
- Parameters:
dataType
- the datatype to add.length
- the length to associate with the datatype. For fixed length types a length <= 0 will use the length of the resolved dataType.componentName
- the field name to associate with this component.comment
- the comment to associate with this component.- Returns:
- the componentDataType created.
- Throws:
IllegalArgumentException
- if the specified data type is not allowed to be added to this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to add dt1 to dt2 since this would cause a cyclic dependency.
-
insert
public DataTypeComponent insert(int ordinal, DataType dataType, int length, String componentName, String comment) throws IllegalArgumentException Description copied from interface:Composite
Inserts a new datatype at the specified ordinal position in this composite.
Note: For an aligned structure the ordinal position will get adjusted automatically to provide the proper alignment.- Specified by:
insert
in interfaceComposite
- Parameters:
ordinal
- the ordinal where the new datatype is to be inserted (numbering starts at 0).dataType
- the datatype to insert.length
- the length to associate with the datatype. For fixed length types a length <= 0 will use the length of the resolved dataType.componentName
- the field name to associate with this component.comment
- the comment to associate with this component.- Returns:
- the componentDataType created.
- Throws:
IllegalArgumentException
- if the specified data type is not allowed to be inserted into this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to insert dt1 to dt2 since this would cause a cyclic dependency.
-
addBitField
public DataTypeComponent addBitField(DataType baseDataType, int bitSize, String componentName, String comment) throws InvalidDataTypeException Description copied from interface:Composite
Adds a new bitfield to the end of this composite. This method is intended to be used with packed structures/unions only where the bitfield will be appropriately packed. The minimum storage storage byte size will be applied. It will not provide useful results for composites with packing disabled.- Specified by:
addBitField
in interfaceComposite
- Parameters:
baseDataType
- the bitfield base datatype (certain restrictions apply).bitSize
- the bitfield size in bitscomponentName
- the field name to associate with this component.comment
- the comment to associate with this component.- Returns:
- the componentDataType created whose associated data type will be BitFieldDataType.
- Throws:
InvalidDataTypeException
- if the specified data type is not a valid base type for bitfields.
-
insertBitField
public DataTypeComponent insertBitField(int ordinal, DataType baseDataType, int bitSize, String componentName, String comment) throws InvalidDataTypeException, IndexOutOfBoundsException Description copied from interface:Union
Inserts a new bitfield at the specified ordinal position in this union. For all Unions, bitfield starts with bit-0 (lsb) of the first byte for little-endian, and with bit-7 (msb) of the first byte for big-endian. This is the default behavior for most compilers. Insertion behavior may not work as expected if packing rules differ from this.- Specified by:
insertBitField
in interfaceUnion
- Parameters:
ordinal
- the ordinal where the new datatype is to be inserted (numbering starts at 0).baseDataType
- the bitfield base datatype (certain restrictions apply).bitSize
- the declared bitfield size in bits. The effective bit size may be adjusted based upon the specified baseDataType.componentName
- the field name to associate with this component.comment
- the comment to associate with this component.- Returns:
- the bitfield component created whose associated data type will be BitFieldDataType.
- Throws:
InvalidDataTypeException
- if the specified baseDataType is not a valid base type for bitfields.IndexOutOfBoundsException
- if ordinal is less than 0 or greater than the current number of components.
-
isZeroLength
public boolean isZeroLength()Description copied from interface:DataType
Indicates this datatype is defined with a zero length.This method should not be confused with
DataType.isNotYetDefined()
which indicates that nothing but the name and basic type is known.NOTE: a zero-length datatype must return a length of 1 via
DataType.getLength()
. Zero-length datatypes used as a component within aComposite
may, or may not, be assigned a component length of 0. The methodDataTypeComponent.usesZeroLengthComponent(DataType)
is used to make this determination.- Specified by:
isZeroLength
in interfaceDataType
- Overrides:
isZeroLength
in classAbstractDataType
- Returns:
- true if type definition has a length of 0, else false
-
getLength
public int getLength()Description copied from interface:DataType
Get the length of this DataType as a number of 8-bit bytes.For primitive datatypes this reflects the smallest varnode which can be used to contain its value (i.e., raw data length).
Example: For x86 32-bit gcc an 80-bit
long double
raw data length
of 10-bytes will fit within a floating point register while itsaligned-length
of 12-bytes is used by the gcc compiler for data/array/component allocations to maintain alignment (i.e.,sizeof(long double)
).NOTE: Other than the
VoidDataType
, no datatype should ever return 0, even ifDataType.isZeroLength()
, and onlyDynamic
/FactoryDataType
datatypes should return -1. IfDataType.isZeroLength()
is true a length of 1 should be returned. Where a zero-length datatype can be handled (e.g.,Composite
) theDataType.isZeroLength()
method should be used. -
hasLanguageDependantLength
public boolean hasLanguageDependantLength()Description copied from interface:DataType
Indicates if the length of this data-type is determined based upon theDataOrganization
obtained from the associatedDataTypeManager
.- Specified by:
hasLanguageDependantLength
in interfaceDataType
- Specified by:
hasLanguageDependantLength
in classCompositeDataTypeImpl
- Returns:
- true length is language/compiler-specification dependent, else false
-
clone
Description copied from interface:DataType
Returns an instance of this DataType using the specifiedDataTypeManager
to allow its use of the correspondingDataOrganization
while retaining its unique identity (seeDataType.getUniversalID()
and archive association (seeDataType.getSourceArchive()
) if applicable.This instance will be returned if this datatype's DataTypeManager matches the specified dtm. The recursion depth of a clone will stop on any datatype whose
DataTypeManager
matches the specified dtm and simply use the existing datatype instance.NOTE: In general, this method should not be used to obtain an instance to be modified. In most cases changes may be made directly to this instance if supported or to a
DataType.copy(DataTypeManager)
of this type. -
copy
Description copied from interface:DataType
Returns a new instance (shallow copy) of this DataType with a new identity and no source archive association.Any reference to other datatypes will use
DataType.clone(DataTypeManager)
. -
delete
public void delete(int ordinal) Description copied from interface:Composite
Deletes the component at the given ordinal position.
Note: Removal of bitfields from a structure with packing disabled will not shift other components causing vacated bytes to revert to undefined filler. -
delete
Description copied from interface:Composite
Deletes the specified set of components at the given ordinal positions.
Note: Removal of bitfields from a structure with packing disabled will not shift other components causing vacated bytes to revert to undefined filler. -
getAlignment
public int getAlignment()Description copied from interface:DataType
Gets the alignment to be used when aligning this datatype within another datatype.- Specified by:
getAlignment
in interfaceComposite
- Specified by:
getAlignment
in interfaceDataType
- Specified by:
getAlignment
in classCompositeDataTypeImpl
- Returns:
- this datatype's alignment.
-
repack
public boolean repack(boolean notify) Description copied from class:CompositeDataTypeImpl
Repack components within this composite based on the current packing, alignment andDataOrganization
settings. Non-packed Structures: change detection is limited to component count and length is assumed to already be correct.NOTE: If modifications to stored length are made prior to invoking this method, detection of a size change may not be possible.
NOTE: Currently a change in calculated alignment can not be provided since this value is not stored.
- Specified by:
repack
in classCompositeDataTypeImpl
- Parameters:
notify
- if true notification will be sent to parents if a size change or component placement change is detected.- Returns:
- true if a layout change was detected.
-
isEquivalent
Description copied from interface:DataType
Check if the given datatype is equivalent to this datatype.The precise meaning of "equivalent" is datatype dependent.
NOTE: if invoked by a DB object or manager it should be invoked on the DataTypeDB object passing the other datatype as the argument.- Specified by:
isEquivalent
in interfaceDataType
- Parameters:
dt
- the datatype being tested for equivalence.- Returns:
- true if the if the given datatype is equivalent to this datatype.
-
dataTypeAlignmentChanged
Description copied from interface:DataType
Notification that the given datatype's alignment has changed.DataTypes may need to make internal changes in response.
TODO: This method is reserved for internal DB use.- Specified by:
dataTypeAlignmentChanged
in interfaceComposite
- Specified by:
dataTypeAlignmentChanged
in interfaceDataType
- Overrides:
dataTypeAlignmentChanged
in classAbstractDataType
- Parameters:
dt
- the datatype that has changed.
-
dataTypeSizeChanged
Description copied from interface:DataType
Notification that the given datatype's size has changed.DataTypes may need to make internal changes in response.
TODO: This method is reserved for internal DB use.- Specified by:
dataTypeSizeChanged
in interfaceDataType
- Overrides:
dataTypeSizeChanged
in classAbstractDataType
- Parameters:
dt
- the datatype that has changed.
-
dataTypeReplaced
Description copied from interface:DataType
Informs this datatype that the given oldDT has been replaced with newDTTODO: This method is reserved for internal DB use.
- Specified by:
dataTypeReplaced
in interfaceDataType
- Overrides:
dataTypeReplaced
in classAbstractDataType
- Parameters:
oldDt
- old datatypenewDt
- new datatype- Throws:
IllegalArgumentException
-
dataTypeDeleted
Description copied from interface:DataType
Informs this datatype that the given datatype has been deleted.TODO: This method is reserved for internal DB use.
- Specified by:
dataTypeDeleted
in interfaceDataType
- Overrides:
dataTypeDeleted
in classAbstractDataType
- Parameters:
dt
- the datatype that has been deleted.
-
replaceWith
Description copied from interface:DataType
For datatypes that support change, this method replaces the internals of this datatype with the internals of the given datatype.The datatypes must be of the same "type" (i.e. structure can only be replacedWith another structure.
- Specified by:
replaceWith
in interfaceDataType
- Overrides:
replaceWith
in classDataTypeImpl
- Parameters:
dataType
- the datatype that contains the internals to upgrade to.- Throws:
IllegalArgumentException
- if the given datatype is not the same type as this datatype.
-
dependsOn
Description copied from interface:DataType
Check if this datatype depends on the existence of the given datatype.For example byte[] depends on byte. If byte were deleted, then byte[] would also be deleted.
- Specified by:
dependsOn
in interfaceDataType
- Overrides:
dependsOn
in classAbstractDataType
- Parameters:
dt
- the datatype to test that this datatype depends on.- Returns:
- true if the existence of this datatype relies on the existence of the specified datatype dt.
-
getDefaultLabelPrefix
Description copied from interface:DataType
Returns the appropriate string to use as the default label prefix in the absence of any data.- Specified by:
getDefaultLabelPrefix
in interfaceDataType
- Overrides:
getDefaultLabelPrefix
in classAbstractDataType
- Returns:
- the default label prefix or null if none specified.
-