Class GoRttiMapper
java.lang.Object
ghidra.app.util.bin.format.golang.structmapping.DataTypeMapper
ghidra.app.util.bin.format.golang.rtti.GoRttiMapper
- All Implemented Interfaces:
AutoCloseable
DataTypeMapper for golang binaries.
When bootstrapping golang binaries, the following steps are used:
- Find the GoBuildInfo struct. This struct is the easiest to locate, even when the binary is stripped. This gives us the go pointerSize (probably same as ghidra pointer size) and the goVersion. This struct does not rely on StructureMapping, allowing its use before a DataTypeMapper is created.
- Create DataTypeMapper
- Find the runtime.firstmoduledata structure.
- If there are symbols, just use the symbol or named memory block.
- If stripped:
- Find the pclntab. This has a magic signature, a pointerSize, and references to a couple of tables that are also referenced in the moduledata structure.
- Search memory for a pointer to the pclntab struct. This should be the first field of the moduledata structure. The values that are duplicated between the two structures can be compared to ensure validity.
- Different binary formats (Elf vs PE) will determine which memory blocks to search.
-
Field Summary
Fields inherited from class ghidra.app.util.bin.format.golang.structmapping.DataTypeMapper
archiveDTM, archiveSearchCPs, mappingInfo, markedupStructs, markupTaskMonitor, program, programDTM, programSearchCPs -
Constructor Summary
ConstructorsConstructorDescriptionGoRttiMapper(Program program, int ptrSize, Endian endian, GoVer goVersion, ResourceFile archiveGDT) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddModule(GoModuledata module) voidcacheRecoveredDataType(GoType typ, DataType dt) protected BinaryReadervoiddiscoverGoTypes(TaskMonitor monitor) voidexportTypesToGDT(File gdtFile, TaskMonitor monitor) Export the currently registered struct mapping types to a gdt file.findContainingModule(long offset) findContainingModuleByFuncData(long offset) static ResourceFilefindGolangBootstrapGDT(GoVer goVer, int ptrSize, String osName) Searches for a golang bootstrap gdt file that matches the specified Go version/size/OS.findGoType(String typeName) static StringgetGDTFilename(GoVer goVer, int pointerSizeInBytes, String osName) <T extends DataType>
TgetGhidraDataType(String goTypeName, Class<T> clazz) static StringgetGolangOSString(Program program) getGoName(long offset) getGoType(long offset) static GoRttiMappergetMapperFor(Program program, MessageLog log) Returns a newGoRttiMapperfor the specified program, or null if the binary is not a supported golang binary.intgetRecoveredType(GoType typ) voidrecoverDataTypes(TaskMonitor monitor) Converts all discovered golang rtti type records to Ghidra data types, placing them in the program's DTM in /golang-recoveredresolveNameOff(long ptrInModule, long off) resolveTextOff(long ptrInModule, long off) resolveTypeOff(long ptrInModule, long off) Methods inherited from class ghidra.app.util.bin.format.golang.structmapping.DataTypeMapper
addArchiveSearchCategoryPath, addProgramSearchCategoryPath, close, findType, getCodeAddress, getDataAddress, getDataConverter, getDTM, getExistingStructureAddress, getExistingStructureContext, getProgram, getReader, getStructureDataType, getStructureDataTypeName, getStructureMappingInfo, getStructureMappingInfo, getType, getTypeOrDefault, labelAddress, labelStructure, markup, markupAddress, markupAddress, markupAddressIfUndefined, readStructure, readStructure, readStructure, registerStructure, registerStructures, setMarkupTaskMonitor, toString
-
Constructor Details
-
GoRttiMapper
public GoRttiMapper(Program program, int ptrSize, Endian endian, GoVer goVersion, ResourceFile archiveGDT) throws IOException - Throws:
IOException
-
-
Method Details
-
getMapperFor
Returns a newGoRttiMapperfor the specified program, or null if the binary is not a supported golang binary.- Parameters:
program-Programlog-- Returns:
- new
GoRttiMapper, or null if not a golang binary - Throws:
IOException
-
getGDTFilename
-
getGolangOSString
-
findGolangBootstrapGDT
Searches for a golang bootstrap gdt file that matches the specified Go version/size/OS.First looks for a gdt with an exact match, then for a gdt with version/size match and "any" OS, and finally, a gdt that matches the version and "any" size and "any" OS.
- Parameters:
goVer- version of GoptrSize- size of pointersosName- name of OS- Returns:
-
getGolangVersion
-
getFirstModule
-
addModule
-
findContainingModule
-
findContainingModuleByFuncData
-
getDefaultVariableLengthStructCategoryPath
- Overrides:
getDefaultVariableLengthStructCategoryPathin classDataTypeMapper
-
getUintptrDT
-
getInt32DT
-
getUint32DT
-
getGenericSliceDT
-
getMapGoType
-
getChanGoType
-
createProgramReader
- Overrides:
createProgramReaderin classDataTypeMapper
-
getPtrSize
public int getPtrSize() -
resolveNameOff
- Throws:
IOException
-
getGoName
- Throws:
IOException
-
resolveTypeOff
- Throws:
IOException
-
getGoType
- Throws:
IOException
-
getGoType
- Throws:
IOException
-
findGoType
-
getGhidraDataType
-
resolveTextOff
-
exportTypesToGDT
Export the currently registered struct mapping types to a gdt file.The struct data types will either be from the current program's DWARF data, or from an earlier golang.gdt (if this binary doesn't have DWARF)
- Parameters:
gdtFile-- Throws:
IOException
-
getRecoveredTypesCp
-
getRecoveredType
- Throws:
IOException
-
cacheRecoveredDataType
- Throws:
IOException
-
getCachedRecoveredDataType
- Throws:
IOException
-
recoverDataTypes
Converts all discovered golang rtti type records to Ghidra data types, placing them in the program's DTM in /golang-recovered- Throws:
IOExceptionCancelledException
-
discoverGoTypes
- Throws:
IOExceptionCancelledException
-