Package ghidra.app.util.bin.format.dwarf

# Class DWARFUtil

java.lang.Object
ghidra.app.util.bin.format.dwarf.DWARFUtil

public class DWARFUtil extends Object

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DWARFUtil()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `appendComment(Program program, Address address, CommentType commentType, String prefix, String comment, String sep)`
  `static void`
  `appendDescription(DataTypeComponent dtc, String description, String sep)`
  Append a string to a description of a field in a structure.
  `static void`
  `appendDescription(DataType dt, String description, String sep)`
  Append a string to a `DataType`'s description.
  `static List<Varnode>`
  `convertRegisterListToVarnodeStorage(List<Register> registers, int dataTypeSize)`
  `static List<String>`
  `findLinkageNameInChildren(DebugInfoEntry die)`
  Try to find gnu mangled name nesting info in a DIE's children's linkage strings.
  `static String`
  `getAnonNameForMeFromParentContext(DIEAggregate diea)`
  Creates a name for anon types based on their position in their parent's childList.
  `static String`
  `getAnonNameForMeFromParentContext2(DIEAggregate diea)`
  Creates a name for anon types based on the names of sibling entries that are using the anon type.
  `static CodeUnit`
  `getCodeUnitForComment(Program program, Address address)`
  `static ResourceFile`
  `getLanguageDefinitionDirectory(Language lang)`
  Returns the base directory of a language definition.
  `static ResourceFile`
  `getLanguageExternalFile(Language lang, String name)`
  Returns a file that has been referenced in the specified `language's` ldefs description via a
  `static String`
  `getLanguageExternalNameValue(Language lang, String name)`
  Returns a value specified in a `Language` definition via a
  `static Field`
  `getStaticFinalFieldWithValue(Class<?> clazz, long value)`
  Searches a Class for a final static variable that has a specific numeric value.
  `static String`
  `getStructLayoutFingerprint(DIEAggregate diea)`
  Creates a fingerprint of the layout of an (anonymous) structure using its size, number of members, and the hashcode of the member field names.
  `static String`
  `getTemplateBaseName(String name)`
  Determines if a name is a C++ style templated name.
  `static boolean`
  `isConstVarnode(Varnode varnode)`
  `static boolean`
  `isEmptyArray(DataType dt)`
  `static boolean`
  `isPointerDataType(DIEAggregate diea)`
  `static boolean`
  `isPointerTo(DIEAggregate targetDIEA, DIEAggregate testDIEA)`
  `static boolean`
  `isStackVarnode(Varnode varnode)`
  `static boolean`
  `isThisParam(DIEAggregate paramDIEA)`
  `static boolean`
  `isVoid(DataType dt)`
  `static boolean`
  `isZeroByteDataType(DataType dt)`
  `static void`
  `packCompositeIfPossible(Composite original, DataTypeManager dtm)`
  `static List<String>`
  `parseMangledNestings(String s)`
  A lightweight attempt to get nesting (ie.
  `static String`
  `toString(Class<?> clazz, int value)`
  Converts a integer value to its corresponding symbolic name from the set of "public static final" member variables in a class.
  `static String`
  `toString(Class<?> clazz, long value)`
  Returns the field name of a final static variable in class `clazz` which holds a specific value.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### DWARFUtil

    public DWARFUtil()

- ## Method Details

  - ### toString

    public static String toString(Class<?> clazz, int value)
    Converts a integer value to its corresponding symbolic name from the set of "public static final" member variables in a class.

    This is a bit of a hack and probably originated from pre-java Enum days.

    Parameters:
      `clazz` - The `Class` to search for the matching static value.
      `value` - the integer value to search for
    Returns:
      the String name of the matching field.

  - ### toString

    public static String toString(Class<?> clazz, long value)
    Returns the field name of a final static variable in class `clazz` which holds a specific value.

    Can be thought of as an enum numeric value to do a name lookup.

    Parameters:
      `clazz` -
      `value` -
    Returns:

  - ### getStaticFinalFieldWithValue

    public static Field getStaticFinalFieldWithValue(Class<?> clazz, long value)
    Searches a Class for a final static variable that has a specific numeric value.
    Parameters:
      `clazz` - Class to search.
      `value` - numeric value to search for
    Returns:
      Java reflection `Field` that has the specified value or null

  - ### parseMangledNestings

    public static List<String> parseMangledNestings(String s)
    A lightweight attempt to get nesting (ie. namespaces and such) information from gnu mangled name strings.

    For example, "_ZN19class1_inline_funcs3fooEv" -> [19 chars]'class1_inline_funcs', [3 chars]'foo'

    Parameters:
      `s` -
    Returns:

  - ### findLinkageNameInChildren

    public static List<String> findLinkageNameInChildren(DebugInfoEntry die)
    Try to find gnu mangled name nesting info in a DIE's children's linkage strings.
    Parameters:
      `die` -
    Returns:
      a list of string of nesting names, ending with what should be the DIE parameter's name.

  - ### getTemplateBaseName

    public static String getTemplateBaseName(String name)
    Determines if a name is a C++ style templated name. If so, returns just the base portion of the name. The name must have a start and end angle bracket: '<' and '>'.

    operator<() and operator<<() are handled so their angle brackets don't trigger the template start/end angle bracket incorrectly.

    Parameters:
      `name` - symbol name with C++ template portions
    Returns:
      base portion of the symbol name without template portion

  - ### getAnonNameForMeFromParentContext

    public static String getAnonNameForMeFromParentContext(DIEAggregate diea)
    Creates a name for anon types based on their position in their parent's childList.
    Parameters:
      `diea` - the die aggregate.
    Returns:
      the anonymous name of the die aggregate.

  - ### getAnonNameForMeFromParentContext2

    public static String getAnonNameForMeFromParentContext2(DIEAggregate diea)
    Creates a name for anon types based on the names of sibling entries that are using the anon type.

    Example: "anon_struct_for_field1_field2"

    Falls back to `getAnonNameForMeFromParentContext(DIEAggregate)` if no siblings found.

    Parameters:
      `diea` - the die aggregate.
    Returns:
      the anonymous name of the die aggregate.

  - ### getStructLayoutFingerprint

    public static String getStructLayoutFingerprint(DIEAggregate diea)
    Creates a fingerprint of the layout of an (anonymous) structure using its size, number of members, and the hashcode of the member field names.
    Parameters:
      `diea` - struct/union/class
    Returns:
      formatted string, example "80_5_73dc6de9" (80 bytes, 5 fields, hex hash of field names)

  - ### appendDescription

    public static void appendDescription(DataType dt, String description, String sep)
    Append a string to a `DataType`'s description.
    Parameters:
      `dt` - `DataType`
      `description` - string to append, if null or empty nothing happens.
      `sep` - characters to place after previous description to separate it from the new portion.

  - ### appendDescription

    public static void appendDescription(DataTypeComponent dtc, String description, String sep)
    Append a string to a description of a field in a structure.
    Parameters:
      `dtc` - the `field` in a struct
      `description` - string to append, if null or empty nothing happens.
      `sep` - characters to place after previous description to separate it from the new portion.

  - ### appendComment

    public static void appendComment(Program program, Address address, CommentType commentType, String prefix, String comment, String sep)

  - ### getCodeUnitForComment

    public static CodeUnit getCodeUnitForComment(Program program, Address address)

  - ### isThisParam

    public static boolean isThisParam(DIEAggregate paramDIEA)

  - ### isPointerTo

    public static boolean isPointerTo(DIEAggregate targetDIEA, DIEAggregate testDIEA)

  - ### isPointerDataType

    public static boolean isPointerDataType(DIEAggregate diea)

  - ### getLanguageExternalFile

    public static ResourceFile getLanguageExternalFile(Language lang, String name) throws IOException
    Returns a file that has been referenced in the specified `language's` ldefs description via a

        <external_name tool="name" name="value"/>

    entry.
    Parameters:
      `lang` - `Language` to query
      `name` - name of the option in the ldefs file
    Returns:
      file pointed to by the specified external_name tool entry
    Throws:
      `IOException` - if not a sleigh lang

  - ### getLanguageDefinitionDirectory

    public static ResourceFile getLanguageDefinitionDirectory(Language lang) throws IOException
    Returns the base directory of a language definition.
    Parameters:
      `lang` - `Language` to get base definition directory
    Returns:
      base directory for language definition files
    Throws:
      `IOException` - if not a sleigh lang

  - ### getLanguageExternalNameValue

    public static String getLanguageExternalNameValue(Language lang, String name) throws IOException
    Returns a value specified in a `Language` definition via a

        <external_name tool="name" name="value"/>

    entry.
    Parameters:
      `lang` - `Language` to query
      `name` - name of the value
    Returns:
      String value
    Throws:
      `IOException` - if invalid language or multiple values with same name

  - ### packCompositeIfPossible

    public static void packCompositeIfPossible(Composite original, DataTypeManager dtm)

  - ### convertRegisterListToVarnodeStorage

    public static List<Varnode> convertRegisterListToVarnodeStorage(List<Register> registers, int dataTypeSize)

  - ### isEmptyArray

    public static boolean isEmptyArray(DataType dt)

  - ### isZeroByteDataType

    public static boolean isZeroByteDataType(DataType dt)

  - ### isVoid

    public static boolean isVoid(DataType dt)

  - ### isStackVarnode

    public static boolean isStackVarnode(Varnode varnode)

  - ### isConstVarnode

    public static boolean isConstVarnode(Varnode varnode)