Class CompositeDataTypeImpl
- java.lang.Object
-
- ghidra.program.model.data.AbstractDataType
-
- ghidra.program.model.data.DataTypeImpl
-
- ghidra.program.model.data.GenericDataType
-
- ghidra.program.model.data.CompositeDataTypeImpl
-
- All Implemented Interfaces:
Composite
,CompositeInternal
,DataType
- Direct Known Subclasses:
StructureDataType
,UnionDataType
public abstract class CompositeDataTypeImpl extends GenericDataType implements CompositeInternal
Common implementation methods for structure and union
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ghidra.program.model.data.CompositeInternal
CompositeInternal.ComponentComparator, CompositeInternal.OffsetComparator, CompositeInternal.OrdinalComparator
-
-
Field Summary
Fields Modifier and Type Field Description protected int
minimumAlignment
protected int
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
DEFAULT_ALIGNMENT, DEFAULT_PACKING, MACHINE_ALIGNMENT, NO_PACKING
-
Fields inherited from interface ghidra.program.model.data.DataType
CONFLICT_SUFFIX, DEFAULT, NO_LAST_CHANGE_TIME, NO_SOURCE_SYNC_TIME, VOID
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DataTypeComponent
add(DataType dataType)
Adds a new datatype to the end of this composite.DataTypeComponent
add(DataType dataType, int length)
Adds a new datatype to the end of this composite.DataTypeComponent
add(DataType dataType, java.lang.String fieldName, java.lang.String comment)
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.void
dataTypeNameChanged(DataType dt, java.lang.String oldName)
Informs this datatype that its name has changed from the indicated old name.abstract int
getAlignment()
Gets the alignment to be used when aligning this datatype within another datatype.AlignmentType
getAlignmentType()
java.lang.String
getDescription()
Get a String briefly describing this DataType.int
getExplicitMinimumAlignment()
Get the explicit minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment()
.int
getExplicitPackingValue()
Gets the current packing value (typically a power of 2).java.lang.String
getMnemonic(Settings settings)
Get the mnemonic for this DataType.protected int
getNonPackedAlignment()
PackingType
getPackingType()
protected int
getPreferredComponentLength(DataType dataType, int length)
Get the preferred length for a new component.int
getStoredMinimumAlignment()
Get the minimum alignment setting for this Composite which contributes to the actual computed alignment value (seeComposite.getAlignment()
.int
getStoredPackingValue()
Gets the current packing value (typically a power of 2).java.lang.Object
getValue(MemBuffer buf, Settings settings, int length)
Get the data in the form of the appropriate Object for this DataType.abstract boolean
hasLanguageDependantLength()
Indicates if the length of this data-type is determined based upon theDataOrganization
obtained from the associatedDataTypeManager
.DataTypeComponent
insert(int ordinal, DataType dataType)
Inserts a new datatype at the specified ordinal position in this composite.DataTypeComponent
insert(int ordinal, DataType dataType, int length)
Inserts a new datatype at the specified ordinal position in this composite.boolean
isNotYetDefined()
Determine if this composite should be treated as undefined.boolean
isPartOf(DataType dataTypeOfInterest)
Check if a data type is part of this data type.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(java.lang.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
setName(java.lang.String name)
Sets the name of the datatypevoid
setPackingEnabled(boolean enabled)
Sets whether this data type's internal components are currently packed.void
setToDefaultAligned()
Sets this data type's alignment to its default alignment.void
setToDefaultPacking()
Enables default packing behavior.void
setToMachineAligned()
Sets this data type's minimum alignment to the machine alignment which is specified byDataOrganization.getMachineAlignment()
.void
setValue(MemBuffer buf, Settings settings, int length, java.lang.Object value)
java.lang.String
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, setDefaultSettings, setLastChangeTime, setLastChangeTimeInSourceArchive, setSourceArchive
-
Methods inherited from class ghidra.program.model.data.AbstractDataType
dataTypeAlignmentChanged, dataTypeDeleted, dataTypeReplaced, dataTypeSizeChanged, dependsOn, encodeRepresentation, encodeValue, getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDisplayName, getDocs, getName, 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, getUniversalID, getValueClass, isDeleted, isEncodable, isEquivalent, isZeroLength, removeParent, replaceWith, setCategoryPath, setDefaultSettings, setLastChangeTime, setLastChangeTimeInSourceArchive, setNameAndCategory, setSourceArchive
-
-
-
-
Method Detail
-
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
public void dataTypeNameChanged(DataType dt, java.lang.String oldName)
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
protected int getPreferredComponentLength(DataType dataType, int length)
Get the preferred length for a new component. For Unions and internally aligned structures the preferred component length for a fixed-length dataType will be the length of that dataType. Otherwise the length returned will be no larger than the specified length.- Parameters:
dataType
- new component datatypelength
- constrained length or -1 to force use of dataType size. Dynamic types such as string must have a positive length specified.- Returns:
- preferred component length
-
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
public boolean isPartOf(DataType dataTypeOfInterest)
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
protected void checkAncestry(DataType dataType) throws java.lang.IllegalArgumentException
This method throws an exception if the indicated data type is an ancestor of this data type. In other words, the specified data type has a component or sub-component containing this data type.- Parameters:
dataType
- the data type- Throws:
java.lang.IllegalArgumentException
- if the data type is an ancestor of this data type.
-
validateDataType
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. 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:
java.lang.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
public void setDescription(java.lang.String desc)
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
public java.lang.String 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
public java.lang.Object getValue(MemBuffer buf, Settings settings, int length)
Description copied from interface:DataType
Get the data in the form of the appropriate Object for this DataType.For instance if the datatype is an AddressDT, return an Address object. a Byte, return a Scalar* (maybe this should be a Byte) a Float, return a Float
-
setValue
public void setValue(MemBuffer buf, Settings settings, int length, java.lang.Object value)
-
add
public final DataTypeComponent add(DataType dataType)
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
public final DataTypeComponent add(DataType dataType, int length)
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
public final DataTypeComponent add(DataType dataType, java.lang.String fieldName, java.lang.String comment)
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
public final DataTypeComponent insert(int ordinal, DataType dataType, int length)
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.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
public final DataTypeComponent insert(int ordinal, DataType dataType)
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
public java.lang.String getMnemonic(Settings settings)
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
public void setName(java.lang.String name) throws InvalidNameException
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
public PackingType 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
public AlignmentType 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
public java.lang.String toString()
- Overrides:
toString
in classAbstractDataType
-
-