Interface Structure
-
- All Known Subinterfaces:
StructureInternal
- All Known Implementing Classes:
StructureDataType
public interface Structure extends Composite
The structure interface.NOTE: Structures containing only a flexible array will report a length of 1 which will result in improper code unit sizing since we are unable to support a defined data of length 0.
NOTE: The use of zero-length bitfields within non-packed structures is discouraged since they have no real affect and are easily misplaced. Their use should be reserved for packed structures.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Structure.BitOffsetComparator
BitOffsetComparator
provides ability to compare an normalized bit offset (seeStructure.BitOffsetComparator.getNormalizedBitfieldOffset(int, int, int, int, boolean)
) with aDataTypeComponent
object.
-
Field Summary
-
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 Modifier and Type Method Description void
clearComponent(int ordinal)
Clears the defined component at the given component ordinal.void
clearFlexibleArrayComponent()
Remove the optional trailing flexible array component associated with this structure.Structure
clone(DataTypeManager dtm)
Returns an instance of this DataType with its universalID and SourceArchive identity retained.void
deleteAll()
Remove all components from this structure (including flex-array), effectively setting the length to zero.void
deleteAtOffset(int offset)
Deletes the component containing the specified offset in this structure.DataTypeComponent
getComponent(int ordinal)
Returns the component of this structure with the indicated ordinal.DataTypeComponent
getComponentAt(int offset)
Gets the immediate child component that contains the byte at the given offset.DataTypeComponent
getDataTypeAt(int offset)
Returns the primitive Data Type that is at this offset.DataTypeComponent
getFlexibleArrayComponent()
Get the optional trailing flexible array component associated with this structure.void
growStructure(int amount)
Increases the size of the structure by the given amount by adding undefined filler at the end of the structure.boolean
hasFlexibleArrayComponent()
Determine if a trailing flexible array component has been defined.DataTypeComponent
insertAtOffset(int offset, DataType dataType, int length)
Inserts a new datatype at the specified offset into this structure.DataTypeComponent
insertAtOffset(int offset, DataType dataType, int length, java.lang.String name, java.lang.String comment)
Inserts a new datatype at the specified offset into this structure.DataTypeComponent
insertBitField(int ordinal, int byteWidth, int bitOffset, DataType baseDataType, int bitSize, java.lang.String componentName, java.lang.String comment)
Inserts a new bitfield at the specified ordinal position in this structure.DataTypeComponent
insertBitFieldAt(int byteOffset, int byteWidth, int bitOffset, DataType baseDataType, int bitSize, java.lang.String componentName, java.lang.String comment)
Inserts a new bitfield at the specified location in this composite.DataTypeComponent
replace(int ordinal, DataType dataType, int length)
Replaces the component at the given component ordinal with a new component of the indicated data type.DataTypeComponent
replace(int ordinal, DataType dataType, int length, java.lang.String name, java.lang.String comment)
Replaces the component at the given component ordinal with a new component of the indicated data type.DataTypeComponent
replaceAtOffset(int offset, DataType dataType, int length, java.lang.String name, java.lang.String comment)
Replaces the component at the specified byte offset with a new component of the indicated data type.DataTypeComponent
setFlexibleArrayComponent(DataType flexType, java.lang.String name, java.lang.String comment)
Set the optional trailing flexible array component associated with this structure.-
Methods inherited from interface ghidra.program.model.data.Composite
add, add, add, add, addBitField, align, dataTypeAlignmentChanged, delete, delete, getAlignment, getAlignmentType, getComponents, getDefinedComponents, getExplicitMinimumAlignment, getExplicitPackingValue, getNumComponents, getNumDefinedComponents, getPackingType, hasDefaultPacking, hasExplicitMinimumAlignment, hasExplicitPackingValue, insert, insert, insert, isDefaultAligned, isMachineAligned, isPackingEnabled, isPartOf, pack, repack, setDescription, setExplicitMinimumAlignment, setExplicitPackingValue, setPackingEnabled, setToDefaultAligned, setToDefaultPacking, setToMachineAligned
-
Methods inherited from interface ghidra.program.model.data.DataType
addParent, copy, dataTypeDeleted, dataTypeNameChanged, dataTypeReplaced, dataTypeSizeChanged, dependsOn, getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDefaultSettings, getDescription, getDisplayName, getDocs, getLastChangeTime, getLastChangeTimeInSourceArchive, getLength, getMnemonic, getName, getParents, getPathName, getRepresentation, getSettingsDefinitions, getSourceArchive, getUniversalID, getValue, getValueClass, hasLanguageDependantLength, isDeleted, isEquivalent, isNotYetDefined, isZeroLength, removeParent, replaceWith, setCategoryPath, setDefaultSettings, setLastChangeTime, setLastChangeTimeInSourceArchive, setName, setNameAndCategory, setSourceArchive
-
-
-
-
Method Detail
-
clone
Structure clone(DataTypeManager dtm)
Description copied from interface:DataType
Returns an instance of this DataType with its universalID and SourceArchive identity retained. The current instanceof will be returned if this datatype's DataTypeManager matches the specified dtm. The recursion depth of a clone will stop on any datatype whose DataTypeManager matches the specified dtm and simply use the existing datatype instance.
-
getComponent
DataTypeComponent getComponent(int ordinal) throws java.lang.IndexOutOfBoundsException
Returns the component of this structure with the indicated ordinal. If the specified ordinal equalsComposite.getNumComponents()
the defined flexible array component will be returned, otherwise an out of bounds exception will be thrown. Use ofgetFlexibleArrayComponent()
is preferred for obtaining this special trailing component.- Specified by:
getComponent
in interfaceComposite
- Parameters:
ordinal
- the ordinal of the component requested.- Returns:
- the data type component.
- Throws:
java.lang.IndexOutOfBoundsException
- if the ordinal is out of bounds
-
getComponentAt
DataTypeComponent getComponentAt(int offset)
Gets the immediate child component that contains the byte at the given offset. If the specified offset corresponds to a bit-field,the first bit-field component containing the offset will be returned.- Parameters:
offset
- the byte offset into this data type- Returns:
- the immediate child component.
-
getDataTypeAt
DataTypeComponent getDataTypeAt(int offset)
Returns the primitive Data Type that is at this offset. This is useful for prototypes that have components that are made up of other components If the specified offset corresponds to a bit-field,the BitFieldDataType of the first bit-field component containing the offset will be returned.- Parameters:
offset
- the byte offset into this data type.- Returns:
- the primitive data type at the offset.
-
insertBitField
DataTypeComponent insertBitField(int ordinal, int byteWidth, int bitOffset, DataType baseDataType, int bitSize, java.lang.String componentName, java.lang.String comment) throws InvalidDataTypeException, java.lang.IndexOutOfBoundsException
Inserts a new bitfield at the specified ordinal position in this structure. Within packed structures the specified byteWidth and bitOffset will be ignored since packing will occur at the specified ordinal position. The resulting component length and bitfield details will reflect the use of minimal storage sizing.For structures with packing disabled, a component shift will only occur if the bitfield placement conflicts with another component. If no conflict occurs, the bitfield will be placed at the specified location consuming any DEFAULT components as needed. When a conflict does occur a shift will be performed at the ordinal position based upon the specified byteWidth. When located onto existing bitfields they will be packed together provided they do not conflict, otherwise the conflict rule above applies.
Supported packing 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.
- Parameters:
ordinal
- the ordinal of the component to be inserted.byteWidth
- the storage allocation unit width which contains the bitfield. Must be large enough to contain the "effective bit size" and corresponding bitOffset. The actual component size used will be recomputed during insertion.bitOffset
- corresponds to the bitfield left-shift amount with the storage unit when viewed as big-endian. The final offset may be reduced based upon the minimal storage size determined during insertion.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.IndexOutOfBoundsException
- if ordinal is less than 0 or greater than the current number of components.
-
insertBitFieldAt
DataTypeComponent insertBitFieldAt(int byteOffset, int byteWidth, int bitOffset, DataType baseDataType, int bitSize, java.lang.String componentName, java.lang.String comment) throws InvalidDataTypeException
Inserts a new bitfield at the specified location in this composite. This method is intended to be used with structures with packing disabled where the bitfield will be precisely placed. Within an packed structure the specified byteOffset, byteWidth and bitOffset will be used to identify the appropriate ordinal but may not be preserved. The component length will be computed based upon the specified parameters and will be reduced from byteWidth to its minimal size for the new component.When packing disabled, a component shift will only occur if the bitfield placement conflicts with another component. If no conflict occurs, the bitfield will be placed at the specified location consuming any DEFAULT components as needed. When a conflict does occur a shift will be performed at the point of conflict based upon the specified byteWidth. When located onto existing bitfields they will be packed together provided they do not conflict, otherwise the conflict rule above applies.
Supported packing for little-endian fills lsb first, whereas big-endian fills msb first. Insertion behavior may not work as expected if packing rules differ from this.
Zero length bitfields may be inserted although they have no real affect when packing disabled. Only the resulting byte offset within the structure is of significance in determining its ordinal placement.
- Parameters:
byteOffset
- the first byte offset within this structure which corresponds to the first byte of the specified storage unit identified by its byteWidth.byteWidth
- the storage unit width which contains the bitfield. Must be large enough to contain the specified bitSize and corresponding bitOffset. The actual component size used will be recomputed during insertion.bitOffset
- corresponds to the bitfield left-shift amount with the storage unit when viewed as big-endian. The final offset may be reduced based upon the minimal storage size determined during insertion.baseDataType
- the bitfield base datatype (certain restrictions apply).componentName
- the field name to associate with this component.bitSize
- the bitfield size in bits. A bitSize of 0 may be specified although its name will be ignored.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.
-
insertAtOffset
DataTypeComponent insertAtOffset(int offset, DataType dataType, int length) throws java.lang.IllegalArgumentException
Inserts a new datatype at the specified offset into this structure. Inserting a component will causing any conflicting component to shift down to the extent necessary to avoid a conflict.- Parameters:
offset
- the byte offset into the structure 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.
- 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.
-
insertAtOffset
DataTypeComponent insertAtOffset(int offset, DataType dataType, int length, java.lang.String name, java.lang.String comment) throws java.lang.IllegalArgumentException
Inserts a new datatype at the specified offset into this structure. Inserting a component will causing any conflicting component to shift down to the extent necessary to avoid a conflict.- Parameters:
offset
- the byte offset into the structure 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.name
- 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.
-
deleteAtOffset
void deleteAtOffset(int offset)
Deletes the component containing the specified offset in this structure. If the offset corresponds to a bit-field, all bit-fields whose base type group contains the offset will be removed.- Parameters:
offset
- the byte offset into the structure where the datatype is to be deleted.
-
deleteAll
void deleteAll()
Remove all components from this structure (including flex-array), effectively setting the length to zero. Packing and minimum alignment settings are unaffected.
-
clearComponent
void clearComponent(int ordinal) throws java.lang.IndexOutOfBoundsException
Clears the defined component at the given component ordinal. Clearing a component within a non-packed structure causes a defined component to be replaced with a number of undefined dataTypes to offset the removal of the defined dataType. In the case of a packed structure the component is deleted without backfill.- Parameters:
ordinal
- the ordinal of the component to clear.- Throws:
java.lang.IndexOutOfBoundsException
- if component ordinal is out of bounds
-
replace
DataTypeComponent replace(int ordinal, DataType dataType, int length) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalArgumentException
Replaces the component at the given component ordinal with a new component of the indicated data type.- Parameters:
ordinal
- the ordinal of the component to be replaced.dataType
- the datatype to insert.length
- the length of the dataType to insert. For fixed length types a length <= 0 will use the length of the resolved dataType.- Returns:
- the new component
- Throws:
java.lang.IllegalArgumentException
- if the specified data type is not allowed to replace a component in this composite data type or an invalid length is specified. 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. In addition, any attempt to replace an existing bit-field component or specify aBitFieldDataType
will produce this error.java.lang.IndexOutOfBoundsException
- if component ordinal is out of bounds
-
replace
DataTypeComponent replace(int ordinal, DataType dataType, int length, java.lang.String name, java.lang.String comment) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalArgumentException
Replaces the component at the given component ordinal with a new component of the indicated data type.- Parameters:
ordinal
- the ordinal of the component to be replaced.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.name
- the field name to associate with this component.comment
- the comment to associate with this component.- Returns:
- the new component.
- Throws:
java.lang.IllegalArgumentException
- if the specified data type is not allowed to replace a component in this composite data type or an invalid length is specified. 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. In addition, any attempt to replace an existing bit-field component or specify aBitFieldDataType
will produce this error.java.lang.IndexOutOfBoundsException
- if component ordinal is out of bounds
-
replaceAtOffset
DataTypeComponent replaceAtOffset(int offset, DataType dataType, int length, java.lang.String name, java.lang.String comment) throws java.lang.IllegalArgumentException
Replaces the component at the specified byte offset with a new component of the indicated data type. If the offset corresponds to a bit-field, all bit-fields at that offset will be removed and replaced by the specified component. Keep in mind bit-field or any component removal must clear sufficient space in a structure with packing disabled to complete the replacement.- Parameters:
offset
- the byte offset into the structure where the datatype is to be replaced.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.name
- the field name to associate with this component.comment
- the comment to associate with this component.- Returns:
- the new component.
- Throws:
java.lang.IllegalArgumentException
- if the specified data type is not allowed to replace a component in this composite data type or an invalid length is specified. 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. In addition, any attempt to replace an existing bit-field component or specify aBitFieldDataType
will produce this error.
-
hasFlexibleArrayComponent
boolean hasFlexibleArrayComponent()
Determine if a trailing flexible array component has been defined.- Returns:
- true if trailing flexible array component has been defined.
-
getFlexibleArrayComponent
DataTypeComponent getFlexibleArrayComponent()
Get the optional trailing flexible array component associated with this structure.NOTE: The trailing flexable array may be assigned an incorrect offset when packing is enabled and the minimum alignment is specified. In such cases, the flex array may be less than the overall structure length. Currently, it is assumed the trailing flex array will have an offset equal to the overall structure length.
- Returns:
- optional trailing flexible array component associated with this structure or null if not present.
-
setFlexibleArrayComponent
DataTypeComponent setFlexibleArrayComponent(DataType flexType, java.lang.String name, java.lang.String comment) throws java.lang.IllegalArgumentException
Set the optional trailing flexible array component associated with this structure.- Parameters:
flexType
- the flexible array dataType (example: for 'char[0]' the type 'char' should be specified)name
- component field name or null for default namecomment
- component comment- Returns:
- updated flexible array component
- Throws:
java.lang.IllegalArgumentException
- if specified flexType is not permitted (e.g., self referencing or unsupported type)
-
clearFlexibleArrayComponent
void clearFlexibleArrayComponent()
Remove the optional trailing flexible array component associated with this structure.
-
growStructure
void growStructure(int amount)
Increases the size of the structure by the given amount by adding undefined filler at the end of the structure. NOTE: This method only has an affect on structures with packing disabled.- Parameters:
amount
- the amount by which to grow the structure.- Throws:
java.lang.IllegalArgumentException
- if amount < 1
-
-