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 CategoryPathcategoryPathprotected DataTypeManagerdataMgrprotected java.lang.Stringname-
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 protectedAbstractDataType(CategoryPath path, java.lang.String name, DataTypeManager dataTypeManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddParent(DataType dt)Inform this datatype that it has the given parentvoiddataTypeAlignmentChanged(DataType dt)Notification that the given datatype's alignment has changed.voiddataTypeDeleted(DataType dt)Informs this datatype that the given datatype has been deleted.voiddataTypeNameChanged(DataType dt, java.lang.String oldName)Informs this datatype that its name has changed from the indicated old name.voiddataTypeReplaced(DataType oldDt, DataType newDt)Informs this datatype that the given oldDT has been replaced with newDTvoiddataTypeSizeChanged(DataType dt)Notification that the given datatype's size has changed.booleandependsOn(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.CategoryPathgetCategoryPath()Gets the categoryPath associated with this datatypeDataOrganizationgetDataOrganization()Returns the DataOrganization associated with this data-typeDataTypeManagergetDataTypeManager()Get the DataTypeManager containing this datatype.DataTypePathgetDataTypePath()Returns the dataTypePath for this datatype;java.lang.StringgetDefaultAbbreviatedLabelPrefix()Returns the prefix to use for this datatype when an abbreviated prefix is desired.java.lang.StringgetDefaultLabelPrefix()Returns the appropriate string to use as the default label prefix in the absence of any data.java.lang.StringgetDefaultLabelPrefix(MemBuffer buf, Settings settings, int len, DataTypeDisplayOptions options)Returns the appropriate string to use as the default label prefix.java.lang.StringgetDefaultOffcutLabelPrefix(MemBuffer buf, Settings settings, int len, DataTypeDisplayOptions options, int offcutLength)Returns the appropriate string to use as the default label prefix.java.lang.StringgetDisplayName()Gets the name for referring to this datatype.java.net.URLgetDocs()The getDocs method should provide a URL pointing to extended documentation for this DataType if it exists.longgetLastChangeTime()Get the timestamp corresponding to the last time this type was changed within its datatype managerlonggetLastChangeTimeInSourceArchive()Get the timestamp corresponding to the last time this type was sync'd within its source archivejava.lang.StringgetMnemonic(Settings settings)Get the mnemonic for this DataType.java.lang.StringgetName()Get the name of this datatype.DataType[]getParents()Get the parents of this datatypejava.lang.StringgetPathName()Get the full category path name that includes this datatype's name.SourceArchivegetSourceArchive()Get the source archive where this type originatedUniversalIDgetUniversalID()Get the universal ID for this datatype.booleanhasLanguageDependantLength()Indicates if the length of this data-type is determined based upon theDataOrganizationobtained from the associatedDataTypeManager.booleanisDeleted()Returns true if this datatype has been deleted and is no longer validbooleanisEncodable()Check if this type supports encoding (patching)booleanisNotYetDefined()Indicates if this datatype has not yet been fully defined.booleanisZeroLength()Indicates this datatype is defined with a zero length.voidremoveParent(DataType dt)Remove a parent datatypevoidreplaceWith(DataType dataType)For datatypes that support change, this method replaces the internals of this datatype with the internals of the given datatype.voidsetCategoryPath(CategoryPath path)Set the categoryPath associated with this datatypevoidsetDescription(java.lang.String description)Sets a String briefly describing this DataType.voidsetLastChangeTime(long lastChangeTime)Sets the lastChangeTime for this datatype.voidsetLastChangeTimeInSourceArchive(long lastChangeTimeInSourceArchive)Sets the lastChangeTimeInSourceArchive for this datatype.voidsetName(java.lang.String name)Sets the name of the datatypevoidsetNameAndCategory(CategoryPath path, java.lang.String name)Sets the name and category of a datatype at the same time.voidsetSourceArchive(SourceArchive archive)Set the source archive where this type originatedjava.lang.StringtoString()-
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:DataTypeGets the categoryPath associated with this datatype- Specified by:
getCategoryPathin interfaceDataType- Returns:
- the datatype's category path
-
getDataTypeManager
public final DataTypeManager getDataTypeManager()
Description copied from interface:DataTypeGet 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:
getDataTypeManagerin interfaceDataType- Returns:
- the DataTypeManager that is associated with this datatype.
- See Also:
DataType.getDataTypeManager()
-
getDataOrganization
public final DataOrganization getDataOrganization()
Description copied from interface:DataTypeReturns the DataOrganization associated with this data-type- Specified by:
getDataOrganizationin interfaceDataType- Returns:
- associated data organization
-
getDataTypePath
public DataTypePath getDataTypePath()
Description copied from interface:DataTypeReturns the dataTypePath for this datatype;- Specified by:
getDataTypePathin interfaceDataType- Returns:
- the dataTypePath for this datatype;
-
getDocs
public java.net.URL getDocs()
Description copied from interface:DataTypeThe 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:DataTypeGet the name of this datatype.
-
getPathName
public java.lang.String getPathName()
Description copied from interface:DataTypeGet 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:
getPathNamein interfaceDataType- Returns:
- the path, or just this type's name
-
getDisplayName
public java.lang.String getDisplayName()
Description copied from interface:DataTypeGets the name for referring to this datatype.- Specified by:
getDisplayNamein interfaceDataType- Returns:
- generic name for this Data Type (i.e.: Word)
-
getMnemonic
public java.lang.String getMnemonic(Settings settings)
Description copied from interface:DataTypeGet the mnemonic for this DataType.- Specified by:
getMnemonicin 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:DataTypeIndicates 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:
isNotYetDefinedin interfaceDataType- Returns:
- true if this type is not yet defined.
-
isZeroLength
public boolean isZeroLength()
Description copied from interface:DataTypeIndicates 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 aCompositemay, or may not, be assigned a component length of 0. The methodDataTypeComponent.usesZeroLengthComponent(DataType)is used to make this determination.- Specified by:
isZeroLengthin interfaceDataType- Returns:
- true if type definition has a length of 0, else false
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isDeleted
public boolean isDeleted()
Description copied from interface:DataTypeReturns true if this datatype has been deleted and is no longer valid
-
setName
public void setName(java.lang.String name) throws InvalidNameExceptionDescription copied from interface:DataTypeSets the name of the datatype- Specified by:
setNamein 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:DataTypeSets the name and category of a datatype at the same time.- Specified by:
setNameAndCategoryin interfaceDataType- Parameters:
path- the new category path.name- the new name- Throws:
InvalidNameException- if the name is invalidDuplicateNameException- if name change on storedDataTypeis a duplicate of another datatype within the same category (only applies to DB storedDataType).
-
dataTypeSizeChanged
public void dataTypeSizeChanged(DataType dt)
Description copied from interface:DataTypeNotification 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:
dataTypeSizeChangedin interfaceDataType- Parameters:
dt- the datatype that has changed.
-
dataTypeAlignmentChanged
public void dataTypeAlignmentChanged(DataType dt)
Description copied from interface:DataTypeNotification 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:
dataTypeAlignmentChangedin interfaceDataType- Parameters:
dt- the datatype that has changed.
-
dataTypeDeleted
public void dataTypeDeleted(DataType dt)
Description copied from interface:DataTypeInforms this datatype that the given datatype has been deleted.TODO: This method is reserved for internal DB use.
- Specified by:
dataTypeDeletedin interfaceDataType- Parameters:
dt- the datatype that has been deleted.
-
dataTypeReplaced
public void dataTypeReplaced(DataType oldDt, DataType newDt)
Description copied from interface:DataTypeInforms this datatype that the given oldDT has been replaced with newDTTODO: This method is reserved for internal DB use.
- Specified by:
dataTypeReplacedin interfaceDataType- Parameters:
oldDt- old datatypenewDt- new datatype
-
addParent
public void addParent(DataType dt)
Description copied from interface:DataTypeInform 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:DataTypeRemove a parent datatypeTODO: This method is reserved for internal DB use.
- Specified by:
removeParentin interfaceDataType- Parameters:
dt- parent datatype
-
getParents
public DataType[] getParents()
Description copied from interface:DataTypeGet the parents of this datatype- Specified by:
getParentsin interfaceDataType- Returns:
- an array of parents of this datatype
-
dependsOn
public boolean dependsOn(DataType dt)
Description copied from interface:DataTypeCheck 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:DataTypeGet the source archive where this type originated- Specified by:
getSourceArchivein interfaceDataType- Returns:
- source archive object
-
setSourceArchive
public void setSourceArchive(SourceArchive archive)
Description copied from interface:DataTypeSet the source archive where this type originated- Specified by:
setSourceArchivein interfaceDataType- Parameters:
archive- source archive object
-
getLastChangeTime
public long getLastChangeTime()
Description copied from interface:DataTypeGet the timestamp corresponding to the last time this type was changed within its datatype manager- Specified by:
getLastChangeTimein interfaceDataType- Returns:
- timestamp of last change within datatype manager
-
getLastChangeTimeInSourceArchive
public long getLastChangeTimeInSourceArchive()
Description copied from interface:DataTypeGet the timestamp corresponding to the last time this type was sync'd within its source archive- Specified by:
getLastChangeTimeInSourceArchivein interfaceDataType- Returns:
- timestamp of last sync with source archive
-
getUniversalID
public UniversalID getUniversalID()
Description copied from interface:DataTypeGet 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:
getUniversalIDin interfaceDataType- Returns:
- datatype UniversalID
-
dataTypeNameChanged
public void dataTypeNameChanged(DataType dt, java.lang.String oldName)
Description copied from interface:DataTypeInforms this datatype that its name has changed from the indicated old name.TODO: This method is reserved for internal DB use.
- Specified by:
dataTypeNameChangedin interfaceDataType- Parameters:
dt- the datatype whose name changedoldName- the datatype's old name
-
replaceWith
public void replaceWith(DataType dataType)
Description copied from interface:DataTypeFor 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:
replaceWithin interfaceDataType
-
setLastChangeTime
public void setLastChangeTime(long lastChangeTime)
Description copied from interface:DataTypeSets 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:
setLastChangeTimein interfaceDataType- Parameters:
lastChangeTime- the time to use as the lastChangeTime for this datatype
-
setLastChangeTimeInSourceArchive
public void setLastChangeTimeInSourceArchive(long lastChangeTimeInSourceArchive)
Description copied from interface:DataTypeSets the lastChangeTimeInSourceArchive for this datatype.This is used by when a datatype change is committed back to its source archive.
- Specified by:
setLastChangeTimeInSourceArchivein interfaceDataType- Parameters:
lastChangeTimeInSourceArchive- the time to use as the lastChangeTimeInSourceArchive for this datatype
-
setDescription
public void setDescription(java.lang.String description) throws java.lang.UnsupportedOperationExceptionDescription copied from interface:DataTypeSets a String briefly describing this DataType.- Specified by:
setDescriptionin 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:DataTypeIndicates if the length of this data-type is determined based upon theDataOrganizationobtained from the associatedDataTypeManager.- Specified by:
hasLanguageDependantLengthin interfaceDataType- Returns:
- true length is language/compiler-specification dependent, else false
-
getDefaultLabelPrefix
public java.lang.String getDefaultLabelPrefix()
Description copied from interface:DataTypeReturns the appropriate string to use as the default label prefix in the absence of any data.- Specified by:
getDefaultLabelPrefixin interfaceDataType- Returns:
- the default label prefix or null if none specified.
-
getDefaultAbbreviatedLabelPrefix
public java.lang.String getDefaultAbbreviatedLabelPrefix()
Description copied from interface:DataTypeReturns 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:
getDefaultAbbreviatedLabelPrefixin 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:DataTypeSet the categoryPath associated with this datatype- Specified by:
setCategoryPathin 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:DataTypeReturns the appropriate string to use as the default label prefix.- Specified by:
getDefaultLabelPrefixin 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:DataTypeReturns 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
offcutLengthbytes into this type- Specified by:
getDefaultOffcutLabelPrefixin 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:DataTypeCheck 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 eitherencodemethod should not be displayed if the applicable datatype is not encodable.- Specified by:
isEncodablein interfaceDataType- Returns:
- true if encoding is supported
-
encodeValue
public byte[] encodeValue(java.lang.Object value, MemBuffer buf, Settings settings, int length) throws DataTypeEncodeExceptionDescription copied from interface:DataTypeEncode 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:
encodeValuein 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 DataTypeEncodeExceptionDescription copied from interface:DataTypeEncode 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:
encodeRepresentationin 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()).
-
-