Class AbstractDataType
- All Implemented Interfaces:
DataType
- Direct Known Subclasses:
BitFieldDataType
,DataTypeImpl
,PartialUnion
-
Field Summary
Modifier and TypeFieldDescriptionprotected CategoryPath
protected final DataTypeManager
protected String
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
AbstractDataType
(CategoryPath path, String name, DataTypeManager dataTypeManager) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inform this data type that it has the given parent
TODO: This method is reserved for internal DB use.void
Notification that the given datatype's alignment has changed.void
Informs this datatype that the given datatype has been deleted.void
dataTypeNameChanged
(DataType dt, String oldName) Informs this datatype that its name has changed from the indicated old name.void
dataTypeReplaced
(DataType oldDt, DataType newDt) Informs this datatype that the given oldDT has been replaced with newDTvoid
Notification that the given datatype's size has changed.boolean
Check if this datatype depends on the existence of the given datatype.byte[]
encodeRepresentation
(String repr, MemBuffer buf, Settings settings, int length) Encode bytes according to the display format for this type.byte[]
encodeValue
(Object value, MemBuffer buf, Settings settings, int length) Encode bytes from an Object appropriate for this DataType.Gets the categoryPath associated with this datatypefinal DataOrganization
Returns the DataOrganization associated with this data-typeprotected static DataOrganization
getDataOrganization
(DataTypeManager dataMgr) Get theDataOrganization
which should be used by aAbstractDataType
when associated with a specifieddataMgr
.final DataTypeManager
Get the DataTypeManager containing this datatype.Returns the dataTypePath for this datatype;Returns the prefix to use for this datatype when an abbreviated prefix is desired.Returns the appropriate string to use as the default label prefix in the absence of any data.getDefaultLabelPrefix
(MemBuffer buf, Settings settings, int len, DataTypeDisplayOptions options) Returns the appropriate string to use as the default label prefix.getDefaultOffcutLabelPrefix
(MemBuffer buf, Settings settings, int len, DataTypeDisplayOptions options, int offcutLength) Returns the appropriate string to use as the default label prefix.Gets the name for referring to this datatype.getDocs()
The getDocs method should provide a URL pointing to extended documentation for this DataType if it exists.long
Get the timestamp corresponding to the last time this type was changed within its datatype managerlong
Get the timestamp corresponding to the last time this type was sync'd within its source archivegetMnemonic
(Settings settings) Get the mnemonic for this DataType.getName()
Get the name of this datatype.Get the parents of this datatype.Get the full category path name that includes this datatype's name.Get the source archive where this type originatedGet the list of all settings definitions for this datatype that may be used for an associatedTypeDef
.Get the universal ID for this datatype.boolean
Indicates if the length of this data-type is determined based upon theDataOrganization
obtained from the associatedDataTypeManager
.boolean
Returns true if this datatype has been deleted and is no longer validboolean
Check if this type supports encoding (patching)boolean
Indicates if this datatype has not yet been fully defined.boolean
Indicates this datatype is defined with a zero length.void
removeParent
(DataType dt) Remove a parent datatypevoid
replaceWith
(DataType dataType) For datatypes that support change, this method replaces the internals of this datatype with the internals of the given datatype.void
setCategoryPath
(CategoryPath path) Set the categoryPath associated with this datatypevoid
setDescription
(String description) Sets a String briefly describing this DataType.void
setLastChangeTime
(long lastChangeTime) Sets the lastChangeTime for this datatype.void
setLastChangeTimeInSourceArchive
(long lastChangeTimeInSourceArchive) Sets the lastChangeTimeInSourceArchive for this datatype.void
Sets the name of the datatypevoid
setNameAndCategory
(CategoryPath path, String name) Sets the name and category of a datatype at the same time.void
setSourceArchive
(SourceArchive archive) Set the source archive where this type originatedtoString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ghidra.program.model.data.DataType
clone, copy, getAlignedLength, getAlignment, getDefaultSettings, getDescription, getLength, getRepresentation, getSettingsDefinitions, getValue, getValueClass, isEquivalent
-
Field Details
-
name
-
categoryPath
-
dataMgr
-
-
Constructor Details
-
AbstractDataType
-
-
Method Details
-
getTypeDefSettingsDefinitions
Description copied from interface:DataType
Get the list of all settings definitions for this datatype that may be used for an associatedTypeDef
. When used for an associatedTypeDef
, these settings will be considered during aDataType.isEquivalent(DataType)
check and will be preserved during the resolve process.- Specified by:
getTypeDefSettingsDefinitions
in interfaceDataType
- Returns:
- a list of the settings definitions for a
TypeDef
associated with this datatype.
-
getCategoryPath
Description copied from interface:DataType
Gets the categoryPath associated with this datatype- Specified by:
getCategoryPath
in interfaceDataType
- Returns:
- the datatype's category path
-
getDataTypeManager
Description copied from interface:DataType
Get the DataTypeManager containing this datatype.This association should not be used to indicate whether this DataType has been resolved, but is intended to indicate whether the appropriate DataOrganization is being used.
- Specified by:
getDataTypeManager
in interfaceDataType
- Returns:
- the DataTypeManager that is associated with this datatype.
- See Also:
-
getDataOrganization
Description copied from interface:DataType
Returns the DataOrganization associated with this data-type- Specified by:
getDataOrganization
in interfaceDataType
- Returns:
- associated data organization
-
getDataOrganization
Get theDataOrganization
which should be used by aAbstractDataType
when associated with a specifieddataMgr
. If a nulldataMgr
is specified the defaultDataOrganization
will be returned.- Parameters:
dataMgr
- datatype manager- Returns:
- the
DataOrganization
which should be used by aAbstractDataType
instance.
-
getDataTypePath
Description copied from interface:DataType
Returns the dataTypePath for this datatype;- Specified by:
getDataTypePath
in interfaceDataType
- Returns:
- the dataTypePath for this datatype;
-
getDocs
Description copied from interface:DataType
The getDocs method should provide a URL pointing to extended documentation for this DataType if it exists.A typical use would be to return a URL pointing to the programmers reference for this instruction or a page describing this data structure.
-
getName
Description copied from interface:DataType
Get the name of this datatype. -
getPathName
Description copied from interface:DataType
Get the full category path name that includes this datatype's name.If the category is null, then this just the datatype's name is returned.
- Specified by:
getPathName
in interfaceDataType
- Returns:
- the path, or just this type's name
-
getDisplayName
Description copied from interface:DataType
Gets the name for referring to this datatype.- Specified by:
getDisplayName
in interfaceDataType
- Returns:
- generic name for this Data Type (i.e.: Word)
-
getMnemonic
Description copied from interface:DataType
Get the mnemonic for this DataType.- Specified by:
getMnemonic
in interfaceDataType
- Parameters:
settings
- settings which may influence the result or null- Returns:
- the mnemonic for this DataType.
-
isNotYetDefined
public boolean isNotYetDefined()Description copied from interface:DataType
Indicates if this datatype has not yet been fully defined.Such datatypes should always return a
DataType.getLength()
of 1 and true forDataType.isZeroLength()
. (example: empty structure)- Specified by:
isNotYetDefined
in interfaceDataType
- Returns:
- true if this type is not yet defined.
-
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
- Returns:
- true if type definition has a length of 0, else false
-
toString
-
isDeleted
public boolean isDeleted()Description copied from interface:DataType
Returns true if this datatype has been deleted and is no longer valid -
setName
Description copied from interface:DataType
Sets the name of the datatype- Specified by:
setName
in interfaceDataType
- Parameters:
name
- the new name for this datatype.- Throws:
InvalidNameException
- if the given name does not form a valid name.
-
setNameAndCategory
public void setNameAndCategory(CategoryPath path, String name) throws InvalidNameException, DuplicateNameException Description copied from interface:DataType
Sets the name and category of a datatype at the same time.- Specified by:
setNameAndCategory
in interfaceDataType
- Parameters:
path
- the new category path.name
- the new name- Throws:
InvalidNameException
- if the name is invalidDuplicateNameException
- if name change on storedDataType
is a duplicate of another datatype within the same category (only applies to DB storedDataType
).
-
dataTypeSizeChanged
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.- Specified by:
dataTypeSizeChanged
in interfaceDataType
- Parameters:
dt
- the datatype that has changed.
-
dataTypeAlignmentChanged
Description copied from interface:DataType
Notification that the given datatype's alignment has changed.DataTypes may need to make internal changes in response.
TODO: This method is reserved for internal DB use.- Specified by:
dataTypeAlignmentChanged
in interfaceDataType
- Parameters:
dt
- the datatype that has changed.
-
dataTypeDeleted
Description copied from interface:DataType
Informs this datatype that the given datatype has been deleted.TODO: This method is reserved for internal DB use.
- Specified by:
dataTypeDeleted
in interfaceDataType
- Parameters:
dt
- the datatype that has been deleted.
-
dataTypeReplaced
Description copied from interface:DataType
Informs this datatype that the given oldDT has been replaced with newDTTODO: This method is reserved for internal DB use.
- Specified by:
dataTypeReplaced
in interfaceDataType
- Parameters:
oldDt
- old datatypenewDt
- new datatype
-
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. -
removeParent
Description copied from interface:DataType
Remove a parent datatypeTODO: This method is reserved for internal DB use.
- Specified by:
removeParent
in interfaceDataType
- Parameters:
dt
- parent datatype
-
getParents
Description copied from interface:DataType
Get the parents of this datatype. NOTE: This method is intended to be used on a DB-managed datatype only and is not fully supported for use with non-DB datatype instances.- Specified by:
getParents
in interfaceDataType
- Returns:
- parents of this datatype
-
dependsOn
Description copied from interface:DataType
Check 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.
-
getSourceArchive
Description copied from interface:DataType
Get the source archive where this type originated- Specified by:
getSourceArchive
in interfaceDataType
- Returns:
- source archive object
-
setSourceArchive
Description copied from interface:DataType
Set the source archive where this type originated- Specified by:
setSourceArchive
in interfaceDataType
- Parameters:
archive
- source archive object
-
getLastChangeTime
public long getLastChangeTime()Description copied from interface:DataType
Get the timestamp corresponding to the last time this type was changed within its datatype manager- Specified by:
getLastChangeTime
in interfaceDataType
- Returns:
- timestamp of last change within datatype manager
-
getLastChangeTimeInSourceArchive
public long getLastChangeTimeInSourceArchive()Description copied from interface:DataType
Get the timestamp corresponding to the last time this type was sync'd within its source archive- Specified by:
getLastChangeTimeInSourceArchive
in interfaceDataType
- Returns:
- timestamp of last sync with source archive
-
getUniversalID
Description copied from interface:DataType
Get the universal ID for this datatype.This value is intended to be a unique identifier across all programs and archives. The same ID indicates that two datatypes were originally the same one. Keep in mind names, categories, and component makeup may differ and have changed since there origin.
- Specified by:
getUniversalID
in interfaceDataType
- Returns:
- datatype UniversalID
-
dataTypeNameChanged
Description copied from interface:DataType
Informs this datatype that its name has changed from the indicated old name.TODO: This method is reserved for internal DB use.
- Specified by:
dataTypeNameChanged
in interfaceDataType
- Parameters:
dt
- the datatype whose name changedoldName
- the datatype's old name
-
replaceWith
Description copied from interface:DataType
For 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:
replaceWith
in interfaceDataType
- Parameters:
dataType
- the datatype that contains the internals to upgrade to.
-
setLastChangeTime
public void setLastChangeTime(long lastChangeTime) Description copied from interface:DataType
Sets the lastChangeTime for this datatype.Normally, this is updated automatically when a datatype is changed, but when committing or updating while synchronizing an archive, the lastChangeTime may need to be updated externally.
- Specified by:
setLastChangeTime
in interfaceDataType
- Parameters:
lastChangeTime
- the time to use as the lastChangeTime for this datatype
-
setLastChangeTimeInSourceArchive
public void setLastChangeTimeInSourceArchive(long lastChangeTimeInSourceArchive) Description copied from interface:DataType
Sets the lastChangeTimeInSourceArchive for this datatype.This is used by when a datatype change is committed back to its source archive.
- Specified by:
setLastChangeTimeInSourceArchive
in interfaceDataType
- Parameters:
lastChangeTimeInSourceArchive
- the time to use as the lastChangeTimeInSourceArchive for this datatype
-
setDescription
Description copied from interface:DataType
Sets a String briefly describing this DataType.- Specified by:
setDescription
in interfaceDataType
- Parameters:
description
- a one-liner describing this DataType.- Throws:
UnsupportedOperationException
- if the description is not allowed to be set for this datatype.
-
hasLanguageDependantLength
public boolean hasLanguageDependantLength()Description copied from interface:DataType
Indicates if the length of this data-type is determined based upon theDataOrganization
obtained from the associatedDataTypeManager
.- Specified by:
hasLanguageDependantLength
in interfaceDataType
- Returns:
- true length is language/compiler-specification dependent, else false
-
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
- Returns:
- the default label prefix or null if none specified.
-
getDefaultAbbreviatedLabelPrefix
Description copied from interface:DataType
Returns the prefix to use for this datatype when an abbreviated prefix is desired.For example, some datatypes will built a large default label, at which is is more desirable to have a shortened prefix.
- Specified by:
getDefaultAbbreviatedLabelPrefix
in interfaceDataType
- Returns:
- the prefix to use for this datatype when an abbreviated prefix is desired. May return null.
-
setCategoryPath
Description copied from interface:DataType
Set the categoryPath associated with this datatype- Specified by:
setCategoryPath
in interfaceDataType
- Parameters:
path
- the new path- Throws:
DuplicateNameException
- if an attempt to place this datatype into the specified category resulted in a name collision. This should not occur for non-DB DataType instances.
-
getDefaultLabelPrefix
public String getDefaultLabelPrefix(MemBuffer buf, Settings settings, int len, DataTypeDisplayOptions options) Description copied from interface:DataType
Returns the appropriate string to use as the default label prefix.- Specified by:
getDefaultLabelPrefix
in interfaceDataType
- Parameters:
buf
- memory buffer containing the bytes.settings
- the Settings objectlen
- the length of the data.options
- options for how to format the default label prefix.- Returns:
- the default label prefix or null if none specified.
-
getDefaultOffcutLabelPrefix
public String getDefaultOffcutLabelPrefix(MemBuffer buf, Settings settings, int len, DataTypeDisplayOptions options, int offcutLength) Description copied from interface:DataType
Returns the appropriate string to use as the default label prefix.This takes into account the fact that there exists a reference to the data that references
offcutLength
bytes into this type- Specified by:
getDefaultOffcutLabelPrefix
in interfaceDataType
- Parameters:
buf
- memory buffer containing the bytes.settings
- the Settings objectlen
- the length of the data.options
- options for how to format the default label prefix.offcutLength
- offset into datatype- Returns:
- the default label prefix.
-
isEncodable
public boolean isEncodable()Description copied from interface:DataType
Check if this type supports encoding (patching)If unsupported,
DataType.encodeValue(Object, MemBuffer, Settings, int)
andDataType.encodeRepresentation(String, MemBuffer, Settings, int)
will always throw an exception. Actions which rely on eitherencode
method should not be displayed if the applicable datatype is not encodable.- Specified by:
isEncodable
in interfaceDataType
- Returns:
- true if encoding is supported
-
encodeValue
public byte[] encodeValue(Object value, MemBuffer buf, Settings settings, int length) throws DataTypeEncodeException Description copied from interface:DataType
Encode bytes from an Object appropriate for this DataType.Converts the given object to the byte encoding and returns it. When appropriate, this should seek the nearest encoding to the specified value, since the object may come from a user script. For example, a floating-point value may be rounded. Invalid values should be rejected with a
DataTypeEncodeException
.- Specified by:
encodeValue
in interfaceDataType
- Parameters:
value
- the desired value.buf
- a buffer representing the eventual destination of the bytes.settings
- the settings to use.length
- the expected length of the result, usually the length of the data unit, or -1 to let the type choose the length. It may be ignored, e.g., for fixed-length types.- Returns:
- the encoded value.
- Throws:
DataTypeEncodeException
- if the value cannot be encoded for any reason, e.g., incorrect type, not enough space, buffer overflow, unsupported (seeDataType.isEncodable()
).
-
encodeRepresentation
public byte[] encodeRepresentation(String repr, MemBuffer buf, Settings settings, int length) throws DataTypeEncodeException Description copied from interface:DataType
Encode bytes according to the display format for this type.Converts the given representation to the byte encoding and returns it. When appropriate, this should seek the nearest encoding to the specified value, since the representation is likely coming from user input. For example, a floating-point value may be rounded. Invalid representations should be rejected with a
DataTypeEncodeException
.- Specified by:
encodeRepresentation
in interfaceDataType
- Parameters:
repr
- the representation of the desired value, as inDataType.getRepresentation(MemBuffer, Settings, int)
. The supported formats depend on the specific datatype and its settings.buf
- a buffer representing the eventual destination of the bytes.settings
- the settings to use for the representation.length
- the expected length of the result, usually the length of the data unit, or -1 to let the type choose the length. It may be ignored, e.g., for fixed-length types.- Returns:
- the encoded value.
- Throws:
DataTypeEncodeException
- if the value cannot be encoded for any reason, e.g., incorrect format, not enough space, buffer overflow, unsupported (seeDataType.isEncodable()
).
-