Package ghidra.program.model.data
Class UnionDataType
- java.lang.Object
-
- ghidra.program.model.data.AbstractDataType
-
- 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.util.EventListener,javax.swing.event.ChangeListener
public class UnionDataType extends CompositeDataTypeImpl implements Union
Basic implementation of the union data type
-
-
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, alignmentType, externalAlignment, 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
-
-
Constructor Summary
Constructors Constructor Description UnionDataType(CategoryPath path, java.lang.String name)Construct a new empty union with the given name within the specified categry path.UnionDataType(CategoryPath path, java.lang.String name, DataTypeManager dtm)Construct a new empty union with the given name and datatype manager within the specified categry path.UnionDataType(CategoryPath path, java.lang.String name, UniversalID universalID, SourceArchive sourceArchive, long lastChangeTime, long lastChangeTimeInSourceArchive, DataTypeManager dtm)Construct a new empty union with the given name within the specified categry path.UnionDataType(java.lang.String name)Construct a new UnionDataType
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataTypeComponentadd(DataType dataType, int length, java.lang.String componentName, java.lang.String comment)Adds a new datatype to the end of this composite.DataTypeComponentaddBitField(DataType baseDataType, int bitSize, java.lang.String componentName, java.lang.String comment)Adds a new bitfield to the end of this composite.voidadjustInternalAlignment()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.DataTypeclone(DataTypeManager dtm)Returns a new instance of this DataType with its universalID and SourceArchive identity retained.DataTypecopy(DataTypeManager dtm)Returns a new instance of this DataType with a new identity.voiddataTypeAlignmentChanged(DataType dt)The overall (external) alignment changed for the specified data type.voiddataTypeDeleted(DataType dt)Informs this dataType that the given dataType has been deleted.voiddataTypeNameChanged(DataType dt, java.lang.String oldName)Informs this data type that its name has changed from the indicated old name.voiddataTypeReplaced(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!!voiddataTypeSizeChanged(DataType dt)Notification that the given dataType's size has changed.voiddelete(int ordinal)Deletes the component at the given ordinal position.voiddelete(int[] ordinals)Deletes the components at the given ordinal positions.booleandependsOn(DataType dt)Returns true if this dataType depends on the existence of the given dataType.DataTypeComponentgetComponent(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 composite including undefined filler components which may be present within an unaligned structure.java.lang.StringgetDefaultLabelPrefix()Returns the appropriate string to use as the default label prefix in the absence of any data.DataTypeComponent[]getDefinedComponents()Returns an array of Data Type Components that make up this composite excluding undefined filler components which may be present within an unaligned structure.intgetLength()Get the length (number of 8-bit bytes) of this DataType.intgetNumComponents()Gets the number of component data types in this composite.intgetNumDefinedComponents()Returns the number of explicitly defined components in this composite.java.lang.StringgetRepresentation(MemBuffer buf, Settings settings, int length)Get bytes from memory in a printable format for this type.DataTypeComponentinsert(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.DataTypeComponentinsertBitField(int ordinal, DataType baseDataType, int bitSize, java.lang.String componentName, java.lang.String comment)Inserts a new bitfield at the specified ordinal position in this union.booleanisEquivalent(DataType dt)Returns true if the given dataType is equivalent to this dataType.booleanisNotYetDefined()Indicates if type has not yet been defined.voidrealign()Updates the composite to any changes in the data organization.voidreplaceWith(DataType dataType)For dataTypes that support change, this method replaces the internals of this dataType with the internals of the given dataType.-
Methods inherited from class ghidra.program.model.data.CompositeDataTypeImpl
add, add, add, checkAncestry, dumpComponents, getAlignment, getDescription, getMinimumAlignment, getMnemonic, getPackingValue, getPreferredComponentLength, getValue, insert, insert, isDefaultAligned, isDynamicallySized, isInternallyAligned, isMachineAligned, isPartOf, notifyAlignmentChanged, setAlignment, setDescription, setInternallyAligned, setMinimumAlignment, setName, setPackingValue, setToDefaultAlignment, setToMachineAlignment, setValue, toString, updateBitFieldDataType, validateDataType
-
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, setDefaultSettings, setLastChangeTime, setLastChangeTimeInSourceArchive, setSourceArchive, stateChanged
-
Methods inherited from class ghidra.program.model.data.AbstractDataType
getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDisplayName, getDocs, getName, isDeleted
-
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, add, add, getBitFieldPacking, getMinimumAlignment, getPackingValue, insert, insert, isDefaultAligned, isInternallyAligned, isMachineAligned, isPartOf, setDescription, setInternallyAligned, setMinimumAlignment, setPackingValue, setToDefaultAlignment, setToMachineAlignment
-
Methods inherited from interface ghidra.program.model.data.DataType
addParent, getAlignment, getCategoryPath, getDataOrganization, 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 empty union with the given name within the specified categry path. An empty union will report its length as 1 andisNotYetDefined()will return true.- Parameters:
path- the category path indicating where this data type is located.name- the name of the new union
-
UnionDataType
public UnionDataType(CategoryPath path, java.lang.String name, DataTypeManager dtm)
Construct a new empty union with the given name and datatype manager within the specified categry path. An empty union will report its length as 1 andisNotYetDefined()will return true.- Parameters:
path- the category path indicating where this data type is located.name- the name of the new uniondtm- the data type manager associated with this data type. This can be null. Also, the data type manager may not yet contain this actual data type.
-
UnionDataType
public UnionDataType(CategoryPath path, java.lang.String name, UniversalID universalID, SourceArchive sourceArchive, long lastChangeTime, long lastChangeTimeInSourceArchive, DataTypeManager dtm)
Construct a new empty union with the given name within the specified categry path. An empty union will report its length as 1 andisNotYetDefined()will return true.- Parameters:
path- the category path indicating where this data type is located.name- the name of the new structureuniversalID- the id for the data typesourceArchive- the source archive for this data typelastChangeTime- the last time this data type was changedlastChangeTimeInSourceArchive- the last time this data type was changed in its source archive.dtm- 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:DataTypeGet bytes from memory in a printable format for this type.- Specified by:
getRepresentationin 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:DataTypeIndicates if type has not yet been defined. Such types will always return a size of 1. (example: empty structure)- Specified by:
isNotYetDefinedin interfaceDataType- Overrides:
isNotYetDefinedin classAbstractDataType- Returns:
- true if this type is not yet defined.
-
getComponent
public DataTypeComponent getComponent(int ordinal)
Description copied from interface:CompositeReturns the component of this data type with the indicated ordinal.- Specified by:
getComponentin interfaceComposite- Parameters:
ordinal- the component's ordinal (zero based).- Returns:
- the data type component.
-
getComponents
public DataTypeComponent[] getComponents()
Description copied from interface:CompositeReturns an array of Data Type Components that make up this composite including undefined filler components which may be present within an unaligned structure. The number of components corresponds toComposite.getNumComponents().- Specified by:
getComponentsin interfaceComposite- Returns:
- list all components
-
getDefinedComponents
public DataTypeComponent[] getDefinedComponents()
Description copied from interface:CompositeReturns an array of Data Type Components that make up this composite excluding undefined filler components which may be present within an unaligned structure. The number of components corresponds toComposite.getNumComponents(). For Unions and aligned Structures this is equivalent toComposite.getComponents()since they do not contain undefined components. Structures do not include the optional trailing flexible array component in this list (seeStructure.getFlexibleArrayComponent()).- Specified by:
getDefinedComponentsin interfaceComposite- Returns:
- list all explicitly defined components
-
getNumComponents
public int getNumComponents()
Description copied from interface:CompositeGets the number of component data types in this composite. The count will include all undefined filler components which may be present within an unaligned structure. Structures do not include the optional trailing flexible array component in this count (seeStructure.hasFlexibleArrayComponent()).- Specified by:
getNumComponentsin interfaceComposite- Returns:
- the number of components that make up this composite
-
getNumDefinedComponents
public int getNumDefinedComponents()
Description copied from interface:CompositeReturns the number of explicitly defined components in this composite. For Unions and aligned Structures this is equivalent toComposite.getNumComponents()since they do not contain undefined components. The count will exclude all undefined filler components which may be present within an unaligned structure.- Specified by:
getNumDefinedComponentsin interfaceComposite- Returns:
- the number of explicitly defined components in this composite
-
add
public DataTypeComponent add(DataType dataType, int length, java.lang.String componentName, java.lang.String comment) throws java.lang.IllegalArgumentException
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.- Specified by:
addin interfaceComposite- Parameters:
dataType- the datatype to add.length- the length to associate with the datatype. For fixed length types a length <= 0 will use the length of the resolved dataType.componentName- the field name to associate with this component.comment- the comment to associate with this component.- Returns:
- the componentDataType created.
- Throws:
java.lang.IllegalArgumentException- if the specified data type is not allowed to be added to this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to add dt1 to dt2 since this would cause a cyclic dependency.
-
insert
public DataTypeComponent insert(int ordinal, DataType dataType, int length, java.lang.String componentName, java.lang.String comment) throws java.lang.IllegalArgumentException
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.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.componentName- the field name to associate with this component.comment- the comment to associate with this component.- Returns:
- the componentDataType created.
- Throws:
java.lang.IllegalArgumentException- if the specified data type is not allowed to be inserted into this composite data type or an invalid length is specified. For example, suppose dt1 contains dt2. Therefore it is not valid to insert dt1 to dt2 since this would cause a cyclic dependency.
-
addBitField
public DataTypeComponent addBitField(DataType baseDataType, int bitSize, java.lang.String componentName, java.lang.String comment) throws InvalidDataTypeException
Description copied from interface:CompositeAdds a new bitfield to the end of this composite. This method is intended to be used with aligned structures/unions only where the bitfield will be appropriately packed. The minimum storage storage byte size will be applied. It will not provide useful results within unaligned composites.- Specified by:
addBitFieldin interfaceComposite- Parameters:
baseDataType- the bitfield base datatype (certain restrictions apply).bitSize- the bitfield size in bitscomponentName- the field name to associate with this component.comment- the comment to associate with this component.- Returns:
- the componentDataType created whose associated data type will be BitFieldDataType.
- Throws:
InvalidDataTypeException- if the specified data type is not a valid base type for bitfields.
-
insertBitField
public DataTypeComponent insertBitField(int ordinal, DataType baseDataType, int bitSize, java.lang.String componentName, java.lang.String comment) throws InvalidDataTypeException, java.lang.ArrayIndexOutOfBoundsException
Description copied from interface:UnionInserts a new bitfield at the specified ordinal position in this union. For both aligned and unaligned unions the bitfield starts with bit-0 (lsb) of the first byte for little-endian, and with bit-7 (msb) of the first byte for big-endian. This is the default behavior for most compilers. Insertion behavior may not work as expected if packing rules differ from this.- Specified by:
insertBitFieldin interfaceUnion- Parameters:
ordinal- the ordinal where the new datatype is to be inserted.baseDataType- the bitfield base datatype (certain restrictions apply).bitSize- the declared bitfield size in bits. The effective bit size may be adjusted based upon the specified baseDataType.componentName- the field name to associate with this component.comment- the comment to associate with this component.- Returns:
- the bitfield component created whose associated data type will be BitFieldDataType.
- Throws:
InvalidDataTypeException- if the specified baseDataType is not a valid base type for bitfields.java.lang.ArrayIndexOutOfBoundsException- if ordinal is less than 0 or greater than the current number of components.
-
getLength
public int getLength()
Description copied from interface:DataTypeGet the length (number of 8-bit bytes) of this DataType.
-
clone
public DataType clone(DataTypeManager dtm)
Description copied from interface:DataTypeReturns 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:DataTypeReturns 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:CompositeDeletes the component at the given ordinal position.
Note: Removal of bitfields from an unaligned structure will not shift other components with vacated bytes reverting to undefined.
-
delete
public void delete(int[] ordinals)
Description copied from interface:CompositeDeletes the components at the given ordinal positions.
Note: Removal of bitfields from an unaligned structure will not shift other components with vacated bytes reverting to undefined.
-
isEquivalent
public boolean isEquivalent(DataType dt)
Description copied from interface:DataTypeReturns true if the given dataType is equivalent to this dataType. The precise meaning of "equivalent" is dataType dependent.
NOTE: if invoked by a DB object or manager it should be invoked on the DataTypeDB object passing the other datatype as the argument.- Specified by:
isEquivalentin interfaceDataType- Parameters:
dt- the dataType being tested for equivalence.- Returns:
- true if the if the given dataType is equivalent to this dataType.
-
dataTypeAlignmentChanged
public void dataTypeAlignmentChanged(DataType dt)
Description copied from interface:CompositeThe 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:
dataTypeAlignmentChangedin interfaceComposite- Parameters:
dt- the data type whose alignment changed.
-
dataTypeSizeChanged
public void dataTypeSizeChanged(DataType dt)
Description copied from interface:DataTypeNotification 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:
dataTypeSizeChangedin interfaceDataType- Overrides:
dataTypeSizeChangedin classAbstractDataType- Parameters:
dt- the dataType that has changed.
-
dataTypeReplaced
public void dataTypeReplaced(DataType oldDt, DataType newDt) throws java.lang.IllegalArgumentException
Description copied from interface:DataTypeInforms 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:
dataTypeReplacedin interfaceDataType- Overrides:
dataTypeReplacedin classAbstractDataType- Parameters:
oldDt- old data typenewDt- new data type- Throws:
java.lang.IllegalArgumentException
-
dataTypeDeleted
public void dataTypeDeleted(DataType dt)
Description copied from interface:DataTypeInforms 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:
dataTypeDeletedin interfaceDataType- Overrides:
dataTypeDeletedin classAbstractDataType- Parameters:
dt- the dataType that has been deleted.
-
replaceWith
public void replaceWith(DataType dataType) throws java.lang.IllegalArgumentException
Description copied from interface:DataTypeFor dataTypes that support change, this method replaces the internals of this dataType with the internals of the given dataType. The dataTypes must be of the same "type" (i.e. structure can only be replacedWith another structure.- Specified by:
replaceWithin interfaceDataType- Overrides:
replaceWithin classDataTypeImpl- Parameters:
dataType- the dataType that contains the internals to upgrade to.- Throws:
java.lang.IllegalArgumentException- if the given dataType is not the same type as this dataType.
-
dataTypeNameChanged
public void dataTypeNameChanged(DataType dt, java.lang.String oldName)
Description copied from interface:DataTypeInforms 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:
dataTypeNameChangedin interfaceDataType- Overrides:
dataTypeNameChangedin classAbstractDataType- Parameters:
dt- the data type whose name changedoldName- the data type's old name
-
dependsOn
public boolean dependsOn(DataType dt)
Description copied from interface:DataTypeReturns 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:
dependsOnin interfaceDataType- Overrides:
dependsOnin classAbstractDataType- Parameters:
dt- the dataType to test that this dataType depends on.
-
getDefaultLabelPrefix
public java.lang.String getDefaultLabelPrefix()
Description copied from interface:DataTypeReturns the appropriate string to use as the default label prefix in the absence of any data.- Specified by:
getDefaultLabelPrefixin interfaceDataType- Overrides:
getDefaultLabelPrefixin classAbstractDataType- Returns:
- the default label prefix or null if none specified.
-
realign
public void realign()
Description copied from interface:CompositeUpdates the composite to any changes in the data organization. If the composite is not internally aligned, this method does nothing.
-
adjustInternalAlignment
public void adjustInternalAlignment()
Description copied from class:CompositeDataTypeImplAdjusts 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:
adjustInternalAlignmentin classCompositeDataTypeImpl
-
-