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 the 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
    • 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 its
      Returns:
      name with without conflict patterns
    • 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.
    • 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.
    • 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.