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 Details

  • Method Details

    • init

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

      public DataTypeManager getDTM()
    • allTypes

      public List<GoType> allTypes()
    • allTypeOffsets

      public List<Long> allTypeOffsets()
    • findGoType

      public GoType findGoType(String typeName)
      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
    • findGoType

      public GoType findGoType(GoSymbolName name)
    • findGoType

      public GoType findGoType(GoSymbolName name, String defaultTypeName)
    • findGoType

      public GoType findGoType(String typeName, String defaultTypeName)
    • getClosureTypes

      public List<GoType> getClosureTypes()
    • getMethodWrapperClosureTypes

      public List<GoType> getMethodWrapperClosureTypes()
    • getType

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

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

      public GoType getType(Address addr) throws IOException
      Returns a specialized GoType for the type that is located at the specified location.
      Parameters:
      addr - location of a go type
      Returns:
      specialized GoType (example, GoStructType, GoArrayType, etc)
      Throws:
      IOException - if error reading
    • getTypeUnchecked

      public GoType getTypeUnchecked(Address addr)
    • getMapGoType

      public GoType getMapGoType()
      Returns the go type that represents a golang built-in map RTTI type struct.
      Returns:
      golang map data type
    • getMapArgGoType

      public GoType getMapArgGoType()
      Returns the go type that represents a generic map argument value.
      Returns:
      GoType
    • getChanGoType

      public GoType getChanGoType()
      Returns the go type that represents the built-in golang channel RTTI type struct.
      Returns:
      golang channel type
    • getChanArgGoType

      public GoType getChanArgGoType()
      Returns the go type that represents a generic chan argument value.
      Returns:
      golang type for chan args
    • getUint8DT

      public DataType getUint8DT()
    • getUintDT

      public DataType getUintDT()
    • getUintptrDT

      public DataType getUintptrDT()
      Returns the data type that represents a golang uintptr
      Returns:
      golang uinptr data type
    • getInt32DT

      public DataType getInt32DT()
      Returns the data type that represents a golang int32
      Returns:
      golang int32 data type
    • getUint32DT

      public DataType getUint32DT()
      Returns the data type that represents a golang uint32
      Returns:
      golang uint32 data type
    • getVoidPtrDT

      public DataType getVoidPtrDT()
    • getTypeName

      public String getTypeName(long offset)
      Returns the name of a gotype.
      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 a list of interfaces that the specified type has implemented.
      Parameters:
      type - GoType
      Returns:
      list of itabs that map a GoType to the interfaces it was found to implement
    • 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 golang 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 - golang type
      dt - Ghidra type
      Throws:
      IOException - if golang type struct is not a valid struct mapped instance
    • getGhidraDataType

      public DataType getGhidraDataType(GoType typ) throws IOException
      Returns a Ghidra data type that represents the golang 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 golang type struct is not a valid struct mapped instance
    • getGhidraDataType

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

      public <T extends DataType> T getGhidraDataType(String goTypeName, Class<T> clazz) throws IOException
      Throws:
      IOException
    • getCP

      public CategoryPath getCP()
    • getCP

      public CategoryPath getCP(GoType typ)
      Returns category path that should be used to place recovered golang types.
      Parameters:
      typ - GoType
      Returns:
      CategoryPath to use when creating recovered golang types
    • getCP

      public CategoryPath getCP(GoSymbolName symbolName)
      Returns category path that should be used to place recovered golang types.
      Parameters:
      symbolName - GoSymbolName to convert to a category path
      Returns:
      CategoryPath to use when creating recovered golang types
    • getGenericSliceDT

      public Structure getGenericSliceDT()
      Returns the data type that represents a generic golang slice.
      Returns:
      golang generic slice data type
    • 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()
    • getDefaultMethodWrapperClosureType

      public Structure getDefaultMethodWrapperClosureType()
    • getFuncMultiReturn

      public Structure getFuncMultiReturn(List<DataType> returnTypes)
    • getSubstitutionType

      public GoType getSubstitutionType(String typeName)
    • getMissingGoTypes

      public Set<String> getMissingGoTypes()