Package ghidra.program.database.data
Class DataTypeUtilities
java.lang.Object
ghidra.program.database.data.DataTypeUtilities
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
equalsIgnoreConflict
(String name1, String name2) Compares two data type name strings to determine if they are equivalent names, ignoring conflict patterns present.static <T extends DataType>
TfindDataType
(DataTypeManager dataTypeManager, Namespace namespace, String dtName, Class<T> classConstraint) Attempt to find the data type whose dtName and specified namespace match a stored data type within the specified dataTypeManager.static Structure
findExistingClassStruct
(DataTypeManager dataTypeManager, GhidraClass classNamespace) Find the structure data type which corresponds to the specified class namespace within the specified data type manager.static <T extends DataType>
TfindNamespaceQualifiedDataType
(DataTypeManager dataTypeManager, String dtNameWithNamespace, Class<T> classConstraint) Attempt to find the data type whose dtNameWithNamespace match a stored data type within the specified dataTypeManager.static DataType
getArrayBaseDataType
(Array arrayDt) static DataType
Get the base data type for the specified data type stripping away pointers and arrays only.static int
getConflictValue
(DataType dataType) Get the conflict value string associated with a conflict datatype name.static int
getConflictValue
(String dataTypeName) Get the conflict value associated with a conflict datatype name.static Collection
<DataType> getContainedDataTypes
(DataType rootDataType) static DataType
getCPrimitiveDataType
(String dataTypeName) Return the appropriate datatype for a given C primitive datatype name.static CategoryPath
getDataTypeCategoryPath
(CategoryPath baseCategory, Namespace namespace) Create a data type category path derived from the specified namespace and rooted from the specified baseCategorystatic String
getDisplayName
(Array arrayDt, boolean showBaseSizeForDynamics) static String
getMnemonic
(Array arrayDt, boolean showBaseSizeForDynamics, Settings settings) static String
static String
Get a datatype's name without conflict suffix.static String
getNameWithoutConflict
(DataType dataType, boolean includeCategoryPath) Get the name of a data type with all conflict naming patterns removed.static String
getNameWithoutConflict
(String dataTypeName) Get the name of a data type with all conflict naming patterns removed.static boolean
Determine if the specified data type has a conflict name.static boolean
isConflictDataTypeName
(String dataTypeName) Determine if the specified data type name is a conflict name.static boolean
isSameDataType
(DataType dataType1, DataType dataType2) Returns true if the two dataTypes have the same sourceArchive and the same UniversalIDstatic boolean
isSameKindDataType
(DataType dataType1, DataType dataType2) Determine if two dataTypes are the same kind of datatype without considering naming or component makeup.static boolean
isSameOrEquivalentDataType
(DataType dataType1, DataType dataType2) Returns true if two dataTypes have the same sourceArchive and the same UniversalID OR are equivalentstatic boolean
isSecondPartOfFirst
(DataType firstDataType, DataType secondDataType) Check to see if the second data type is the same as the first data type or is part of it.
-
Constructor Details
-
DataTypeUtilities
public DataTypeUtilities()
-
-
Method Details
-
getContainedDataTypes
-
isSecondPartOfFirst
Check to see if the second data type is the same as the first data type or is part of it.
Note: pointers to the second data type are references and therefore are not considered to be part of the first and won't cause true to be returned. If you pass a pointer to this method for the first or second parameter, it will return false.- Parameters:
firstDataType
- the data type whose components or base type should be checked to see if the second data type is part of it.secondDataType
- the data type to be checked for in the first data type.- Returns:
- true if the second data type is the first data type or is part of it.
-
isSameDataType
Returns true if the two dataTypes have the same sourceArchive and the same UniversalID- Parameters:
dataType1
- first data typedataType2
- second data type- Returns:
- true if types correspond to the same type from a source archive
-
isSameOrEquivalentDataType
Returns true if two dataTypes have the same sourceArchive and the same UniversalID OR are equivalent- Parameters:
dataType1
- first data type (if invoked by DB object or manager, this argument must correspond to the DataTypeDB).dataType2
- second data type- Returns:
- true if types correspond to the same type from a source archive or they are equivelent, otherwise false
-
isSameKindDataType
Determine if two dataTypes are the same kind of datatype without considering naming or component makeup. The use of Typedefs is ignored and stripped away for comparison. This method also ignores details about most built-in types, pointers and arrays (e.g., number of elements or size). Implementations of the following abstract classes will be treated as the same kind as another datatype which extends the same abstract class: Other uses ofBuiltInDataType
must match the specific implementation class.- Parameters:
dataType1
- first data typedataType2
- second data type- Returns:
- true if the two dataTypes are the same basic kind else false
-
getBaseDataType
Get the base data type for the specified data type stripping away pointers and arrays only. A null will be returned for a default pointer.- Parameters:
dt
- the data type whose base data type is to be determined.- Returns:
- the base data type (may be null for default pointer).
-
getArrayBaseDataType
-
getName
-
getDisplayName
-
getMnemonic
-
getDataTypeCategoryPath
Create a data type category path derived from the specified namespace and rooted from the specified baseCategory- Parameters:
baseCategory
- category path from which to root the namespace-base pathnamespace
- the namespace- Returns:
- namespace derived category path
-
findExistingClassStruct
public static Structure findExistingClassStruct(DataTypeManager dataTypeManager, GhidraClass classNamespace) Find the structure data type which corresponds to the specified class namespace within the specified data type manager. The structure must utilize a namespace-based category path, however, the match criteria can be fuzzy and relies primarily on the full class namespace. A properly named class structure must reside within a category whose trailing path either matches the class namespace or the class-parent's namespace. Preference is given to it residing within the class-parent's namespace.- Parameters:
dataTypeManager
- data type manager which should be searched.classNamespace
- class namespace- Returns:
- existing structure which resides within matching category.
-
findDataType
public static <T extends DataType> T findDataType(DataTypeManager dataTypeManager, Namespace namespace, String dtName, Class<T> classConstraint) Attempt to find the data type whose dtName and specified namespace match a stored data type within the specified dataTypeManager. The first match which satisfies the category path requirement will be returned. If a non-root namespace is specified the datatype's trailing category path must match the specified namespace path.- Parameters:
dataTypeManager
- data type managernamespace
- namespace associated with dtName (null indicates no namespace constraint)dtName
- name of data typeclassConstraint
- optional data type interface constraint (e.g., Structure), or null- Returns:
- best matching data type
-
findNamespaceQualifiedDataType
public static <T extends DataType> T findNamespaceQualifiedDataType(DataTypeManager dataTypeManager, String dtNameWithNamespace, Class<T> classConstraint) Attempt to find the data type whose dtNameWithNamespace match a stored data type within the specified dataTypeManager. The namespace will be used in checking data type parent categories. NOTE: name parsing assumes :: namespace delimiter which can be thrown off if name includes template information which could contain namespaces (seeSymbolPathParser.parse(String)
).- Parameters:
dataTypeManager
- data type managerdtNameWithNamespace
- name of data type qualified with namespace (e.g., ns1::ns2::dtname)classConstraint
- optional data type interface constraint (e.g., Structure), or null- Returns:
- best matching data type
-
getCPrimitiveDataType
Return the appropriate datatype for a given C primitive datatype name.- Parameters:
dataTypeName
- the datatype name (e.g. "unsigned int", "long long")- Returns:
- the appropriate datatype for a given C primitive datatype name.
-
getNameWithoutConflict
Get the name of a data type with all conflict naming patterns removed.- Parameters:
dataType
- data typeincludeCategoryPath
- if true, the category path will be included with the returned name (e.g., /mypath/mydt) and any occurance of a forward slash within individual path components, including the data type name, will be escaped (e.g.,"\/"
).- Returns:
- name with optional category path included
-
getNameWithoutConflict
Get the name of a data type with all conflict naming patterns removed.- Parameters:
dataTypeName
- data type name with optional category path included- Returns:
- name with optional category path included
-
getNameWithoutConflict
Get a datatype's name without conflict suffix.- Parameters:
dt
- datatype (pointer and array permitted)- Returns:
- datatype's name without conflict suffix
-
getConflictValue
Get the conflict value string associated with a conflict datatype name.- Parameters:
dataType
- datatype to be checked- Returns:
- conflict value:
- -1: when type does not have a conflict name,
- 0: when conflict name does not have a number (i.e.,
.conflict
), or - a positive value which corresponds to the conflict number in the name
(e.g., returns 2 for
.conflict2
).
-
getConflictValue
Get the conflict value associated with a conflict datatype name.- Parameters:
dataTypeName
- datatype name to be checked- Returns:
- conflict value:
- -1: when name is not have a conflict name,
- 0: when conflict name does not have a number (i.e.,
.conflict
), or - a positive value which corresponds to the conflict number in the name
(e.g., returns 2 for
.conflict2
).
-
isConflictDataTypeName
Determine if the specified data type name is a conflict name.- Parameters:
dataTypeName
- datatype name- Returns:
- true if data type name is a conflict name.
-
isConflictDataType
Determine if the specified data type has a conflict name.- Parameters:
dt
- datatype (pointer and array permitted)- Returns:
- true if data type has a conflict name.
-
equalsIgnoreConflict
Compares two data type name strings to determine if they are equivalent names, ignoring conflict patterns present.- Parameters:
name1
- the first namename2
- the second name- Returns:
- true if the names are equivalent when conflict suffixes are ignored.
-