Package ghidra.program.model.data
Class BitFieldDataType
- java.lang.Object
-
- ghidra.program.model.data.AbstractDataType
-
- ghidra.program.model.data.BitFieldDataType
-
- All Implemented Interfaces:
DataType
public class BitFieldDataType extends AbstractDataType
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 Modifier and Type Field Description protected Settings
defaultSettings
-
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, VOID
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addParent(DataType dt)
Inform this data type that it has the given parent
TODO: This method is reserved for internal DB use and should be removed from the public DataType interface!!static void
checkBaseDataType(DataType baseDataType)
Check a bitfield base datatypeBitFieldDataType
clone(DataTypeManager dtm)
Clone this bitfield to a new datatype manager.DataType
copy(DataTypeManager dtm)
Returns a clone of this built-in DataTypeboolean
equals(java.lang.Object obj)
int
getAlignment()
Gets the alignment to be used when aligning this data type within another data type.DataType
getBaseDataType()
Get the base datatype associated with this bit-field (e.g., int, long, etc., or TypeDef to supported base type)int
getBaseTypeSize()
Get the size of the base data type based upon the associated data organization.java.math.BigInteger
getBigIntegerValue(MemBuffer buf, Settings settings)
int
getBitOffset()
Get the bit offset of the least-significant bit relative to bit-0 of the base datatype (i.e., least significant bit).int
getBitSize()
Get the effective bit size of this bit-field which may not exceed the size of the base datatype.int
getDeclaredBitSize()
Get the declared bit size of this bit-field which may be larger than the effective size which could be truncated.Settings
getDefaultSettings()
Gets the default settings for this data type.java.lang.String
getDescription()
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
getLength()
Get the length (number of 8-bit bytes) of this DataType.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)AbstractIntegerDataType
getPrimitiveBaseDataType()
Get the base datatype associated with this bit-field (e.g., int, long, etc., or TypeDef to supported base type)java.lang.String
getRepresentation(MemBuffer buf, Settings settings, int length)
Get bytes from memory in a printable format for this type.SettingsDefinition[]
getSettingsDefinitions()
Gets a list of all the settingsDefinitions used by this datatype.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.java.lang.Object
getValue(MemBuffer buf, Settings settings, int length)
Get the data in the form of the appropriate Object for this DataType.java.lang.Class<?>
getValueClass(Settings settings)
Get the Class of the value to be returned by this data type.int
hashCode()
boolean
isEquivalent(DataType dt)
Returns true 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
isZeroLengthField()
Determine if this bit-field has a zero length (i.e., alignment field)void
setDefaultSettings(Settings settings)
Set the default settings for this data type.java.lang.String
toString()
-
Methods inherited from class ghidra.program.model.data.AbstractDataType
dataTypeDeleted, dataTypeNameChanged, dataTypeReplaced, dataTypeSizeChanged, dependsOn, getCategoryPath, getDataOrganization, getDataTypeManager, getDataTypePath, getDefaultAbbreviatedLabelPrefix, getDefaultLabelPrefix, getDefaultLabelPrefix, getDefaultOffcutLabelPrefix, getDisplayName, getDocs, getLastChangeTime, getLastChangeTimeInSourceArchive, getMnemonic, getName, getParents, getPathName, getSourceArchive, getUniversalID, isDeleted, isDynamicallySized, isNotYetDefined, removeParent, replaceWith, setCategoryPath, setDescription, setLastChangeTime, setLastChangeTimeInSourceArchive, setName, setNameAndCategory, setSourceArchive
-
-
-
-
Field Detail
-
defaultSettings
protected Settings defaultSettings
-
-
Constructor Detail
-
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
protected BitFieldDataType(DataType baseDataType, int bitSize) throws InvalidDataTypeException
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 Detail
-
isZeroLengthField
public boolean isZeroLengthField()
Determine if this bit-field has a zero length (i.e., alignment field)- Returns:
- true if this bit-field has a zero length
-
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
public static void checkBaseDataType(DataType baseDataType) throws InvalidDataTypeException
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
public static boolean isValidBaseDataType(DataType baseDataType)
Check if a specified baseDataType is valid for use with a bitfield- Parameters:
baseDataType
- bitfield base data type (Enum, AbstractIntegerDataType and derived TypeDefs permitted)
-
addParent
public void addParent(DataType dt)
Description copied from interface:DataType
Inform this data type that it has the given parent
TODO: This method is reserved for internal DB use and should be removed from the public DataType interface!!- 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
public DataType 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
public AbstractIntegerDataType 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
public final SettingsDefinition[] getSettingsDefinitions()
Gets a list of all the settingsDefinitions used by this datatype.- Returns:
- a list of the settingsDefinitions used by this datatype.
-
isEquivalent
public final 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.- 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()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getDefaultSettings
public Settings getDefaultSettings()
Description copied from interface:DataType
Gets the default settings for this data type.- Returns:
- the default settings for this dataType.
-
copy
public final DataType copy(DataTypeManager dtm)
Returns a clone of this built-in DataType- Parameters:
dtm
- the data-type manager instance whose data-organization should apply.- See Also:
DataType.copy(ghidra.program.model.data.DataTypeManager)
-
clone
public BitFieldDataType clone(DataTypeManager dtm)
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 (number of 8-bit bytes) of this DataType.- Returns:
- the length of this DataType
-
getDescription
public java.lang.String getDescription()
Description copied from interface:DataType
Get a String briefly describing this DataType.- 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- Parameters:
buf
- the data buffer.settings
- the settings to use.length
- the number of bytes to get the value from.- Returns:
- the data Object.
-
getBigIntegerValue
public java.math.BigInteger getBigIntegerValue(MemBuffer buf, Settings settings)
-
getValueClass
public java.lang.Class<?> getValueClass(Settings settings)
Description copied from interface:DataType
Get the Class of the value to be returned by this data type.- Parameters:
settings
- the relevant settings to use or null for default.- Returns:
- Class of the value to be returned by this data type or null if it can vary or is unspecified. Types which correspond to a string or char array will return the String class.
-
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.- 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.
-
setDefaultSettings
public void setDefaultSettings(Settings settings)
Description copied from interface:DataType
Set the default settings for this data type.
TODO: This method is reserved for internal DB use and should be removed from the public DataType interface!!- Parameters:
settings
- the settings to be used as this dataTypes default settings.
-
getAlignment
public int getAlignment()
Description copied from interface:DataType
Gets the alignment to be used when aligning this data type within another data type.- Returns:
- this data type's alignment.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractDataType
-
-