Package ghidra.program.model.data
Interface DataTypeManager
- All Known Subinterfaces:
DomainFileBasedDataTypeManager
,FileArchiveBasedDataTypeManager
,FileBasedDataTypeManager
,ProgramBasedDataTypeManager
,ProjectArchiveBasedDataTypeManager
- All Known Implementing Classes:
BuiltInDataTypeManager
,DataTypeManagerDB
,FileDataTypeManager
,ProgramBasedDataTypeManagerDB
,ProgramDataTypeManager
,ProjectDataTypeManager
,StandAloneDataTypeManager
public interface DataTypeManager
Interface for Managing data types.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
ID if data type type is BAD.static final long
static final UniversalID
static final String
Name of the category for the build in data types.static final long
ID for the default (undefined) data type.static final long
static final UniversalID
static final long
ID if data type type is not known in this data type manager. -
Method Summary
Modifier and TypeMethodDescriptionaddDataType
(DataType dataType, DataTypeConflictHandler handler) Returns a data type after adding it to this data manager.void
Add a listener that is notified when the dataTypeManger changes.void
addDataTypes
(Collection<DataType> dataTypes, DataTypeConflictHandler handler, TaskMonitor monitor) Sequentially adds a collection of datatypes to this data manager.void
addInvalidatedListener
(InvalidatedListener listener) Adds a listener that will be notified when this manager's cache is invalidated.boolean
Determine if settings are supported for BuiltIn datatypes within this datatype manager.boolean
Determine if settings are supported for datatype components within this datatype manager (i.e., for structure and union components).void
associateDataTypeWithArchive
(DataType datatype, SourceArchive archive) Change the given data type and its dependencies so thier source archive is set to given archive.void
close()
Closes this dataType managerboolean
Return true if the given dataType exists in this data type managerboolean
containsCategory
(CategoryPath path) Returns true if the given category path exists in this datatype managercreateCategory
(CategoryPath path) Create a category for the given path; returns the current category if it already exitsvoid
disassociate
(DataType datatype) If the indicated data type is associated with a source archive, this will remove the association and the data type will become local to this data type manager.void
endTransaction
(int transactionID, boolean commit) Ends the current transactionfindDataType
(String dataTypePath) Deprecated.findDataTypeForID
(UniversalID datatypeID) Get's the data type with the matching universal data type id.void
findDataTypes
(String name, List<DataType> list) Begin searching at the root category for all data types with the given name.void
findDataTypes
(String name, List<DataType> list, boolean caseSensitive, TaskMonitor monitor) Begin searching at the root category for all data types with names that match the given name that may contain wildcards using familiar globbing characters '*' and '?'.void
findEnumValueNames
(long value, Set<String> enumValueNames) Adds all enum value names that match the given value, to the given set.void
Force all pending notification events to be flushedReturns the associated AddressMap used by this datatype manager.Returns an iterator over all composite data types (structures and unions) in this managerReturns an iterator over all the dataTypes in this managervoid
getAllDataTypes
(List<DataType> list) Adds all data types to the specified list.]Returns an iterator over all function definition data types in this managerReturns an iterator over all structures in this managergetCallingConvention
(String name) Get the prototype model of the calling convention with the specified name from the associated compiler specification.getCategory
(long categoryID) Returns the Category with the given idgetCategory
(CategoryPath path) Get the category that has the given pathint
Returns the total number of data type categoriesGet the data organization associated with this data type manager.getDataType
(long dataTypeID) Returns the dataType associated with the given dataTypeId or null if the dataTypeId is not validgetDataType
(CategoryPath path, String name) Gets the data type with the indicated name in the indicated category.getDataType
(DataTypePath dataTypePath) Find the dataType for the given dataTypePath.getDataType
(SourceArchive sourceArchive, UniversalID datatypeID) Finds the data type using the given source archive and id.getDataType
(String dataTypePath) Retrieve the data type with the fully qualified path.int
getDataTypeCount
(boolean includePointersAndArrays) Returns the total number of defined data types.getDataTypes
(SourceArchive sourceArchive) Returns all data types within this manager that have as their source the given archivegetDataTypesContaining
(DataType dataType) Deprecated.the methodDataType.getParents()
should be used instead.Get the default calling convention's prototype model in this datatype manager if known.Get the ordered list of defined calling convention names.Returns a list of datatypes that have been designated as favorites.long
Returns the dataTypeId for the given dataType.Get the ordered list of known calling convention names.long
Returns the timestamp of the last time this manager was changedReturns the source archive for this managergetName()
Returns this data type manager's namegetPointer
(DataType datatype) Returns a default sized pointer to the given datatype.getPointer
(DataType datatype, int size) Returns a pointer of the given size to the given datatype.Get the optional program architecture details associated with this archiveGet the program architecture information which has been associated with this datatype manager.long
Returns the dataTypeId for the given dataType.Returns the root category ManagergetSourceArchive
(UniversalID sourceID) Returns the source archive for the given IDReturns a list of source archives not including the builtin or the program's archive.getType()
Returns this manager's archive typegetUniqueName
(CategoryPath path, String baseName) Returns a unique name not currently used by any other dataType or category with the same baseName.Returns the universal ID for this dataType managerboolean
isFavorite
(DataType datatype) Returns true if the given datatype has been designated as a favorite.boolean
Returns true if this DataTypeManager can be modified.openTransaction
(String description) Open new transaction.boolean
remove
(DataType dataType, TaskMonitor monitor) Remove the given datatype from this managervoid
Remove the DataTypeManger change listener.void
removeInvalidatedListener
(InvalidatedListener listener) Removes a previously added InvalidatedListenervoid
removeSourceArchive
(SourceArchive sourceArchive) Removes the source archive from this manager.replaceDataType
(DataType existingDt, DataType replacementDt, boolean updateCategoryPath) Replace an existing dataType with another.resolve
(DataType dataType, DataTypeConflictHandler handler) Returns a dataType that is "in" (ie suitable implementation) this Manager, creating a new one if necessary.resolveSourceArchive
(SourceArchive sourceArchive) Returns or creates a persisted version of the given source archivevoid
setFavorite
(DataType datatype, boolean isFavorite) Sets the given dataType to be either a favorite or not a favorite.void
Sets this data type manager's nameint
startTransaction
(String description) Starts a transaction for making changes in this data type manager.boolean
updateSourceArchiveName
(UniversalID sourceID, String name) Updates the name associated with a source archive in this data type manager.boolean
updateSourceArchiveName
(String archiveFileID, String name) Updates the name associated with a source archive in this data type manager.default <E extends Exception>
voidwithTransaction
(String description, ExceptionalCallback<E> callback) Performs the given callback inside of a transaction.default <E extends Exception,
T>
TwithTransaction
(String description, ExceptionalSupplier<T, E> supplier) Calls the given supplier inside of a transaction.
-
Field Details
-
DEFAULT_DATATYPE_ID
static final long DEFAULT_DATATYPE_IDID for the default (undefined) data type.- See Also:
-
NULL_DATATYPE_ID
static final long NULL_DATATYPE_IDID if data type type is not known in this data type manager.- See Also:
-
BAD_DATATYPE_ID
static final long BAD_DATATYPE_IDID if data type type is BAD.- See Also:
-
BUILT_IN_DATA_TYPES_NAME
Name of the category for the build in data types.- See Also:
-
LOCAL_ARCHIVE_KEY
static final long LOCAL_ARCHIVE_KEY- See Also:
-
BUILT_IN_ARCHIVE_KEY
static final long BUILT_IN_ARCHIVE_KEY- See Also:
-
LOCAL_ARCHIVE_UNIVERSAL_ID
-
BUILT_IN_ARCHIVE_UNIVERSAL_ID
-
-
Method Details
-
getUniversalID
UniversalID getUniversalID()Returns the universal ID for this dataType manager- Returns:
- the universal ID for this dataType manager
-
getProgramArchitecture
ProgramArchitecture getProgramArchitecture()Get the optional program architecture details associated with this archive- Returns:
- program architecture details or null if none
-
getProgramArchitectureSummary
String getProgramArchitectureSummary()Get the program architecture information which has been associated with this datatype manager. IfgetProgramArchitecture()
returns null this method may still return information if the program architecture was set on an archive but unable to properly instantiate.- Returns:
- program architecture summary if it has been set
-
containsCategory
Returns true if the given category path exists in this datatype manager- Parameters:
path
- the path- Returns:
- true if the given category path exists in this datatype manager
-
getUniqueName
Returns a unique name not currently used by any other dataType or category with the same baseName. This does not produce a conflict name and is intended to be used when generating an artifical datatype name only (e.g.,temp_1
,temp_2
; forbaseName="temp"
.- Parameters:
path
- the path of the namebaseName
- the base name to be made unique- Returns:
- a unique name starting with baseName
-
resolve
Returns a dataType that is "in" (ie suitable implementation) this Manager, creating a new one if necessary. Also the returned dataType will be in a category in this dataTypeManager that is equivalent to the category of the passed in dataType.- Parameters:
dataType
- the dataType to be resolved.handler
- used to resolve conflicts with existing dataTypes.- Returns:
- an equivalent dataType that "belongs" to this dataTypeManager.
-
addDataType
Returns a data type after adding it to this data manager. The returned dataType will be in a category in this dataTypeManager that is equivalent to the category of the passed in dataType.- Parameters:
dataType
- the dataType to be resolved.handler
- used to resolve conflicts with existing dataTypes.- Returns:
- an equivalent dataType that "belongs" to this dataTypeManager.
-
addDataTypes
void addDataTypes(Collection<DataType> dataTypes, DataTypeConflictHandler handler, TaskMonitor monitor) throws CancelledException Sequentially adds a collection of datatypes to this data manager. This method provides the added benefit of equivalence caching for improved performance.
WARNING: This is an experimental method whose use may cause the GUI and task monitor to become unresponsive due to extended hold times on the manager lock.- Parameters:
dataTypes
- collection of datatypeshandler
- conflict handlermonitor
- task monitor- Throws:
CancelledException
- if monitor is cancelled
-
getAllDataTypes
Returns an iterator over all the dataTypes in this manager- Returns:
- an iterator over all the dataTypes in this manager
-
getAllDataTypes
Adds all data types to the specified list.]- Parameters:
list
- the result list into which the types will be placed
-
getAllStructures
Returns an iterator over all structures in this manager- Returns:
- the iterator
-
getAllComposites
Returns an iterator over all composite data types (structures and unions) in this manager- Returns:
- the iterator
-
getAllFunctionDefinitions
Iterator<FunctionDefinition> getAllFunctionDefinitions()Returns an iterator over all function definition data types in this manager- Returns:
- the iterator
-
findDataTypes
Begin searching at the root category for all data types with the given name. Places all the data types in this data type manager with the given name into the list. Presence of.conflict
extension will be ignored for both specified name and returned results.- Parameters:
name
- name of the data type (wildcards are not supported and will be treated as explicit search characters)list
- list that will be populated with matching DataType objects
-
findDataTypes
Begin searching at the root category for all data types with names that match the given name that may contain wildcards using familiar globbing characters '*' and '?'.- Parameters:
name
- name to match; may contain wildcardslist
- list that will be populated with matching DataType objectscaseSensitive
- true if the match is case sensitivemonitor
- task monitor to cancel the search
-
replaceDataType
DataType replaceDataType(DataType existingDt, DataType replacementDt, boolean updateCategoryPath) throws DataTypeDependencyException Replace an existing dataType with another. All instances and references will be updated to use the replacement dataType.- Parameters:
existingDt
- the dataType to be replaced.replacementDt
- the dataType to use as the replacement.updateCategoryPath
- if true, the replacementDt will have its categoryPath changed to the exitingDt's path.- Returns:
- the resolved replacement dataType.
- Throws:
DataTypeDependencyException
- if the replacement datatype depends on the existing dataType;
-
getDataType
Retrieve the data type with the fully qualified path. So you can get the data named "bar" in the category "foo" by calling getDataType("/foo/bar"). This method can be problematic now that datatype names can contain slashes. It will work provided that the part of the datatype name that precedes its internal slash is not also the name of a category in the same category as the datatype. For example, if you call getDataType("/a/b/c"), and "b/c" is the name of your datatype, it will find it unless there is also a category "b" under category "a". A better solution is to use thegetDataType(DataTypePath)
method because the DataTypePath keeps the category and datatype name separate.- Parameters:
dataTypePath
- path- Returns:
- the dataType or null if it isn't found
-
findDataType
Deprecated.usegetDataType(String)
or better yetgetDataType(DataTypePath)
Gets the dataType for the given path. SeegetDataType(String)
for details.- Parameters:
dataTypePath
- dataType path- Returns:
- dataType at the given path
-
getDataType
Find the dataType for the given dataTypePath.- Parameters:
dataTypePath
- the DataTypePath for the datatype- Returns:
- the datatype for the given path.
-
getResolvedID
Returns the dataTypeId for the given dataType. If the dataType is not currently in the dataTypeManger, it will be added- Parameters:
dt
- the data type- Returns:
- the ID of the resolved type
-
getID
Returns the dataTypeId for the given dataType. If the dataType does not exist, a -1 will be returned- Parameters:
dt
- the datatype to get an id for- Returns:
- the ID of the type
-
getDataType
Returns the dataType associated with the given dataTypeId or null if the dataTypeId is not valid- Parameters:
dataTypeID
- the ID- Returns:
- the type
-
getCategory
Returns the Category with the given id- Parameters:
categoryID
- id of the desired category- Returns:
- the category
-
getCategory
Get the category that has the given path- Parameters:
path
- the path- Returns:
- the category if defined, otherwise null
-
addDataTypeManagerListener
Add a listener that is notified when the dataTypeManger changes.- Parameters:
l
- the listener
-
removeDataTypeManagerListener
Remove the DataTypeManger change listener.- Parameters:
l
- the listener
-
addInvalidatedListener
Adds a listener that will be notified when this manager's cache is invalidated. This will happen when the system has changed and the manager cannot determine the exact change, like during an undo or a redo.- Parameters:
listener
- The listener to add
-
removeInvalidatedListener
Removes a previously added InvalidatedListener- Parameters:
listener
- the listener to remove.
-
remove
Remove the given datatype from this manager- Parameters:
dataType
- the dataType to be removedmonitor
- the task monitor- Returns:
- true if the data type existed and was removed
-
contains
Return true if the given dataType exists in this data type manager- Parameters:
dataType
- the type- Returns:
- true if the type is in this manager
-
createCategory
Create a category for the given path; returns the current category if it already exits- Parameters:
path
- the path- Returns:
- the category
-
getDataType
Gets the data type with the indicated name in the indicated category.- Parameters:
path
- the path for the categoryname
- the data type's name- Returns:
- the data type.
-
getName
String getName()Returns this data type manager's name- Returns:
- the name
-
setName
Sets this data type manager's name- Parameters:
name
- the new name- Throws:
InvalidNameException
- if the given name is invalid (such as when null or empty)
-
isUpdatable
boolean isUpdatable()Returns true if this DataTypeManager can be modified.- Returns:
- true if this DataTypeMangaer can be modified.
-
openTransaction
Open new transaction. This should generally be done with a try-with-resources block:try (Transaction tx = dtm.openTransaction(description)) { // ... Do something }
- Parameters:
description
- a short description of the changes to be made.- Returns:
- transaction object
- Throws:
IllegalStateException
- if thisDataTypeManager
has already been closed.
-
startTransaction
Starts a transaction for making changes in this data type manager.- Parameters:
description
- a short description of the changes to be made.- Returns:
- the transaction ID
-
endTransaction
void endTransaction(int transactionID, boolean commit) Ends the current transaction- Parameters:
transactionID
- id of the transaction to endcommit
- true if changes are committed, false if changes in transaction are revoked
-
withTransaction
default <E extends Exception> void withTransaction(String description, ExceptionalCallback<E> callback) throws E Performs the given callback inside of a transaction. Use this method in place of the more verbose try/catch/finally semantics.program.withTransaction("My Description", () -> { // ... Do something });
Note: the transaction created by this method will always be committed when the call is finished. If you need the ability to abort transactions, then you need to use the other methods on this interface.
- Parameters:
description
- brief description of transactioncallback
- the callback that will be called inside of a transaction- Throws:
E
- any exception that may be thrown in the given callback
-
withTransaction
default <E extends Exception,T> T withTransaction(String description, ExceptionalSupplier<T, E> supplier) throws ECalls the given supplier inside of a transaction. Use this method in place of the more verbose try/catch/finally semantics.program.withTransaction("My Description", () -> { // ... Do something return result; });
If you do not need to supply a result, then use
withTransaction(String, ExceptionalCallback)
instead.- Type Parameters:
E
- the exception that may be thrown from this methodT
- the type of result returned by the supplier- Parameters:
description
- brief description of transactionsupplier
- the supplier that will be called inside of a transaction- Returns:
- the result returned by the supplier
- Throws:
E
- any exception that may be thrown in the given callback
-
flushEvents
void flushEvents()Force all pending notification events to be flushed- Throws:
IllegalStateException
- if the client is holding this object's lock
-
close
void close()Closes this dataType manager -
getPointer
Returns a default sized pointer to the given datatype. The pointer size is established dynamically based upon the data organization established by the compiler specification.- Parameters:
datatype
- the pointed to data type- Returns:
- the pointer
-
getPointer
Returns a pointer of the given size to the given datatype. Note: It is preferred to use default sized pointers when possible (i.e., size=-1, seegetPointer(DataType)
) instead of explicitly specifying the size value.- Parameters:
datatype
- the pointed to data typesize
- the size of the pointer to be created or -1 for a default sized pointer- Returns:
- the pointer
-
getRootCategory
Category getRootCategory()Returns the root category Manager- Returns:
- the category
-
isFavorite
Returns true if the given datatype has been designated as a favorite. If the datatype does not belong to this datatype manager, then false will be returned.- Parameters:
datatype
- the datatype to check.- Returns:
- true if the given datatype is a favorite in this manager.
-
setFavorite
Sets the given dataType to be either a favorite or not a favorite.- Parameters:
datatype
- the datatype for which to change its status as a favorite.isFavorite
- true if the datatype is to be a favorite or false otherwise.- Throws:
IllegalArgumentException
- if the given datatype does not belong to this manager.
-
getFavorites
Returns a list of datatypes that have been designated as favorites.- Returns:
- the list of favorite datatypes in this manager.
-
getCategoryCount
int getCategoryCount()Returns the total number of data type categories- Returns:
- the count
-
getDataTypeCount
int getDataTypeCount(boolean includePointersAndArrays) Returns the total number of defined data types.- Parameters:
includePointersAndArrays
- if true all pointers and array data types will be included- Returns:
- the count
-
findEnumValueNames
Adds all enum value names that match the given value, to the given set.- Parameters:
value
- the value to look for enum name matchesenumValueNames
- the set to add matches to.
-
getDataType
Finds the data type using the given source archive and id.- Parameters:
sourceArchive
- the optional source archive; required when the type is associated with that source archivedatatypeID
- the type's id- Returns:
- the type or null
-
findDataTypeForID
Get's the data type with the matching universal data type id.- Parameters:
datatypeID
- The universal id of the data type to search for- Returns:
- The data type with the matching UUID, or null if no such data type can be found.
-
getLastChangeTimeForMyManager
long getLastChangeTimeForMyManager()Returns the timestamp of the last time this manager was changed- Returns:
- the timestamp
-
getSourceArchive
Returns the source archive for the given ID- Parameters:
sourceID
- the ID- Returns:
- the archive; null if the ID is null; null if the archive does not exist
-
getType
ArchiveType getType()Returns this manager's archive type- Returns:
- the type
-
getDataTypes
Returns all data types within this manager that have as their source the given archive- Parameters:
sourceArchive
- the archive- Returns:
- the types
-
getLocalSourceArchive
SourceArchive getLocalSourceArchive()Returns the source archive for this manager- Returns:
- the archive; null if the ID is null; null if the archive does not exist
-
associateDataTypeWithArchive
Change the given data type and its dependencies so thier source archive is set to given archive. Only those data types not already associated with a source archive will be changed.- Parameters:
datatype
- the typearchive
- the archive
-
disassociate
If the indicated data type is associated with a source archive, this will remove the association and the data type will become local to this data type manager.- Parameters:
datatype
- the data type to be disassociated from a source archive.
-
updateSourceArchiveName
Updates the name associated with a source archive in this data type manager.- Parameters:
archiveFileID
- Universal domain file ID of the source data type archive that has a new name.name
- the new name of the program or archive.- Returns:
- true if the name associated with the source data type archive was changed. false if it wasn't changed.
-
updateSourceArchiveName
Updates the name associated with a source archive in this data type manager.- Parameters:
sourceID
- Universal archive ID of the source data type archive that has a new name.name
- the new name of the program or archive.- Returns:
- true if the name associated with the source data type archive was changed. false if it wasn't changed.
-
getDataOrganization
DataOrganization getDataOrganization()Get the data organization associated with this data type manager. Note that the DataOrganization settings may not be changed dynamically.- Returns:
- data organization (will never be null)
-
getAddressMap
AddressMap getAddressMap()Returns the associated AddressMap used by this datatype manager.- Returns:
- the AddressMap used by this datatype manager or null if one has not be established.
-
getSourceArchives
List<SourceArchive> getSourceArchives()Returns a list of source archives not including the builtin or the program's archive.- Returns:
- a list of source archives not including the builtin or the program's archive.
-
removeSourceArchive
Removes the source archive from this manager. This will disassociate all data types in this manager from the given archive.- Parameters:
sourceArchive
- the archive
-
resolveSourceArchive
Returns or creates a persisted version of the given source archive- Parameters:
sourceArchive
- the archive- Returns:
- the archive
-
getDataTypesContaining
Deprecated.the methodDataType.getParents()
should be used instead. Use ofSet
implementations for containing DataTypes is also inefficient.Returns the data types within this data type manager that contain the specified data type. The specified dataType must belong to this datatype manager. An empty set will be returned for unsupported datatype instances.- Parameters:
dataType
- the data type- Returns:
- a set of data types that contain the specified data type.
-
allowsDefaultBuiltInSettings
boolean allowsDefaultBuiltInSettings()Determine if settings are supported for BuiltIn datatypes within this datatype manager.- Returns:
- true if BuiltIn Settings are permitted
-
allowsDefaultComponentSettings
boolean allowsDefaultComponentSettings()Determine if settings are supported for datatype components within this datatype manager (i.e., for structure and union components).- Returns:
- true if BuiltIn Settings are permitted
-
getKnownCallingConventionNames
Collection<String> getKnownCallingConventionNames()Get the ordered list of known calling convention names. The reserved names "unknown" and "default" are not included. The returned collection will include all names ever used or resolved by associatedFunction
andFunctionDefinition
objects, even if not currently defined by the associatedCompilerSpec
orProgram
SpecExtension
. To get only those calling conventions formally defined, the methodCompilerSpec.getCallingConventions()
should be used.- Returns:
- all known calling convention names.
-
getDefinedCallingConventionNames
Collection<String> getDefinedCallingConventionNames()Get the ordered list of defined calling convention names. The reserved names "unknown" and "default" are not included. The returned collection may not include all names referenced by various functions and function-definitions. This set is generally limited to those defined by the associated compiler specification. If this instance does not have an assigned architecture theGenericCallingConvention
names will be returned.For a set of all known names (including those that are not defined by compiler spec) see
getKnownCallingConventionNames()
.- Returns:
- the set of defined calling convention names.
-
getDefaultCallingConvention
PrototypeModel getDefaultCallingConvention()Get the default calling convention's prototype model in this datatype manager if known.- Returns:
- the default calling convention prototype model or null.
-
getCallingConvention
Get the prototype model of the calling convention with the specified name from the associated compiler specification. If an architecture has not been established this method will return null. IfFunction.DEFAULT_CALLING_CONVENTION_STRING
is specifiedgetDefaultCallingConvention()
will be returned.- Parameters:
name
- the calling convention name- Returns:
- the named function calling convention prototype model or null.
-
getDataType(String)
or better yetgetDataType(DataTypePath)