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
FieldsFields inherited from class ghidra.program.model.data.DataTypeImpl
defaultSettingsFields inherited from class ghidra.program.model.data.AbstractDataType
categoryPath, dataMgr, nameFields 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_NAMEFields 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 DataTypeComponentAdds a new datatype to the end of this composite.final DataTypeComponentAdds a new datatype to the end of this composite.final DataTypeComponentAdds a new datatype to the end of this composite.protected voidcheckAncestry(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).voiddataTypeNameChanged(DataType dt, String oldName) Informs this datatype that its name has changed from the indicated old name.final intGet the aligned-length of this datatype as a number of 8-bit bytes.abstract intGets the alignment to be used when aligning this datatype within another datatype.Get a String briefly describing this DataType.intGet the explicit minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment().intGets the current packing value (typically a power of 2).getMnemonic(Settings settings) Get the mnemonic for this DataType.protected final intprotected intgetPreferredComponentLength(DataType dataType, int length) Get the preferred length for a new component.protected intgetPreferredComponentLength(DataType dataType, int length, int maxLength) Get the preferred length for a new component.intGet the minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment().intGets the current packing value (typically a power of 2).Returns the interpreted data value as an instance of theadvertised value class.abstract booleanIndicates if the length of this data-type is determined based upon theDataOrganizationobtained from the associatedDataTypeManager.final DataTypeComponentInserts a new datatype at the specified ordinal position in this composite.final DataTypeComponentInserts a new datatype at the specified ordinal position in this composite.final booleanDetermine if this composite should be treated as undefined.booleanCheck if a data type is part of this data type.final voidrepack()Updates packed composite to any changes in the data organization.abstract booleanrepack(boolean notify) Repack components within this composite based on the current packing, alignment andDataOrganizationsettings.voidsetDescription(String desc) Sets a String briefly describing this DataType.voidsetExplicitMinimumAlignment(int minimumAlignment) Sets this data type's explicit minimum alignment (positive value).voidsetExplicitPackingValue(int packingValue) Sets the pack value for this composite (positive value, usually a power of 2).voidSets the name of the datatypevoidsetPackingEnabled(boolean enabled) Sets whether this data type's internal components are currently packed.voidSets this data type's alignment to its default alignment.voidEnables default packing behavior.voidSets this data type's minimum alignment to the machine alignment which is specified byDataOrganization.getMachineAlignment().voidtoString()protected booleanupdateBitFieldDataType(DataTypeComponentImpl bitfieldComponent, DataType oldDt, DataType newDt) Handle replacement of datatype which may impact bitfield datatype.protected DataTypevalidateDataType(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, setNameAndCategoryMethods 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, setSourceArchiveMethods 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, getName, getTypeDefSettingsDefinitions, isDeleted, isEncodable, isZeroLengthMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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, packMethods 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, 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:DataTypeGet 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
Arrayelement length or component sizing for aComposite. ForPointer,CompositeandArraytypes this will return the same value asDataType.getLength().Example: For x86 32-bit gcc an 80-bit
long doubleraw data lengthof 10-bytes will fit within a floating point register while itsaligned-lengthof 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/FunctionDefinitiondatatypes should return -1. IfDataType.isZeroLength()is true a length of 1 should be returned.- Specified by:
getAlignedLengthin interfaceDataType- Overrides:
getAlignedLengthin classDataTypeImpl- Returns:
- byte length of binary encoding.
-
getStoredPackingValue
public int getStoredPackingValue()Description copied from interface:CompositeInternalGets the current packing value (typically a power of 2). Other special values which may be returned include 0 and -1.- Specified by:
getStoredPackingValuein interfaceCompositeInternal- Returns:
- the current positive packing value, 0 or -1.
-
getStoredMinimumAlignment
public int getStoredMinimumAlignment()Description copied from interface:CompositeInternalGet the minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment().- Specified by:
getStoredMinimumAlignmentin interfaceCompositeInternal- Returns:
- the minimum alignment setting for this Composite or a reserved value to indicate
either
CompositeInternal.DEFAULT_ALIGNMENTorCompositeInternal.MACHINE_ALIGNMENT.
-
dataTypeNameChanged
Description copied from interface:DataTypeInforms this datatype that its name has changed from the indicated old name.TODO: This method is reserved for internal DB use.
- Specified by:
dataTypeNameChangedin interfaceDataType- Overrides:
dataTypeNameChangedin 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 aDynamicdataType.
-
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 aDynamicdataType.
-
hasLanguageDependantLength
public abstract boolean hasLanguageDependantLength()Description copied from interface:DataTypeIndicates if the length of this data-type is determined based upon theDataOrganizationobtained from the associatedDataTypeManager.- Specified by:
hasLanguageDependantLengthin interfaceDataType- Overrides:
hasLanguageDependantLengthin 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
DataTypeComponentdefined 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:
isNotYetDefinedin interfaceDataType- Overrides:
isNotYetDefinedin classAbstractDataType- Returns:
- true if this type is not yet defined.
-
isPartOf
Description copied from interface:CompositeCheck 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) 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
-
setDescription
Description copied from class:DataTypeImplSets 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:
setDescriptionin interfaceComposite- Specified by:
setDescriptionin interfaceDataType- Overrides:
setDescriptionin classDataTypeImpl- Parameters:
desc- a one-liner describing this DataType.
-
getDescription
Description copied from interface:DataTypeGet a String briefly describing this DataType.- Specified by:
getDescriptionin interfaceDataType- Returns:
- a one-liner describing this DataType.
-
getValue
Description copied from interface:DataTypeReturns the interpreted data value as an instance of theadvertised value class.For instance,
Pointerdata types should return an Address object (or null), or integer data types should return aScalarobject.- Specified by:
getValuein interfaceDataType- Parameters:
buf- the data buffersettings- the settings to use.length- indicates the maximum number of bytes that may be consumed by aDynamicdatatype, 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:CompositeAdds 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:CompositeAdds 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:CompositeAdds 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:CompositeInserts 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:
insertin 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:CompositeInserts 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:DataTypeGet the mnemonic for this DataType.- Specified by:
getMnemonicin interfaceDataType- Overrides:
getMnemonicin classAbstractDataType- Parameters:
settings- settings which may influence the result or null- Returns:
- the mnemonic for this DataType.
-
setName
Description copied from interface:DataTypeSets the name of the datatype- Specified by:
setNamein interfaceDataType- Overrides:
setNamein 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:CompositeUpdates 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 andDataOrganizationsettings. 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:CompositeSets whether this data type's internal components are currently packed. The affect of disabled packing differs betweenStructureandUnion. 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:
setPackingEnabledin interfaceComposite- Parameters:
enabled- true enables packing of components respecting component alignment and pack setting, whereas false disables packing.
-
getPackingType
- Specified by:
getPackingTypein interfaceComposite- Returns:
- the packing type set for this composite
-
setToDefaultPacking
public void setToDefaultPacking()Description copied from interface:CompositeEnables 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:
setToDefaultPackingin interfaceComposite
-
getExplicitPackingValue
public int getExplicitPackingValue()Description copied from interface:CompositeGets 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:
getExplicitPackingValuein interfaceComposite- Returns:
- the current packing value or an undefined non-positive value
-
setExplicitPackingValue
public void setExplicitPackingValue(int packingValue) Description copied from interface:CompositeSets 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:
setExplicitPackingValuein interfaceComposite- Parameters:
packingValue- the new positive packing value.
-
getAlignmentType
- Specified by:
getAlignmentTypein interfaceComposite- Returns:
- the alignment type set for this composite
-
setToDefaultAligned
public void setToDefaultAligned()Description copied from interface:CompositeSets 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:
setToDefaultAlignedin interfaceComposite
-
setToMachineAligned
public void setToMachineAligned()Description copied from interface:CompositeSets 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:
setToMachineAlignedin interfaceComposite
-
getExplicitMinimumAlignment
public int getExplicitMinimumAlignment()Description copied from interface:CompositeGet the explicit minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment().- Specified by:
getExplicitMinimumAlignmentin 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:CompositeSets 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:
setExplicitMinimumAlignmentin interfaceComposite- Parameters:
minimumAlignment- the minimum alignment for this Composite.
-
getNonPackedAlignment
protected final int getNonPackedAlignment() -
getAlignment
public abstract int getAlignment()Description copied from interface:DataTypeGets the alignment to be used when aligning this datatype within another datatype.- Specified by:
getAlignmentin interfaceComposite- Specified by:
getAlignmentin interfaceDataType- Overrides:
getAlignmentin classDataTypeImpl- Returns:
- this datatype's alignment.
-
toString
- Overrides:
toStringin classAbstractDataType
-