Class AbstractDataType
- java.lang.Object
-
- ghidra.program.model.data.AbstractDataType
-
- All Implemented Interfaces:
DataType
- Direct Known Subclasses:
BitFieldDataType
,DataTypeImpl
public abstract class AbstractDataType extends java.lang.Object implements DataType
Base class for DataType classes. Many of the DataType methods are stubbed out so simple datatype classes can be created without implementing too many methods.
-
-
Field Summary
Fields Modifier and Type Field Description protected CategoryPath
categoryPath
protected DataTypeManager
dataMgr
protected java.lang.String
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
AbstractDataType(CategoryPath path, java.lang.String name, DataTypeManager dataTypeManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addParent(DataType dt)
Inform this datatype that it has the given parentvoid
dataTypeAlignmentChanged(DataType dt)
Notification that the given datatype's alignment has changed.void
dataTypeDeleted(DataType dt)
Informs this datatype that the given datatype has been deleted.void
dataTypeNameChanged(DataType dt, java.lang.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
dataTypeSizeChanged(DataType dt)
Notification that the given datatype's size has changed.boolean
dependsOn(DataType dt)
Check if this datatype depends on the existence of the given datatype.byte[]
encodeRepresentation(java.lang.String repr, MemBuffer buf, Settings settings, int length)
Encode bytes according to the display format for this type.byte[]
encodeValue(java.lang.Object value, MemBuffer buf, Settings settings, int length)
Encode bytes from an Object appropriate for this DataType.CategoryPath
getCategoryPath()
Gets the categoryPath associated with this datatypeDataOrganization
getDataOrganization()
Returns the DataOrganization associated with this data-typeDataTypeManager
getDataTypeManager()
Get the DataTypeManager containing this datatype.DataTypePath
getDataTypePath()
Returns the dataTypePath for this datatype;java.lang.String
getDefaultAbbreviatedLabelPrefix()
Returns the prefix to use for this datatype when an abbreviated prefix is desired.java.lang.String
getDefaultLabelPrefix()
Returns the appropriate string to use as the default label prefix in the absence of any data.java.lang.String
getDefaultLabelPrefix(MemBuffer buf, Settings settings, int len, DataTypeDisplayOptions options)
Returns the appropriate string to use as the default label prefix.java.lang.String
getDefaultOffcutLabelPrefix(MemBuffer buf, Settings settings, int len, DataTypeDisplayOptions options, int offcutLength)
Returns the appropriate string to use as the default label prefix.java.lang.String
getDisplayName()
Gets the name for referring to this datatype.java.net.URL
getDocs()
The getDocs method should provide a URL pointing to extended documentation for this DataType if it exists.long
getLastChangeTime()
Get the timestamp corresponding to the last time this type was changed within its datatype managerlong
getLastChangeTimeInSourceArchive()
Get the timestamp corresponding to the last time this type was sync'd within its source archivejava.lang.String
getMnemonic(Settings settings)
Get the mnemonic for this DataType.java.lang.String
getName()
Get the name of this datatype.DataType[]
getParents()
Get the parents of this datatypejava.lang.String
getPathName()
Get the full category path name that includes this datatype's name.SourceArchive
getSourceArchive()
Get the source archive where this type originatedUniversalID
getUniversalID()
Get the universal ID for this datatype.boolean
hasLanguageDependantLength()
Indicates if the length of this data-type is determined based upon theDataOrganization
obtained from the associatedDataTypeManager
.boolean
isDeleted()
Returns true if this datatype has been deleted and is no longer validboolean
isEncodable()
Check if this type supports encoding (patching)boolean
isNotYetDefined()
Indicates if this datatype has not yet been fully defined.boolean
isZeroLength()
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(java.lang.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
setName(java.lang.String name)
Sets the name of the datatypevoid
setNameAndCategory(CategoryPath path, java.lang.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 originatedjava.lang.String
toString()
-
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, getAlignment, getDefaultSettings, getDescription, getLength, getRepresentation, getSettingsDefinitions, getValue, getValueClass, isEquivalent, setDefaultSettings
-
-
-
-
Field Detail
-
name
protected java.lang.String name
-
categoryPath
protected CategoryPath categoryPath
-
dataMgr
protected final DataTypeManager dataMgr
-
-
Constructor Detail
-
AbstractDataType
protected AbstractDataType(CategoryPath path, java.lang.String name, DataTypeManager dataTypeManager)
-
-
Method Detail
-
getCategoryPath
public CategoryPath 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
public final DataTypeManager 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:
DataType.getDataTypeManager()
-
getDataOrganization
public final DataOrganization getDataOrganization()
Description copied from interface:DataType
Returns the DataOrganization associated with this data-type- Specified by:
getDataOrganization
in interfaceDataType
- Returns:
- associated data organization
-
getDataTypePath
public DataTypePath getDataTypePath()
Description copied from interface:DataType
Returns the dataTypePath for this datatype;- Specified by:
getDataTypePath
in interfaceDataType
- Returns:
- the dataTypePath for this datatype;
-
getDocs
public java.net.URL 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
public java.lang.String getName()
Description copied from interface:DataType
Get the name of this datatype.
-
getPathName
public java.lang.String 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
public java.lang.String 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
public java.lang.String getMnemonic(Settings settings)
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
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isDeleted
public boolean isDeleted()
Description copied from interface:DataType
Returns true if this datatype has been deleted and is no longer valid
-
setName
public void setName(java.lang.String name) throws InvalidNameException
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, java.lang.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
public void dataTypeSizeChanged(DataType dt)
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
public void dataTypeAlignmentChanged(DataType dt)
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
public void dataTypeDeleted(DataType dt)
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
public void dataTypeReplaced(DataType oldDt, DataType newDt)
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
public void addParent(DataType dt)
Description copied from interface:DataType
Inform this datatype that it has the given parentTODO: This method is reserved for internal DB use.
-
removeParent
public void removeParent(DataType dt)
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
public DataType[] getParents()
Description copied from interface:DataType
Get the parents of this datatype- Specified by:
getParents
in interfaceDataType
- Returns:
- an array of parents of this datatype
-
dependsOn
public boolean dependsOn(DataType dt)
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
public SourceArchive getSourceArchive()
Description copied from interface:DataType
Get the source archive where this type originated- Specified by:
getSourceArchive
in interfaceDataType
- Returns:
- source archive object
-
setSourceArchive
public void setSourceArchive(SourceArchive archive)
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
public UniversalID 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
public void dataTypeNameChanged(DataType dt, java.lang.String oldName)
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
public void replaceWith(DataType dataType)
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
-
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
public void setDescription(java.lang.String description) throws java.lang.UnsupportedOperationException
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:
java.lang.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
public java.lang.String 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
public java.lang.String 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
public void setCategoryPath(CategoryPath path) throws DuplicateNameException
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 java.lang.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 java.lang.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(java.lang.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(java.lang.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()
).
-
-