Class BitFieldDataType
- All Implemented Interfaces:
DataType
BitFieldDataType
provides a means of defining a minimally sized bit-field
for use within data structures. The length (i.e., storage size) of this bitfield datatype is
the minimum number of bytes required to contain the bitfield at its specified offset.
The effective bit-size of a bitfield will be limited by the size of the base
datatype whose size may be controlled by its associated datatype manager and data organization
(e.g., IntegerDataType
).
NOTE: Instantiation of this datatype implementation is intended for internal use only. Creating and manipulating bitfields should be accomplished directly via Structure or Union bitfield methods.
-
Field Summary
Fields inherited from class ghidra.program.model.data.AbstractDataType
categoryPath, dataMgr, name
Fields inherited from interface ghidra.program.model.data.DataType
CONFLICT_SUFFIX, DEFAULT, NO_LAST_CHANGE_TIME, NO_SOURCE_SYNC_TIME, TYPEDEF_ATTRIBUTE_PREFIX, TYPEDEF_ATTRIBUTE_SUFFIX, VOID
-
Constructor Summary
ModifierConstructorDescriptionprotected
BitFieldDataType
(DataType baseDataType, int bitSize) Construct a bit-field type based upon a supported baseDataType.protected
BitFieldDataType
(DataType baseDataType, int bitSize, int bitOffset) Construct a bit-field type based upon a specified base type. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inform this data type that it has the given parent
TODO: This method is reserved for internal DB use.static void
checkBaseDataType
(DataType baseDataType) Check a bitfield base datatypeclone
(DataTypeManager dtm) Clone this bitfield to a new datatype manager.final DataType
copy
(DataTypeManager dtm) Returns a clone of this built-in DataTypefinal boolean
int
Get the aligned-length of this datatype as a number of 8-bit bytes.int
Gets the alignment to be used when aligning this datatype within another datatype.Get the base datatype associated with this bit-field (e.g., int, long, etc., or TypeDef to supported base type)int
Get the size of the base data type based upon the associated data organization.int
Get the bit offset of the least-significant bit relative to bit-0 of the base datatype (i.e., least significant bit).int
Get the effective bit size of this bit-field which may not exceed the size of the base datatype.int
Get the declared bit size of this bit-field which may be larger than the effective size which could be truncated.Gets the settings for this data type.Get a String briefly describing this DataType.static int
getEffectiveBitSize
(int declaredBitSize, int baseTypeByteSize) Get the effective bit-size based upon the specified base type size.int
Get the length of this DataType as a number of 8-bit bytes.static int
getMinimumStorageSize
(int bitSize) Get the minimum storage size in bytes for a given size in bits.static int
getMinimumStorageSize
(int bitSize, int bitOffset) Get the minimum storage size in bytes for a given size in bits with the specified bitOffset (lsb position within big endian storage)Get the base datatype associated with this bit-field (e.g., int, long, etc., or TypeDef to supported base type)getRepresentation
(MemBuffer buf, Settings settings, int length) Get bytes from memory in a printable format for this type.final SettingsDefinition[]
Gets a list of all the settingsDefinitions used by this datatype.int
Get the packing storage size in bytes associated with this bit-field which may be larger than the base type associated with the fields original definition.Returns the interpreted data value as an instance of theadvertised value class
.Class
<?> getValueClass
(Settings settings) Get the Class of the value Object to be returned by this datatype (seeDataType.getValue(MemBuffer, Settings, int)
).final int
hashCode()
final boolean
isEquivalent
(DataType dt) Check if the given datatype is equivalent to this datatype.static boolean
isValidBaseDataType
(DataType baseDataType) Check if a specified baseDataType is valid for use with a bitfieldboolean
Indicates this datatype is defined with a zero length.toString()
Methods inherited from class ghidra.program.model.data.AbstractDataType
dataTypeAlignmentChanged, dataTypeDeleted, dataTypeNameChanged, dataTypeReplaced, dataTypeSizeChanged, dependsOn, encodeRepresentation, encodeValue, getCategoryPath, getDataOrganization, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDisplayName, getDocs, getLastChangeTime, getLastChangeTimeInSourceArchive, getMnemonic, getName, getParents, getPathName, getSourceArchive, getTypeDefSettingsDefinitions, getUniversalID, hasLanguageDependantLength, isDeleted, isEncodable, isNotYetDefined, removeParent, replaceWith, setCategoryPath, setDescription, setLastChangeTime, setLastChangeTimeInSourceArchive, setName, setNameAndCategory, setSourceArchive
-
Field Details
-
defaultSettings
-
-
Constructor Details
-
BitFieldDataType
protected BitFieldDataType(DataType baseDataType, int bitSize, int bitOffset) throws InvalidDataTypeException Construct a bit-field type based upon a specified base type. The baseDataType will take precedence if specified. Either baseType or baseDatatype must be specified.- Parameters:
baseDataType
- base data type (integer/enum type or typedef to same). This bitfield will adopt the same datatype manager as this base type.bitSize
- size of bit-field expressed as number of bits (0..255). The effective bit size may be reduced based upon the specified base datatype size.bitOffset
- right shift factor within storage unit when viewed as a big-endian dd scalar value. Based upon minimal storage bitOffset should be in the range 0 to 7.- Throws:
InvalidDataTypeException
-
BitFieldDataType
Construct a bit-field type based upon a supported baseDataType.- Parameters:
baseDataType
- a supported primitive integer data type or TypeDef to such a type. The baseType must already be cloned to the target datatype manager.bitSize
- size of bit-field expressed as number of bits- Throws:
InvalidDataTypeException
- if specified baseDataType is not permitted
-
-
Method Details
-
isZeroLength
public boolean isZeroLength()Description copied from interface:DataType
Indicates this datatype is defined with a zero length.This method should not be confused with
DataType.isNotYetDefined()
which indicates that nothing but the name and basic type is known.NOTE: a zero-length datatype must return a length of 1 via
DataType.getLength()
. Zero-length datatypes used as a component within aComposite
may, or may not, be assigned a component length of 0. The methodDataTypeComponent.usesZeroLengthComponent(DataType)
is used to make this determination.- Specified by:
isZeroLength
in interfaceDataType
- Overrides:
isZeroLength
in classAbstractDataType
- Returns:
- true if type definition has a length of 0, else false
-
getEffectiveBitSize
public static int getEffectiveBitSize(int declaredBitSize, int baseTypeByteSize) Get the effective bit-size based upon the specified base type size. A bit size larger than the base type size will truncated to the base type size.- Parameters:
declaredBitSize
-baseTypeByteSize
-- Returns:
- effective bit-size
-
getMinimumStorageSize
public static int getMinimumStorageSize(int bitSize) Get the minimum storage size in bytes for a given size in bits. This does not consider the bit offset which may increase the required storage.- Parameters:
bitSize
- number of bits within bitfield- Returns:
- minimum storage size in bytes
-
getMinimumStorageSize
public static int getMinimumStorageSize(int bitSize, int bitOffset) Get the minimum storage size in bytes for a given size in bits with the specified bitOffset (lsb position within big endian storage)- Parameters:
bitSize
- number of bits within bitfieldbitOffset
- normalized bitfield offset within storage (lsb)- Returns:
- minimum storage size in bytes
-
checkBaseDataType
Check a bitfield base datatype- Parameters:
baseDataType
- bitfield base data type (Enum, AbstractIntegerDataType and derived TypeDefs permitted)- Throws:
InvalidDataTypeException
- if baseDataType is invalid as a bitfield base type.
-
isValidBaseDataType
Check if a specified baseDataType is valid for use with a bitfield- Parameters:
baseDataType
- bitfield base data type (Enum, AbstractIntegerDataType and derived TypeDefs permitted)- Returns:
- true if baseDataType is valid else false
-
addParent
Description copied from interface:DataType
Inform this data type that it has the given parent
TODO: This method is reserved for internal DB use.- Specified by:
addParent
in interfaceDataType
- Overrides:
addParent
in classAbstractDataType
- Parameters:
dt
- parent data type
-
getBaseTypeSize
public int getBaseTypeSize()Get the size of the base data type based upon the associated data organization.- Returns:
- base type size
-
getStorageSize
public int getStorageSize()Get the packing storage size in bytes associated with this bit-field which may be larger than the base type associated with the fields original definition. Returned value is the same asgetLength()
.- Returns:
- packing storage size in bytes
-
getBitSize
public int getBitSize()Get the effective bit size of this bit-field which may not exceed the size of the base datatype.- Returns:
- bit size
-
getDeclaredBitSize
public int getDeclaredBitSize()Get the declared bit size of this bit-field which may be larger than the effective size which could be truncated.- Returns:
- bit size as defined by the field construction/declaration.
-
getBitOffset
public int getBitOffset()Get the bit offset of the least-significant bit relative to bit-0 of the base datatype (i.e., least significant bit). This corresponds to the right-shift amount within the base data type when viewed as a big-endian value.- Returns:
- bit offset
-
getBaseDataType
Get the base datatype associated with this bit-field (e.g., int, long, etc., or TypeDef to supported base type)- Returns:
- base data type
-
getPrimitiveBaseDataType
Get the base datatype associated with this bit-field (e.g., int, long, etc., or TypeDef to supported base type)- Returns:
- base data type
-
getSettingsDefinitions
Gets a list of all the settingsDefinitions used by this datatype.- Returns:
- a list of the settingsDefinitions used by this datatype.
-
isEquivalent
Description copied from interface:DataType
Check 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.- Parameters:
dt
- the datatype being tested for equivalence.- Returns:
- true if the if the given datatype is equivalent to this datatype.
-
hashCode
public final int hashCode() -
equals
-
getDefaultSettings
Description copied from interface:DataType
Gets the settings for this data type. The settings may have underlying default settings and may in turn become defaults for instance-specific settings (e.g., Data or DataTypeComponent). It is important to note that these settings are tied to a specific DataType instantiation so it is important to understand the scope of its use. Example: TheBuiltInDataTypeManager
has its own set of DataType instances which are separate from those which have been instantiated or resolved to a specific Program/ArchiveDataTypeManager
. Settings manipulation may be disabled by default in some instances.- Returns:
- the settings for this dataType.
-
copy
Returns a clone of this built-in DataType- Parameters:
dtm
- the data-type manager instance whose data-organization should apply.- Returns:
- new instanceof of this datatype
- See Also:
-
clone
Clone this bitfield to a new datatype manager. This may change the effective bit size and storage size of the resulting datatype based upon the data organization of the specified dtm.- Parameters:
dtm
- target datatype manager- Returns:
- new instance or same instance of dtm is unchanged.
-
getLength
public int getLength()Description copied from interface:DataType
Get the length of this DataType as a number of 8-bit bytes.For primitive datatypes this reflects the smallest varnode which can be used to contain its value (i.e., raw data length).
Example: For x86 32-bit gcc an 80-bit
long double
raw data length
of 10-bytes will fit within a floating point register while itsaligned-length
of 12-bytes is used by the gcc compiler for data/array/component allocations to maintain alignment (i.e.,sizeof(long double)
).NOTE: Other than the
VoidDataType
, no datatype should ever return 0, even ifDataType.isZeroLength()
, and onlyDynamic
/FactoryDataType
datatypes should return -1. IfDataType.isZeroLength()
is true a length of 1 should be returned. Where a zero-length datatype can be handled (e.g.,Composite
) theDataType.isZeroLength()
method should be used.- Returns:
- the length of this DataType
-
getAlignedLength
public int getAlignedLength()Description copied from interface:DataType
Get the aligned-length of this datatype as a number of 8-bit bytes.For primitive datatypes this is equivalent to the C/C++ "sizeof" operation within source code and should be used when determining
Array
element length or component sizing for aComposite
. ForPointer
,Composite
andArray
types this will return the same value asDataType.getLength()
.Example: For x86 32-bit gcc an 80-bit
long double
raw data length
of 10-bytes will fit within a floating point register while itsaligned-length
of 12-bytes is used by the gcc compiler for data/array/component allocations to maintain alignment (i.e.,sizeof(long double)
).NOTE: Other than the
VoidDataType
, no datatype should ever return 0, even ifDataType.isZeroLength()
, and onlyDynamic
/FactoryDataType
/FunctionDefinition
datatypes should return -1. IfDataType.isZeroLength()
is true a length of 1 should be returned.- Returns:
- byte length of binary encoding.
-
getDescription
Description copied from interface:DataType
Get a String briefly describing this DataType.- Returns:
- a one-liner describing this DataType.
-
getValue
Description copied from interface:DataType
Returns the interpreted data value as an instance of theadvertised value class
.For instance,
Pointer
data types should return an Address object (or null), or integer data types should return aScalar
object.- Parameters:
buf
- the data buffersettings
- the settings to use.length
- indicates the maximum number of bytes that may be consumed by aDynamic
datatype, otherwise this value is ignored. A value of -1 may be specified to allow a Dynamic datatype to determine the length based upon the actual data bytes- Returns:
- the data object, or null if data is invalid
-
getValueClass
Description copied from interface:DataType
Get the Class of the value Object to be returned by this datatype (seeDataType.getValue(MemBuffer, Settings, int)
).- Parameters:
settings
- the relevant settings to use or null for default.- Returns:
- Class of the value to be returned by this datatype or null if it can vary or is unspecified. Types which correspond to a string or char array will return the String class.
-
getRepresentation
Description copied from interface:DataType
Get bytes from memory in a printable format for this type.- 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.
-
getAlignment
public int getAlignment()Description copied from interface:DataType
Gets the alignment to be used when aligning this datatype within another datatype.- Returns:
- this datatype's alignment.
-
toString
- Overrides:
toString
in classAbstractDataType
-