Package ghidra.app.util.bin.format.golang.rtti

# Class GoTypeManager

java.lang.Object
ghidra.app.util.bin.format.golang.rtti.GoTypeManager

public class GoTypeManager extends Object
Manages all Go RTTI type info, along with their Ghidra data type equivs.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GoTypeManager(GoRttiMapper goBinary, GoApiSnapshot apiSnapshot)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<Long>`
  `allTypeOffsets()`
  `List<GoType>`
  `allTypes()`
  `void`
  `cacheRecoveredDataType(GoType typ, DataType dt)`
  Inserts a mapping between a `Go type` and a `ghidra data type`.
  `FunctionDefinitionDataType`
  `createFuncDef(List<ParameterDefinition> params, DataType returnDT, GoSymbolName symbolName, boolean noReturn)`
  `FunctionDefinitionDataType`
  `createFuncDef(List<ParameterDefinition> params, List<ParameterDefinition> returnParams, GoSymbolName symbolName, boolean noReturn)`
  `DataType`
  `createSpecializedMapDT(String mapTypeName)`
  `Structure`
  `createSpecializedSlice(GoSymbolName sliceTypeName, DataType element)`
  `DataType`
  `findDataType(GoSymbolName typeName)`
  Finds a Ghidra data type by its go-type name.
  `<T extends DataType>
  T`
  `findDataType(GoSymbolName typeName, Class<T> clazz)`
  Finds a Ghidra data type by its go-type name.
  `DataType`
  `findDataType(String typeName)`
  Finds a Ghidra data type by its go-type name.
  `<T extends DataType>
  T`
  `findDataType(String typeName, Class<T> clazz)`
  Finds a Ghidra data type by its go-type name.
  `GoType`
  `findGoType(String typeName)`
  Finds a Go type by its go-type name, from the list of discovered Go types.
  `List<GoType>`
  `getClosureTypes()`
  `CategoryPath`
  `getCP()`
  `CategoryPath`
  `getCP(GoSymbolName symbolName)`
  Returns `CategoryPath` that should be used to place recovered Go types.
  `CategoryPath`
  `getCP(GoType typ)`
  Returns category path that should be used to place recovered Go types.
  `DataType`
  `getDataType(GoType typ)`
  Returns a `Ghidra data type` that represents the `Go type`, using a cache of already recovered types to eliminate extra work and self recursion.
  `<T extends DataType>
  T`
  `getDataType(GoType typ, Class<T> clazz, boolean cacheOnly)`
  `DataType`
  `getDataType(String typeName)`
  Returns a Ghidra data type by its go-type name.
  `DataType`
  `getDefaultClosureType()`
  `Structure`
  `getDefaultMethodWrapperClosureType()`
  `DataTypeManager`
  `getDTM()`
  `Structure`
  `getFuncMultiReturn(List<DataType> returnTypes)`
  `DataType`
  `getGenericDictDT()`
  `Structure`
  `getGenericInterfaceDT()`
  `Structure`
  `getGenericITabDT()`
  `Structure`
  `getGenericSliceDT()`
  Returns data type that represents a generic Go slice.
  `List<GoItab>`
  `getInterfacesImplementedByType(GoType type)`
  Returns list of interfaces that the specified type has implemented.
  `DataType`
  `getMethodClosureType(String recvType)`
  `List<GoType>`
  `getMethodWrapperClosureTypes()`
  `Set<String>`
  `getMissingGoTypes()`
  `int`
  `getPtrSize()`
  `GoType`
  `getSubstitutionType(String typeName)`
  `GoType`
  `getType(long offset)`
  Returns `GoType` for the specified offset (example: GoStructType, GoArrayType, etc).
  `GoType`
  `getType(long offset, boolean cacheOnly)`
  `String`
  `getTypeName(long offset)`
  Returns string name, with a fallback if the specified offset was invalid.
  `String`
  `getTypeName(GoType type)`
  `List<GoItab>`
  `getTypesThatImplementInterface(GoInterfaceType iface)`
  `GoType`
  `getTypeUnchecked(Address addr)`
  `DataType`
  `getVoidPtrDT()`
  `boolean`
  `hasGoType(String typeName)`
  `void`
  `init(TaskMonitor monitor)`
  Discovers available Go types
  `void`
  `markupGoTypes(MarkupSession markupSession, TaskMonitor monitor)`
  `void`
  `recoverGhidraDataTypes(TaskMonitor monitor)`
  `DataType`
  `recoverPlainDataType(GoKind kind)`
  `GoType`
  `resolveTypeOff(long ptrInModule, long off)`
  Returns the `GoType` corresponding to an offset that is relative to the controlling GoModuledata's typesOffset.

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

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

- ## Constructor Details

  - ### GoTypeManager

    public GoTypeManager(GoRttiMapper goBinary, GoApiSnapshot apiSnapshot)

- ## Method Details

  - ### init

    public void init(TaskMonitor monitor) throws IOException
    Discovers available Go types
    Parameters:
      `monitor` - `TaskMonitor`
    Throws:
      `IOException` - if error reading data or cancelled

  - ### markupGoTypes

    public void markupGoTypes(MarkupSession markupSession, TaskMonitor monitor) throws CancelledException, IOException
    Throws:
      `CancelledException`
      `IOException`

  - ### getDTM

    public DataTypeManager getDTM()

  - ### getPtrSize

    public int getPtrSize()

  - ### allTypes

    public List<GoType> allTypes()

  - ### allTypeOffsets

    public List<Long> allTypeOffsets()

  - ### hasGoType

    public boolean hasGoType(String typeName)

  - ### findGoType

    public GoType findGoType(String typeName) throws IOException
    Finds a Go type by its go-type name, from the list of discovered Go types.
    Parameters:
      `typeName` - name string
    Returns:
      `GoType`, or `NULL` if not found
    Throws:
      `IOException` - if error

  - ### findDataType

    public DataType findDataType(GoSymbolName typeName) throws IOException
    Finds a Ghidra data type by its go-type name.
    Parameters:
      `typeName` - go type name
    Returns:
      Ghidra `DataType` corresponding to the requested name, coerced into a specific `DataType` subclass, or `NULL` if not found
    Throws:
      `IOException` - if error

  - ### findDataType

    public <T extends DataType> T findDataType(GoSymbolName typeName, Class<T> clazz) throws IOException
    Finds a Ghidra data type by its go-type name.
    Type Parameters:
      `T` - Ghidra DataType generic type specifier
    Parameters:
      `typeName` - go type name
      `clazz` - `DataType` class reference
    Returns:
      Ghidra `DataType` corresponding to the requested name, coerced into a specific `DataType` subclass, or `NULL` if not found
    Throws:
      `IOException` - if error

  - ### findDataType

    public DataType findDataType(String typeName) throws IOException
    Finds a Ghidra data type by its go-type name.
    Parameters:
      `typeName` - go type name
    Returns:
      Ghidra `DataType` corresponding to the requested name, or `NULL` if not found
    Throws:
      `IOException` - if error

  - ### findDataType

    public <T extends DataType> T findDataType(String typeName, Class<T> clazz) throws IOException
    Finds a Ghidra data type by its go-type name.
    Type Parameters:
      `T` - Ghidra DataType generic type specifier
    Parameters:
      `typeName` - go type name
      `clazz` - `DataType` class reference
    Returns:
      Ghidra `DataType` corresponding to the requested name, coerced into a specific `DataType` subclass, or `NULL` if not found
    Throws:
      `IOException` - if error

  - ### getDataType

    public DataType getDataType(String typeName) throws IOException
    Returns a Ghidra data type by its go-type name.
    Parameters:
      `typeName` - go type name
    Returns:
      Ghidra `DataType` corresponding to the requested name, never `NULL`
    Throws:
      `IOException` - if error or not found

  - ### getClosureTypes

    public List<GoType> getClosureTypes()

  - ### getMethodWrapperClosureTypes

    public List<GoType> getMethodWrapperClosureTypes()

  - ### getType

    public GoType getType(long offset) throws IOException
    Returns `GoType` for the specified offset (example: GoStructType, GoArrayType, etc).
    Parameters:
      `offset` - absolute position of a Go type
    Returns:
      `GoType` for the specified offset (example: GoStructType, GoArrayType, etc)
    Throws:
      `IOException` - if error reading

  - ### getType

    public GoType getType(long offset, boolean cacheOnly) throws IOException
    Throws:
      `IOException`

  - ### getTypeUnchecked

    public GoType getTypeUnchecked(Address addr)

  - ### getVoidPtrDT

    public DataType getVoidPtrDT()

  - ### getTypeName

    public String getTypeName(long offset)
    Returns string name, with a fallback if the specified offset was invalid.
    Parameters:
      `offset` - offset of the gotype RTTI record
    Returns:
      string name, with a fallback if the specified offset was invalid

  - ### getTypeName

    public String getTypeName(GoType type)

  - ### getInterfacesImplementedByType

    public List<GoItab> getInterfacesImplementedByType(GoType type)
    Returns list of interfaces that the specified type has implemented.
    Parameters:
      `type` - GoType
    Returns:
      list of interfaces that the specified type has implemented

  - ### getTypesThatImplementInterface

    public List<GoItab> getTypesThatImplementInterface(GoInterfaceType iface)

  - ### resolveTypeOff

    public GoType resolveTypeOff(long ptrInModule, long off) throws IOException
    Returns the `GoType` corresponding to an offset that is relative to the controlling GoModuledata's typesOffset.
    Parameters:
      `ptrInModule` - the address of the structure that contains the offset that needs to be calculated. The containing-structure's address is important because it indicates which GoModuledata is the 'parent'
      `off` - offset
    Returns:
      `GoType`, or `NULL` if offset is special value 0 or -1
    Throws:
      `IOException` - if error

  - ### cacheRecoveredDataType

    public void cacheRecoveredDataType(GoType typ, DataType dt) throws IOException
    Inserts a mapping between a `Go type` and a `ghidra data type`.

    Useful to prepopulate the data type mapping before recursing into contained/referenced types that might be self-referencing.

    Parameters:
      `typ` - `Go type`
      `dt` - `Ghidra type`
    Throws:
      `IOException` - if Go type struct is not a valid struct mapped instance

  - ### recoverGhidraDataTypes

    public void recoverGhidraDataTypes(TaskMonitor monitor) throws IOException, CancelledException
    Throws:
      `IOException`
      `CancelledException`

  - ### recoverPlainDataType

    public DataType recoverPlainDataType(GoKind kind)

  - ### getDataType

    public DataType getDataType(GoType typ) throws IOException
    Returns a `Ghidra data type` that represents the `Go type`, using a cache of already recovered types to eliminate extra work and self recursion.
    Parameters:
      `typ` - the `GoType` to convert
    Returns:
      Ghidra `DataType`
    Throws:
      `IOException` - if Go type struct is not a valid struct mapped instance

  - ### getDataType

    public <T extends DataType> T getDataType(GoType typ, Class<T> clazz, boolean cacheOnly) throws IOException
    Throws:
      `IOException`

  - ### getCP

    public CategoryPath getCP()

  - ### getCP

    public CategoryPath getCP(GoType typ)
    Returns category path that should be used to place recovered Go types.
    Parameters:
      `typ` - `GoType`
    Returns:
      category path that should be used to place recovered Go types

  - ### getCP

    public CategoryPath getCP(GoSymbolName symbolName)
    Returns `CategoryPath` that should be used to place recovered Go types.
    Parameters:
      `symbolName` - `GoSymbolName` to convert to a category path
    Returns:
      `CategoryPath` that should be used to place recovered Go types

  - ### createSpecializedMapDT

    public DataType createSpecializedMapDT(String mapTypeName)

  - ### getGenericSliceDT

    public Structure getGenericSliceDT() throws IllegalArgumentException, IOException
    Returns data type that represents a generic Go slice.
    Returns:
      data type that represents a generic Go slice
    Throws:
      `IOException`
      `IllegalArgumentException`

  - ### createSpecializedSlice

    public Structure createSpecializedSlice(GoSymbolName sliceTypeName, DataType element) throws IllegalArgumentException, IOException
    Throws:
      `IllegalArgumentException`
      `IOException`

  - ### getGenericDictDT

    public DataType getGenericDictDT()

  - ### getGenericInterfaceDT

    public Structure getGenericInterfaceDT()

  - ### getGenericITabDT

    public Structure getGenericITabDT()

  - ### getMethodClosureType

    public DataType getMethodClosureType(String recvType) throws IOException
    Throws:
      `IOException`

  - ### getDefaultClosureType

    public DataType getDefaultClosureType() throws IOException
    Throws:
      `IOException`

  - ### getDefaultMethodWrapperClosureType

    public Structure getDefaultMethodWrapperClosureType()

  - ### getFuncMultiReturn

    public Structure getFuncMultiReturn(List<DataType> returnTypes)

  - ### getSubstitutionType

    public GoType getSubstitutionType(String typeName) throws IOException
    Throws:
      `IOException`

  - ### getMissingGoTypes

    public Set<String> getMissingGoTypes()

  - ### createFuncDef

    public FunctionDefinitionDataType createFuncDef(List<ParameterDefinition> params, List<ParameterDefinition> returnParams, GoSymbolName symbolName, boolean noReturn)

  - ### createFuncDef

    public FunctionDefinitionDataType createFuncDef(List<ParameterDefinition> params, DataType returnDT, GoSymbolName symbolName, boolean noReturn)