Class DataTypeUtilities

java.lang.Object
ghidra.program.database.data.DataTypeUtilities

public class DataTypeUtilities extends Object
  • Constructor Details

    • DataTypeUtilities

      public DataTypeUtilities()
  • Method Details

    • getContainedDataTypes

      public static Collection<DataType> getContainedDataTypes(DataType rootDataType)
    • isSecondPartOfFirst

      public static 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.
      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

      public static boolean isSameDataType(DataType dataType1, DataType dataType2)
      Returns true if the two dataTypes have the same sourceArchive and the same UniversalID
      Parameters:
      dataType1 - first data type
      dataType2 - second data type
      Returns:
      true if types correspond to the same type from a source archive
    • isSameOrEquivalentDataType

      public static boolean isSameOrEquivalentDataType(DataType dataType1, DataType dataType2)
      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

      public static boolean isSameKindDataType(DataType dataType1, DataType dataType2)
      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 of BuiltInDataType must match the specific implementation class.
      Parameters:
      dataType1 - first data type
      dataType2 - second data type
      Returns:
      true if the two dataTypes are the same basic kind else false
    • getBaseDataType

      public static DataType getBaseDataType(DataType dt)
      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

      public static DataType getArrayBaseDataType(Array arrayDt)
    • getName

      public static String getName(Array arrayDt, boolean showBaseSizeForDynamics)
    • getDisplayName

      public static String getDisplayName(Array arrayDt, boolean showBaseSizeForDynamics)
    • getMnemonic

      public static String getMnemonic(Array arrayDt, boolean showBaseSizeForDynamics, Settings settings)
    • getDataTypeCategoryPath

      public static CategoryPath getDataTypeCategoryPath(CategoryPath baseCategory, Namespace namespace)
      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 path
      namespace - 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 manager
      namespace - namespace associated with dtName (null indicates no namespace constraint)
      dtName - name of data type
      classConstraint - 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 (see SymbolPathParser.parse(String)).
      Parameters:
      dataTypeManager - data type manager
      dtNameWithNamespace - 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

      public static DataType getCPrimitiveDataType(String dataTypeName)
      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

      public static String getNameWithoutConflict(DataType dataType, boolean includeCategoryPath)
      Get the name of a data type with all conflict naming patterns removed.
      Parameters:
      dataType - data type
      includeCategoryPath - 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

      public static String getNameWithoutConflict(String dataTypeName)
      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

      public static String getNameWithoutConflict(DataType dt)
      Get a datatype's name without conflict suffix.
      Parameters:
      dt - datatype (pointer and array permitted)
      Returns:
      datatype's name without conflict suffix
    • getConflictValue

      public static int getConflictValue(DataType dataType)
      Get the conflict value string associated with a conflict datatype name.
      Parameters:
      dataType - datatype to be checked
      Returns:
      conflict value:
      1. -1: when type does not have a conflict name,
      2. 0: when conflict name does not have a number (i.e., .conflict), or
      3. a positive value which corresponds to the conflict number in the name (e.g., returns 2 for .conflict2).
    • getConflictValue

      public static int getConflictValue(String dataTypeName)
      Get the conflict value associated with a conflict datatype name.
      Parameters:
      dataTypeName - datatype name to be checked
      Returns:
      conflict value:
      1. -1: when name is not have a conflict name,
      2. 0: when conflict name does not have a number (i.e., .conflict), or
      3. a positive value which corresponds to the conflict number in the name (e.g., returns 2 for .conflict2).
    • isConflictDataTypeName

      public static boolean isConflictDataTypeName(String dataTypeName)
      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

      public static boolean isConflictDataType(DataType dt)
      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

      public static boolean equalsIgnoreConflict(String name1, String name2)
      Compares two data type name strings to determine if they are equivalent names, ignoring conflict patterns present.
      Parameters:
      name1 - the first name
      name2 - the second name
      Returns:
      true if the names are equivalent when conflict suffixes are ignored.