Package ghidra.program.model.data
Class UnionDataType
- java.lang.Object
-
- ghidra.program.model.data.DataTypeImpl
-
- ghidra.program.model.data.GenericDataType
-
- ghidra.program.model.data.CompositeDataTypeImpl
-
- ghidra.program.model.data.UnionDataType
-
- All Implemented Interfaces:
Composite
,DataType
,Union
,java.io.Serializable
,java.util.EventListener
,javax.swing.event.ChangeListener
public class UnionDataType extends CompositeDataTypeImpl implements Union
Basic implementation of the union data type- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ghidra.program.model.data.Composite
Composite.AlignmentType, Composite.NamedAlignment
-
-
Field Summary
-
Fields inherited from class ghidra.program.model.data.CompositeDataTypeImpl
aligned, currentAlignment, externalAlignment, packingValue
-
Fields inherited from class ghidra.program.model.data.GenericDataType
packed
-
Fields inherited from class ghidra.program.model.data.DataTypeImpl
categoryPath, defaultSettings, 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
-
-
Constructor Summary
Constructors Constructor Description UnionDataType(CategoryPath path, java.lang.String name)
Construct a new UnionDataTypeUnionDataType(CategoryPath path, java.lang.String name, DataTypeManager dtm)
UnionDataType(CategoryPath path, java.lang.String name, UniversalID universalID, SourceArchive sourceArchive, long lastChangeTime, long lastChangeTimeInSourceArchive, DataTypeManager dtm)
Construct a new UnionDataTypeUnionDataType(java.lang.String name)
Construct a new UnionDataType
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataTypeComponent
add(DataType dataType, int length, java.lang.String componentName, java.lang.String comment)
Adds a new datatype to the end of this composite.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.void
align(DataOrganization dataOrganization)
DataType
clone(DataTypeManager dtm)
Returns a new instance of this DataType with its universalID and SourceArchive identity retained.DataType
copy(DataTypeManager dtm)
Returns a new instance of this DataType with a new identity.void
dataTypeAlignmentChanged(DataType dt)
The overall (external) alignment changed for the specified data type.void
dataTypeDeleted(DataType dt)
Informs this dataType that the given dataType has been deleted.void
dataTypeNameChanged(DataType dt, java.lang.String oldName)
Informs this data type that its name has changed from the indicated old name.void
dataTypeReplaced(DataType oldDt, DataType newDt)
Informs this data type that the given oldDT has been replaced with newDT
TODO: This method is reserved for internal DB use and should be removed from the public DataType interface!!void
dataTypeSizeChanged(DataType dt)
Notification that the given dataType's size has changed.void
delete(int ordinal)
Deletes the component at the given ordinal position.void
delete(int[] ordinals)
Deletes the components at the given ordinal positions.boolean
dependsOn(DataType dt)
Returns true if this dataType depends on the existence of the given dataType.DataTypeComponent
getComponent(int ordinal)
Returns the component of this data type with the indicated ordinal.DataTypeComponent[]
getComponents()
Returns an array of Data Type Components that make up this data type.java.lang.String
getDefaultLabelPrefix()
Returns the appropriate string to use as the default label prefix in the absence of any data.int
getLength()
Get the length (number of 8-bit bytes) of this DataType.int
getNumComponents()
Gets the number of component data types in this data type.int
getPackingValue()
Gets the current packing value (typically a power of 2).java.lang.String
getRepresentation(MemBuffer buf, Settings settings, int length)
Get bytes from memory in a printable format for this type.DataTypeComponent
insert(int ordinal, DataType dataType, int length, java.lang.String componentName, java.lang.String comment)
Inserts a new datatype at the specified ordinal position in this composite.boolean
isEquivalent(DataType dt)
Returns true if the given dataType is equivalent to this dataType.boolean
isNotYetDefined()
Indicates if type has not yet been defined.void
realign()
Updates the composite to any changes in the data organization.void
replaceWith(DataType dataType)
Replaces the internal components of this union with components of the given union.void
setPackingValue(int packingValue)
Sets the current packing value (usually a power of 2).-
Methods inherited from class ghidra.program.model.data.CompositeDataTypeImpl
add, add, add, checkAncestry, dumpComponents, getAlignment, getDescription, getMinimumAlignment, getMnemonic, getValue, insert, insert, isDefaultAligned, isDynamicallySized, isInternallyAligned, isMachineAligned, isPartOf, notifyAlignmentChanged, setDataAlignmentInfo, setDescription, setInternallyAligned, setMinimumAlignment, setName, setToDefaultAlignment, setToMachineAlignment, setValue, toString, validateDataType
-
Methods inherited from class ghidra.program.model.data.GenericDataType
setCategoryPath, setNameAndCategory
-
Methods inherited from class ghidra.program.model.data.DataTypeImpl
addParent, equals, getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDefaultSettings, getDisplayName, getDocs, getLastChangeTime, getLastChangeTimeInSourceArchive, getName, getParents, getPathName, getSettingsDefinitions, getSourceArchive, getUniversalID, getValueClass, hashCode, isDeleted, notifyDeleted, notifyNameChanged, notifyReplaced, notifySizeChanged, removeParent, setDefaultSettings, setLastChangeTime, setLastChangeTimeInSourceArchive, setSourceArchive, stateChanged
-
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, getMinimumAlignment, isDefaultAligned, isInternallyAligned, isMachineAligned, isPartOf, setDescription, setInternallyAligned, setMinimumAlignment, setToDefaultAlignment, setToMachineAlignment
-
Methods inherited from interface ghidra.program.model.data.DataType
addParent, getAlignment, getCategoryPath, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDefaultSettings, getDescription, getDisplayName, getDocs, getLastChangeTime, getLastChangeTimeInSourceArchive, getMnemonic, getName, getParents, getPathName, getSettingsDefinitions, getSourceArchive, getUniversalID, getValue, getValueClass, isDeleted, isDynamicallySized, removeParent, setCategoryPath, setDefaultSettings, setLastChangeTime, setLastChangeTimeInSourceArchive, setName, setNameAndCategory, setSourceArchive
-
-
-
-
Constructor Detail
-
UnionDataType
public UnionDataType(CategoryPath path, java.lang.String name)
Construct a new UnionDataType- Parameters:
path
- the category path indicating where this data type is located.name
- the name of this dataType
-
UnionDataType
public UnionDataType(CategoryPath path, java.lang.String name, DataTypeManager dtm)
-
UnionDataType
public UnionDataType(CategoryPath path, java.lang.String name, UniversalID universalID, SourceArchive sourceArchive, long lastChangeTime, long lastChangeTimeInSourceArchive, DataTypeManager dtm)
Construct a new UnionDataType- Parameters:
path
- the category path indicating where this data type is located.name
- the name of this dataTypedataTypeManager
- 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
public UnionDataType(java.lang.String name)
Construct a new UnionDataType- Parameters:
name
- the name of this dataType
-
-
Method Detail
-
getRepresentation
public java.lang.String getRepresentation(MemBuffer buf, Settings settings, int length)
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.
-
isNotYetDefined
public boolean isNotYetDefined()
Description copied from interface:DataType
Indicates if type has not yet been defined. Such types will always return a size of 1. (example: empty structure)- Specified by:
isNotYetDefined
in interfaceDataType
- Overrides:
isNotYetDefined
in classDataTypeImpl
- Returns:
- true if this type is not yet defined.
-
getComponent
public DataTypeComponent getComponent(int ordinal)
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 (zero based).- Returns:
- the data type component.
- See Also:
Composite.getComponent(int)
-
getComponents
public DataTypeComponent[] getComponents()
Description copied from interface:Composite
Returns an array of Data Type Components that make up this data type. Returns an array of length 0 if there are no subcomponents.- Specified by:
getComponents
in interfaceComposite
- Specified by:
getComponents
in interfaceUnion
- See Also:
Composite.getComponents()
-
getNumComponents
public int getNumComponents()
Description copied from interface:Composite
Gets the number of component data types in this data type.- Specified by:
getNumComponents
in interfaceComposite
- Returns:
- the number of components that make up this data prototype
- See Also:
Composite.getNumComponents()
-
add
public DataTypeComponent add(DataType dataType, int length, java.lang.String componentName, java.lang.String comment)
Description copied from interface:Composite
Adds a new datatype to the end of this composite.- Specified by:
add
in interfaceComposite
- Specified by:
add
in interfaceUnion
- Parameters:
dataType
- the datatype to add.length
- the length to associate with the datatype.componentName
- the field name to associate with this component.comment
- the comment to associate with this component.- Returns:
- the componentDataType created.
- See Also:
Composite.add(ghidra.program.model.data.DataType, int, java.lang.String, java.lang.String)
-
insert
public DataTypeComponent insert(int ordinal, DataType dataType, int length, java.lang.String componentName, java.lang.String comment)
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
- Specified by:
insert
in interfaceUnion
- 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.componentName
- the field name to associate with this component.comment
- the comment to associate with this component.- Returns:
- the componentDataType created.
- See Also:
Composite.insert(int, ghidra.program.model.data.DataType, int, java.lang.String, java.lang.String)
-
getLength
public int getLength()
Description copied from interface:DataType
Get the length (number of 8-bit bytes) of this DataType.- Specified by:
getLength
in interfaceDataType
- Returns:
- the length of this DataType
- See Also:
DataType.getLength()
-
clone
public DataType clone(DataTypeManager dtm)
Description copied from interface:DataType
Returns a new instance of this DataType with its universalID and SourceArchive identity retained. Note: for built-in DataType's, clone and copy should have the same affect.
-
copy
public DataType copy(DataTypeManager dtm)
Description copied from interface:DataType
Returns a new instance of this DataType with a new identity. Note: for built-in DataType's, clone and copy should have the same affect.
-
delete
public void delete(int ordinal)
Description copied from interface:Composite
Deletes the component at the given ordinal position.
Note: For an aligned structure the delete will have no effect if the ordinal position is a component that provides alignment padding.- Specified by:
delete
in interfaceComposite
- Specified by:
delete
in interfaceUnion
- Parameters:
ordinal
- the ordinal of the component to be deleted.- See Also:
Composite.delete(int)
-
delete
public void delete(int[] ordinals)
Description copied from interface:Composite
Deletes the components at the given ordinal positions.
Note: For an aligned structure the delete will have no effect if the ordinal position is a component that provides alignment padding.
-
isEquivalent
public boolean isEquivalent(DataType dt)
Description copied from interface:DataType
Returns true if the given dataType is equivalent to this dataType. The precise meaning of "equivalent" is dataType dependent.- 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.
- See Also:
DataType.isEquivalent(ghidra.program.model.data.DataType)
-
dataTypeAlignmentChanged
public void dataTypeAlignmentChanged(DataType dt)
Description copied from interface:Composite
The overall (external) alignment changed for the specified data type. In other words, the data type has a different alignment when placed inside other structures.- Specified by:
dataTypeAlignmentChanged
in interfaceComposite
- Parameters:
dt
- the data type whose alignment changed.
-
dataTypeSizeChanged
public void dataTypeSizeChanged(DataType dt)
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 and should be removed from the public DataType interface!!- Specified by:
dataTypeSizeChanged
in interfaceDataType
- Parameters:
dt
- the dataType that has changed.- See Also:
DataType.dataTypeSizeChanged(ghidra.program.model.data.DataType)
-
dataTypeReplaced
public void dataTypeReplaced(DataType oldDt, DataType newDt)
Description copied from interface:DataType
Informs this data type that the given oldDT has been replaced with newDT
TODO: This method is reserved for internal DB use and should be removed from the public DataType interface!!- Specified by:
dataTypeReplaced
in interfaceDataType
- Parameters:
oldDt
- old data typenewDt
- new data type
-
dataTypeDeleted
public void dataTypeDeleted(DataType dt)
Description copied from interface:DataType
Informs this dataType that the given dataType has been deleted.
TODO: This method is reserved for internal DB use and should be removed from the public DataType interface!!- Specified by:
dataTypeDeleted
in interfaceDataType
- Parameters:
dt
- the dataType that has been deleted.- See Also:
DataType.dataTypeDeleted(ghidra.program.model.data.DataType)
-
replaceWith
public void replaceWith(DataType dataType)
Replaces the internal components of this union with components of the given union.- Specified by:
replaceWith
in interfaceDataType
- Overrides:
replaceWith
in classDataTypeImpl
- Parameters:
dataType
- the union to get the component information from.- Throws:
java.lang.IllegalArgumentException
- if any of the component data types are not allowed to replace a component in this composite data type. For example, suppose dt1 contains dt2. Therefore it is not valid to replace a dt2 component with dt1 since this would cause a cyclic dependency.
-
dataTypeNameChanged
public void dataTypeNameChanged(DataType dt, java.lang.String oldName)
Description copied from interface:DataType
Informs this data type that its name has changed from the indicated old name.
TODO: This method is reserved for internal DB use and should be removed from the public DataType interface!!- Specified by:
dataTypeNameChanged
in interfaceDataType
- Parameters:
dt
- the data type whose name changedoldName
- the data type's old name- See Also:
DataType.dataTypeNameChanged(ghidra.program.model.data.DataType, java.lang.String)
-
dependsOn
public boolean dependsOn(DataType dt)
Description copied from interface:DataType
Returns true 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
- Parameters:
dt
- the dataType to test that this dataType depends on.- See Also:
DataType.dependsOn(ghidra.program.model.data.DataType)
-
getDefaultLabelPrefix
public java.lang.String 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 classDataTypeImpl
- Returns:
- the default label prefix or null if none specified.
-
align
public void align(DataOrganization dataOrganization)
-
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
- Overrides:
getPackingValue
in classCompositeDataTypeImpl
- 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
- Overrides:
setPackingValue
in classCompositeDataTypeImpl
- Parameters:
packingValue
- the new packing value or 0NOT_PACKING.
-
adjustInternalAlignment
public void adjustInternalAlignment()
Description copied from class:CompositeDataTypeImpl
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.- Specified by:
adjustInternalAlignment
in classCompositeDataTypeImpl
-
-