Class CompositeDataTypeImpl
- All Implemented Interfaces:
Composite
,CompositeInternal
,DataType
- Direct Known Subclasses:
StructureDataType
,UnionDataType
-
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.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
-
Method Summary
Modifier and TypeMethodDescriptionfinal DataTypeComponent
Adds a new datatype to the end of this composite.final DataTypeComponent
Adds a new datatype to the end of this composite.final DataTypeComponent
Adds a new datatype to the end of this composite.protected void
checkAncestry
(DataType dataType) This method throws an exception if the indicated data type is an ancestor of this data type (i.e., the specified data type has a component or sub-component containing this data type).void
dataTypeNameChanged
(DataType dt, String oldName) Informs this datatype that its name has changed from the indicated old name.final int
Get the aligned-length of this datatype as a number of 8-bit bytes.abstract int
Gets the alignment to be used when aligning this datatype within another datatype.Get a String briefly describing this DataType.int
Get the explicit minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment()
.int
Gets the current packing value (typically a power of 2).getMnemonic
(Settings settings) Get the mnemonic for this DataType.protected final int
protected int
getPreferredComponentLength
(DataType dataType, int length) Get the preferred length for a new component.protected int
getPreferredComponentLength
(DataType dataType, int length, int maxLength) Get the preferred length for a new component.int
Get the minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment()
.int
Gets the current packing value (typically a power of 2).Returns the interpreted data value as an instance of theadvertised value class
.abstract boolean
Indicates if the length of this data-type is determined based upon theDataOrganization
obtained from the associatedDataTypeManager
.final DataTypeComponent
Inserts a new datatype at the specified ordinal position in this composite.final DataTypeComponent
Inserts a new datatype at the specified ordinal position in this composite.final boolean
Determine if this composite should be treated as undefined.boolean
Check if a data type is part of this data type.final void
repack()
Updates packed composite to any changes in the data organization.abstract boolean
repack
(boolean notify) Repack components within this composite based on the current packing, alignment andDataOrganization
settings.void
setDescription
(String desc) Sets a String briefly describing this DataType.void
setExplicitMinimumAlignment
(int minimumAlignment) Sets this data type's explicit minimum alignment (positive value).void
setExplicitPackingValue
(int packingValue) Sets the pack value for this composite (positive value, usually a power of 2).void
Sets the name of the datatypevoid
setPackingEnabled
(boolean enabled) Sets whether this data type's internal components are currently packed.void
Sets this data type's alignment to its default alignment.void
Enables default packing behavior.void
Sets this data type's minimum alignment to the machine alignment which is specified byDataOrganization.getMachineAlignment()
.void
toString()
protected boolean
updateBitFieldDataType
(DataTypeComponentImpl bitfieldComponent, DataType oldDt, DataType newDt) Handle replacement of datatype which may impact bitfield datatype.protected DataType
validateDataType
(DataType dataType) This method throws an exception if the indicated data type is not a valid data type for a component of this composite data type.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, replaceWith, setLastChangeTime, setLastChangeTimeInSourceArchive, setSourceArchive
Methods inherited from class ghidra.program.model.data.AbstractDataType
dataTypeAlignmentChanged, dataTypeDeleted, dataTypeReplaced, dataTypeSizeChanged, dependsOn, encodeRepresentation, encodeValue, getCategoryPath, getDataOrganization, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDisplayName, getDocs, getName, getTypeDefSettingsDefinitions, isDeleted, isEncodable, isZeroLength
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, addBitField, align, dataTypeAlignmentChanged, delete, delete, getComponent, getComponents, getDefinedComponents, getNumComponents, getNumDefinedComponents, hasDefaultPacking, hasExplicitMinimumAlignment, hasExplicitPackingValue, insert, isDefaultAligned, isMachineAligned, isPackingEnabled, pack
Methods inherited from interface ghidra.program.model.data.DataType
addParent, clone, copy, dataTypeDeleted, dataTypeReplaced, dataTypeSizeChanged, dependsOn, encodeRepresentation, encodeValue, getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDefaultSettings, getDisplayName, getDocs, getLastChangeTime, getLastChangeTimeInSourceArchive, getLength, getName, getParents, getPathName, getRepresentation, getSettingsDefinitions, getSourceArchive, getTypeDefSettingsDefinitions, getUniversalID, getValueClass, isDeleted, isEncodable, isEquivalent, isZeroLength, removeParent, replaceWith, setCategoryPath, setLastChangeTime, setLastChangeTimeInSourceArchive, setNameAndCategory, setSourceArchive
-
Field Details
-
minimumAlignment
protected int minimumAlignment -
packing
protected int packing
-
-
Method Details
-
getAlignedLength
public final int getAlignedLength()Description copied from interface:DataType
Get the aligned-length of this datatype as a number of 8-bit bytes.For primitive datatypes this is equivalent to the C/C++ "sizeof" operation within source code and should be used when determining
Array
element length or component sizing for aComposite
. ForPointer
,Composite
andArray
types this will return the same value asDataType.getLength()
.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
/FunctionDefinition
datatypes should return -1. IfDataType.isZeroLength()
is true a length of 1 should be returned.- Specified by:
getAlignedLength
in interfaceDataType
- Overrides:
getAlignedLength
in classDataTypeImpl
- Returns:
- byte length of binary encoding.
-
getStoredPackingValue
public int getStoredPackingValue()Description copied from interface:CompositeInternal
Gets the current packing value (typically a power of 2). Other special values which may be returned include 0 and -1.- Specified by:
getStoredPackingValue
in interfaceCompositeInternal
- Returns:
- the current positive packing value, 0 or -1.
-
getStoredMinimumAlignment
public int getStoredMinimumAlignment()Description copied from interface:CompositeInternal
Get the minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment()
.- Specified by:
getStoredMinimumAlignment
in interfaceCompositeInternal
- Returns:
- the minimum alignment setting for this Composite or a reserved value to indicate
either
CompositeInternal.DEFAULT_ALIGNMENT
orCompositeInternal.MACHINE_ALIGNMENT
.
-
dataTypeNameChanged
Description copied from interface:DataType
Informs this datatype that its name has changed from the indicated old name.TODO: This method is reserved for internal DB use.
- Specified by:
dataTypeNameChanged
in interfaceDataType
- Overrides:
dataTypeNameChanged
in classAbstractDataType
- Parameters:
dt
- the datatype whose name changedoldName
- the datatype's old name
-
getPreferredComponentLength
Get the preferred length for a new component. If type is dynamic length must be specified (assumingDynamic.canSpecifyLength()
is true). Otherwise, when packing is enabled theDataType.getAlignedLength()
is returned; when packing disabled for Union use of fixed-length type size is forced. Otherwise the decision is deferred toDataTypeComponentImpl.getPreferredComponentLength(DataType, int)
. During packing the actual component length may be changed.- Parameters:
dataType
- new component datatypelength
- constrained length or -1 to force use of dataType size for non-packing. Dynamic types such as string must have a positive length specified. This value is ignored for fixed-length types if maxLength has been specified.maxLength
- applies to non-packed structures only to indicate available space for fixed-length types usingDataType.getLength()
. Specify -1 to ignore this value.- Returns:
- preferred component length
- Throws:
IllegalArgumentException
- if length not specified for aDynamic
dataType.
-
getPreferredComponentLength
Get the preferred length for a new component. If type is dynamic length must be specified (assumingDynamic.canSpecifyLength()
is true). Otherwise, when packing is enabled theDataType.getAlignedLength()
is returned; when packing disabled for Union use of fixed-length type size is forced. Otherwise the decision is deferred toDataTypeComponentImpl.getPreferredComponentLength(DataType, int)
. During packing the actual component length may be changed.- Parameters:
dataType
- new component datatypelength
- constrained length or -1 to force use of dataType size for non-packing. Dynamic types such as string must have a positive length specified.- Returns:
- preferred component length
- Throws:
IllegalArgumentException
- if length not specified for aDynamic
dataType.
-
hasLanguageDependantLength
public abstract 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
- Overrides:
hasLanguageDependantLength
in classAbstractDataType
- Returns:
- true length is language/compiler-specification dependent, else false
-
isNotYetDefined
public final boolean isNotYetDefined()Determine if this composite should be treated as undefined.A composite is considered undefined with a zero-length when it has no components and packing is disabled. A
DataTypeComponent
defined by an an datatype which is not-yet-defined (i.e.,DataType.isNotYetDefined()
is true) will always have a size of 1. If an empty composite should be treated as fully specified, packing on the composite should be enabled to ensure that a zero-length component is used should the occassion arise (e.g., empty structure placed within union as a component).- Specified by:
isNotYetDefined
in interfaceDataType
- Overrides:
isNotYetDefined
in classAbstractDataType
- Returns:
- true if this type is not yet defined.
-
isPartOf
Description copied from interface:Composite
Check if a data type is part of this data type. A data type could be part of another by:
Being the same data type.
containing the data type directly
containing another data type that has the data type as a part of it. -
checkAncestry
This method throws an exception if the indicated data type is an ancestor of this data type (i.e., the specified data type has a component or sub-component containing this data type).- Parameters:
dataType
- the data type- Throws:
IllegalArgumentException
- if the data type is an ancestor of this data type.
-
validateDataType
This method throws an exception if the indicated data type is not a valid data type for a component of this composite data type. If the DEFAULT datatype is specified when unsupported an Undefined1 will be returned in its place (e.g., packing enabled, Union).- Parameters:
dataType
- the data type to be checked.- Returns:
- datatype to be used for insert/add
- Throws:
IllegalArgumentException
- if the data type is invalid.
-
updateBitFieldDataType
protected boolean updateBitFieldDataType(DataTypeComponentImpl bitfieldComponent, DataType oldDt, DataType newDt) throws InvalidDataTypeException Handle replacement of datatype which may impact bitfield datatype.- Parameters:
bitfieldComponent
- bitfield componentoldDt
- affected datatype which has been removed or replacednewDt
- replacement datatype- Returns:
- true if bitfield component was modified
- Throws:
InvalidDataTypeException
- if new datatype is not
-
setDescription
Description copied from class:DataTypeImpl
Sets a String briefly describing this DataType.
If a data type that extends this class wants to allow the description to be changed, then it must override this method.- Specified by:
setDescription
in interfaceComposite
- Specified by:
setDescription
in interfaceDataType
- Overrides:
setDescription
in classDataTypeImpl
- Parameters:
desc
- a one-liner describing this DataType.
-
getDescription
Description copied from interface:DataType
Get a String briefly describing this DataType.- Specified by:
getDescription
in interfaceDataType
- Returns:
- a one-liner describing this DataType.
-
getValue
Description copied from interface:DataType
Returns the interpreted data value as an instance of theadvertised value class
.For instance,
Pointer
data types should return an Address object (or null), or integer data types should return aScalar
object.- Specified by:
getValue
in interfaceDataType
- Parameters:
buf
- the data buffersettings
- the settings to use.length
- indicates the maximum number of bytes that may be consumed by aDynamic
datatype, otherwise this value is ignored. A value of -1 may be specified to allow a Dynamic datatype to determine the length based upon the actual data bytes- Returns:
- the data object, or null if data is invalid
-
setValue
-
add
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 fixed-length dataTypes. -
add
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. -
add
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 fixed-length dataTypes. -
insert
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.- Returns:
- the componentDataType created.
-
insert
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. -
getMnemonic
Description copied from interface:DataType
Get the mnemonic for this DataType.- Specified by:
getMnemonic
in interfaceDataType
- Overrides:
getMnemonic
in classAbstractDataType
- Parameters:
settings
- settings which may influence the result or null- Returns:
- the mnemonic for this DataType.
-
setName
Description copied from interface:DataType
Sets the name of the datatype- Specified by:
setName
in interfaceDataType
- Overrides:
setName
in classGenericDataType
- Parameters:
name
- the new name for this datatype.- Throws:
InvalidNameException
- if the given name does not form a valid name.
-
repack
public final void repack()Description copied from interface:Composite
Updates packed composite to any changes in the data organization. If the composite does not have packing enabled this method does nothing.
NOTE: Changes to data organization is discouraged. Attempts to use this method in such cases should be performed on all composites in dependency order (ignoring pointer components). -
repack
public abstract boolean repack(boolean notify) 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.
- 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.
-
setPackingEnabled
public void setPackingEnabled(boolean enabled) Description copied from interface:Composite
Sets whether this data type's internal components are currently packed. The affect of disabled packing differs betweenStructure
andUnion
. When packing disabled:- Structures utilize explicit component offsets and produce undefined filler components where defined components do not consume space.
- Unions always place components at offset 0 and do not pad for alignment.
- Specified by:
setPackingEnabled
in interfaceComposite
- Parameters:
enabled
- true enables packing of components respecting component alignment and pack setting, whereas false disables packing.
-
getPackingType
- Specified by:
getPackingType
in interfaceComposite
- Returns:
- the packing type set for this composite
-
setToDefaultPacking
public void setToDefaultPacking()Description copied from interface:Composite
Enables default packing behavior. If packing was previously disabled, packing will be enabled. Composite will automatically pack based upon the alignment requirements of its components with overall composite length possibly influenced by the composite's minimum alignment setting.- Specified by:
setToDefaultPacking
in interfaceComposite
-
getExplicitPackingValue
public int getExplicitPackingValue()Description copied from interface:Composite
Gets the current packing value (typically a power of 2). If this isn't a packed composite with an explicit packing value (seeComposite.hasExplicitPackingValue()
) then the return value is undefined.- Specified by:
getExplicitPackingValue
in interfaceComposite
- Returns:
- the current packing value or an undefined non-positive value
-
setExplicitPackingValue
public void setExplicitPackingValue(int packingValue) Description copied from interface:Composite
Sets the pack value for this composite (positive value, usually a power of 2). If packing was previously disabled, packing will be enabled. This value will establish the maximum effective alignment for this composite and each of the components during the alignment computation (e.g., a value of 1 will eliminate any padding). The overall composite length may be influenced by the composite's minimum alignment setting.- Specified by:
setExplicitPackingValue
in interfaceComposite
- Parameters:
packingValue
- the new positive packing value.
-
getAlignmentType
- Specified by:
getAlignmentType
in interfaceComposite
- Returns:
- the alignment type set for this composite
-
setToDefaultAligned
public void setToDefaultAligned()Description copied from interface:Composite
Sets this data type's alignment to its default alignment. For packed composites, this data type's alignment will be based upon the components it contains and its current pack settings. This is the default state and only needs to be used when changing from a non-default alignment type.- Specified by:
setToDefaultAligned
in interfaceComposite
-
setToMachineAligned
public void setToMachineAligned()Description copied from interface:Composite
Sets this data type's minimum alignment to the machine alignment which is specified byDataOrganization.getMachineAlignment()
. The machine alignment is defined as the maximum useful alignment for the target machine.- Specified by:
setToMachineAligned
in interfaceComposite
-
getExplicitMinimumAlignment
public int getExplicitMinimumAlignment()Description copied from interface:Composite
Get the explicit minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment()
.- Specified by:
getExplicitMinimumAlignment
in interfaceComposite
- Returns:
- the minimum alignment setting for this Composite or an undefined non-positive value if an explicit minimum alignment has not been set.
-
setExplicitMinimumAlignment
public void setExplicitMinimumAlignment(int minimumAlignment) Description copied from interface:Composite
Sets this data type's explicit minimum alignment (positive value). Together with the pack setting and component alignments will affect the actual computed alignment of this composite. When packing is enabled, the alignment setting may also affect padding at the end of the composite and its length. When packing is disabled, this setting will not affect the length of this composite.- Specified by:
setExplicitMinimumAlignment
in interfaceComposite
- Parameters:
minimumAlignment
- the minimum alignment for this Composite.
-
getNonPackedAlignment
protected final int getNonPackedAlignment() -
getAlignment
public abstract 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
- Overrides:
getAlignment
in classDataTypeImpl
- Returns:
- this datatype's alignment.
-
toString
- Overrides:
toString
in classAbstractDataType
-