Package ghidra.program.model.data
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
,DataType
,java.util.EventListener
,javax.swing.event.ChangeListener
- Direct Known Subclasses:
StructureDataType
,UnionDataType
public abstract class CompositeDataTypeImpl extends GenericDataType implements Composite
Common implementation methods for structure and union
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ghidra.program.model.data.Composite
Composite.AlignmentType, Composite.NamedAlignment
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
aligned
protected Composite.AlignmentType
alignmentType
protected int
externalAlignment
protected int
packingValue
-
Fields inherited from class ghidra.program.model.data.GenericDataType
packed
-
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.Composite
DEFAULT_ALIGNMENT_VALUE, NOT_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 abstract void
adjustInternalAlignment()
Adjusts the internal alignment of components within this composite based on the current settings of the internal alignment, packing, alignment type and minimum alignment value.protected void
checkAncestry(DataType dataType)
This method throws an exception if the indicated data type is an ancestor of this data type.protected void
dumpComponents(java.lang.StringBuilder buffer, java.lang.String pad)
Dump all components for use intoString()
representation.int
getAlignment()
Gets the alignment to be used when aligning this data type within another data type.java.lang.String
getDescription()
Get a String briefly describing this DataType.int
getMinimumAlignment()
Get the external alignment (a minimum alignment) for this DataType.java.lang.String
getMnemonic(Settings settings)
Get the mnemonic for this DataType.int
getPackingValue()
Gets the current packing value (typically a power of 2).protected int
getPreferredComponentLength(DataType dataType, int length)
Get the preferred length for a new component.java.lang.Object
getValue(MemBuffer buf, Settings settings, int length)
Get the data in the form of the appropriate Object for this DataType.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
isDefaultAligned()
Whether or not this data type is using the default external (minimum) alignment.boolean
isDynamicallySized()
Indicates if this data-type is dynamically sized based upon DataOrganization.boolean
isInternallyAligned()
Determine if this data type has its internal components currently aligned.boolean
isMachineAligned()
Whether or not this data type is using the machine alignment value from the DataOrganization for its external (minimum) alignment.boolean
isPartOf(DataType dataTypeOfInterest)
Check if a data type is part of this data type.protected void
notifyAlignmentChanged()
Notify any parent data types that this composite data type's alignment has changed.protected void
setAlignment(Composite composite)
void
setDescription(java.lang.String desc)
Sets a String briefly describing this DataType.void
setInternallyAligned(boolean aligned)
Sets whether this data type's internal components are currently aligned or unaligned.void
setMinimumAlignment(int externalAlignment)
Sets the external alignment (a minimum alignment) for this DataType.void
setName(java.lang.String name)
Sets the name of the dataTypevoid
setPackingValue(int packingValue)
Sets the current packing value (usually a power of 2).void
setToDefaultAlignment()
Sets this data type's external (minimum) alignment to the default alignment.void
setToMachineAlignment()
Sets this data type's external (minimum) alignment to a multiple of the machine alignment that is specified in the DataOrganization.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 void
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, notifyDeleted, notifyNameChanged, notifyReplaced, notifySizeChanged, removeParent, replaceWith, setDefaultSettings, setLastChangeTime, setLastChangeTimeInSourceArchive, setSourceArchive, stateChanged
-
Methods inherited from class ghidra.program.model.data.AbstractDataType
dataTypeDeleted, dataTypeNameChanged, dataTypeReplaced, dataTypeSizeChanged, dependsOn, getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDisplayName, getDocs, getName, isDeleted, isNotYetDefined
-
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, dataTypeAlignmentChanged, delete, delete, getBitFieldPacking, getComponent, getComponents, getNumComponents, insert, realign
-
Methods inherited from interface ghidra.program.model.data.DataType
addParent, clone, copy, dataTypeDeleted, dataTypeNameChanged, dataTypeReplaced, dataTypeSizeChanged, dependsOn, getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDefaultSettings, getDisplayName, getDocs, getLastChangeTime, getLastChangeTimeInSourceArchive, getLength, getName, getParents, getPathName, getRepresentation, getSettingsDefinitions, getSourceArchive, getUniversalID, getValueClass, isDeleted, isEquivalent, isNotYetDefined, removeParent, replaceWith, setCategoryPath, setDefaultSettings, setLastChangeTime, setLastChangeTimeInSourceArchive, setNameAndCategory, setSourceArchive
-
-
-
-
Field Detail
-
aligned
protected boolean aligned
-
alignmentType
protected Composite.AlignmentType alignmentType
-
packingValue
protected int packingValue
-
externalAlignment
protected int externalAlignment
-
-
Method Detail
-
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
-
isDynamicallySized
public boolean isDynamicallySized()
Description copied from interface:DataType
Indicates if this data-type is dynamically sized based upon DataOrganization.- Specified by:
isDynamicallySized
in interfaceDataType
- Overrides:
isDynamicallySized
in classAbstractDataType
-
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)
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 void 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.- Parameters:
dataType
- the data type to be checked.- 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 datatypetrue
- 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 data type 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
- 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.
-
getPackingValue
public int getPackingValue()
Description copied from interface:Composite
Gets the current packing value (typically a power of 2). If this isn't a packed data type then NOT_PACKING is returned. The packing value only pertains to internally aligned composite data types. Aligned structures allow packing.- Specified by:
getPackingValue
in interfaceComposite
- Returns:
- the current packing value or NOT_PACKING.
-
setPackingValue
public void setPackingValue(int packingValue)
Description copied from interface:Composite
Sets the current packing value (usually a power of 2). A value of NOT_PACKING should be passed if this isn't a packed data type. Otherwise this value indicates a maximum alignment for any component within this data type. Calling this method will cause the data type to become an internally aligned data type.
Note: If a component's data type has a specific external alignment, it will override this value if necessary.- Specified by:
setPackingValue
in interfaceComposite
- Parameters:
packingValue
- the new packing value or 0 for NOT_PACKING. A negative value will be treated the same as 0.
-
getMinimumAlignment
public int getMinimumAlignment()
Description copied from interface:Composite
Get the external alignment (a minimum alignment) for this DataType. This controls where this data type will get aligned within other data types. It also causes the end of this data type to get padded so its length is a multiple of the alignment.- Specified by:
getMinimumAlignment
in interfaceComposite
- Returns:
- the external alignment for this DataType or DEFAULT_ALIGNMENT_VALUE.
-
setMinimumAlignment
public void setMinimumAlignment(int externalAlignment)
Description copied from interface:Composite
Sets the external alignment (a minimum alignment) for this DataType. This controls where this data type will get aligned within other data types. It also causes the end of this data type to get padded so its length is a multiple of the alignment. Calling this method will cause the data type to become an internally aligned data type.- Specified by:
setMinimumAlignment
in interfaceComposite
- Parameters:
externalAlignment
- the external (minimum) alignment for this DataType. Any value less than 1 will revert to default alignment.
-
isInternallyAligned
public boolean isInternallyAligned()
Description copied from interface:Composite
Determine if this data type has its internal components currently aligned.- Specified by:
isInternallyAligned
in interfaceComposite
- Returns:
- true if this data type's components are aligned relative to each other using the current data organization. When internally aligned the end of this data type will be padded to a multiple of its actual alignment.
-
isDefaultAligned
public boolean isDefaultAligned()
Description copied from interface:Composite
Whether or not this data type is using the default external (minimum) alignment.- Specified by:
isDefaultAligned
in interfaceComposite
- Returns:
- true if this data type has the default external alignment.
-
isMachineAligned
public boolean isMachineAligned()
Description copied from interface:Composite
Whether or not this data type is using the machine alignment value from the DataOrganization for its external (minimum) alignment.- Specified by:
isMachineAligned
in interfaceComposite
- Returns:
- true if this data type is using the machine alignment as the minimum alignment.
-
setInternallyAligned
public void setInternallyAligned(boolean aligned)
Description copied from interface:Composite
Sets whether this data type's internal components are currently aligned or unaligned.- Specified by:
setInternallyAligned
in interfaceComposite
- Parameters:
aligned
- true means align the internal components of this data type. false means don't align it. True also causes the end of this data type to be padded to a multiple of its actual alignment.
-
setToDefaultAlignment
public void setToDefaultAlignment()
Description copied from interface:Composite
Sets this data type's external (minimum) alignment to the default alignment. This data type's external alignment will be based upon the components it contains. This should be used when a data type doesn't have an alignment attribute specified. Calling this method will cause the data type to become an internally aligned data type.- Specified by:
setToDefaultAlignment
in interfaceComposite
-
setToMachineAlignment
public void setToMachineAlignment()
Description copied from interface:Composite
Sets this data type's external (minimum) alignment to a multiple of the machine alignment that is specified in the DataOrganization. The machine alignment is defined as the maximum useful alignment for the target machine. This should be used when a data type has an alignment attribute specified without a size (indicating to use the machine alignment). Calling this method will cause the data type to become an internally aligned data type.- Specified by:
setToMachineAlignment
in interfaceComposite
-
notifyAlignmentChanged
protected void notifyAlignmentChanged()
Notify any parent data types that this composite data type's alignment has changed.
-
adjustInternalAlignment
protected abstract void adjustInternalAlignment()
Adjusts the internal alignment of components within this composite based on the current settings of the internal alignment, packing, alignment type and minimum alignment value. This method should be called whenever any of the above settings are changed or whenever a components data type is changed or a component is added or removed.
-
getAlignment
public int getAlignment()
Description copied from interface:DataType
Gets the alignment to be used when aligning this data type within another data type.- Specified by:
getAlignment
in interfaceDataType
- Overrides:
getAlignment
in classDataTypeImpl
- Returns:
- this data type's alignment.
-
setAlignment
protected void setAlignment(Composite composite)
-
dumpComponents
protected void dumpComponents(java.lang.StringBuilder buffer, java.lang.String pad)
Dump all components for use intoString()
representation.- Parameters:
buffer
- string bufferpad
- padding to be used with each component output line
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractDataType
-
-