Class GoRttiMapper
java.lang.Object
ghidra.app.util.bin.format.golang.structmapping.DataTypeMapper
ghidra.app.util.bin.format.golang.rtti.GoRttiMapper
- All Implemented Interfaces:
DataTypeMapperContext,AutoCloseable
DataTypeMapper for Go binaries.
When bootstrapping Go 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic final recordstatic interface -
Field Summary
FieldsFields inherited from class ghidra.app.util.bin.format.golang.structmapping.DataTypeMapper
archiveDTM, archiveSearchCPs, mappingInfo, program, programDTM, programSearchCPs -
Constructor Summary
ConstructorsConstructorDescriptionGoRttiMapper(Program program, GoBuildInfo buildInfo, int ptrSize, GoVer goVer, GoApiSnapshot apiSnapshot) Creates a GoRttiMapper using the specified bootstrap information. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()createMarkupSession(TaskMonitor monitor) Creates aMarkupSessionthat is controlled by the specifiedTaskMonitor.protected BinaryReaderCreates a new BinaryReader that reads bytes from the current program's memory image.findContainingModule(long offset) Finds theGoModuledatathat contains the specified offset.findContainingModuleByFuncData(long offset) Finds theGoModuledatathat contains the specified func data offset.Returns list of all functions contained in the Go func metadata table.CategoryPath location (in the program) where new data types will be created to represent variable length structures.static MemoryBlockgetFirstGoSection(Program program, String... blockNames) Returns the firstGoModuledatamodule data instance.getFuncDefFor(GoFuncData funcData) Returns function definition information for a func.getFunctionByName(String funcName) Returns a function based on its namegetFunctionData(Address funcAddr) Returns metadata about a functiongetFunctionsByNamePattern(Pattern pattern) static GoRttiMappergetGoBinary(Program program, TaskMonitor monitor) Creates aGoRttiMapperrepresenting the specified program.getGoName(long offset) Returns theGoNameinstance at the specified offset.static MemoryBlockgetGoSection(Program program, String sectionName) getGoSection(String sectionName) static SymbolgetGoSymbol(Program program, String symbolName) Returns a matching symbol from the specified program, using Go specific logic.getGoSymbol(String symbolName) getGoVer()ReturnsGo version.getMethodInfoForFunction(Address funcAddr) Returns method info about the specified function.bytegetMinLC()Returns the minLC (pcquantum) value found in the pcln header structure.intReturns the size of pointers in this binary.Returns a sharedGoRegisterInfoinstance<T> GoNamegetSafeName(GoRttiMapper.GoNameSupplier supplier, T structInstance, String defaultValue) An exception handling wrapper around a "getName()" call that could throw an IOException.static GoRttiMappergetSharedGoBinary(Program program, TaskMonitor monitor) Returns a sharedGoRttiMapperfor the specified program, or null if the binary is not a supported Go binary.ReturnsAddressSetViewof range that is valid for string char[] data.ReturnsAddressSetViewof range that is valid to find string structs in.<T extends DataType>
Tstatic AddressgetZerobaseAddress(Program prog) Return the address of the Go zerobase symbol, or an artificial substitute.booleanhasCallingConvention(String ccName) Returns true if the specified calling convention is defined for the program.static booleanhasGolangSections(List<String> sectionNames) voidinit(TaskMonitor monitor) Finishes making this instance ready to be used.static booleanisAbi0Func(Address funcEntry, Program program) booleanisFieldPresent(String presentWhen) Tests if a field should be included when creating bindings between a structure and a class.booleanisGolangAbi0Func(Function func) Returns true if the specified function uses the abi0 calling convention.static booleanisGolangProgram(Program program) Returns true if the specified Program is marked as "golang".Returns newGoParamStorageAllocatorparam storage allocator instance.resolveNameOff(long ptrInModule, long off) Returns theGoNamecorresponding to an offset that is relative to the controlling GoModuledata's typesOffset.resolveTextOff(long ptrInModule, long off) Returns theAddressto an offset that is relative to the controlling GoModuledata's text value.Methods inherited from class ghidra.app.util.bin.format.golang.structmapping.DataTypeMapper
addArchiveSearchCategoryPath, addProgramSearchCategoryPath, createArtificialStructureContext, findType, getAddressOfStructure, getCodeAddress, getDataAddress, getDataConverter, getDTM, getMaxAddressOfStructure, getProgram, getReader, getStructureContextOfInstance, getStructureDataType, getStructureDataTypeName, getStructureMappingInfo, getStructureMappingInfo, getType, getTypeOrDefault, readStructure, readStructure, readStructure, readStructure, registerStructure, registerStructures, toString
-
Field Details
-
SUPPORTED_VERSIONS
-
ARTIFICIAL_RUNTIME_ZEROBASE_SYMBOLNAME
- See Also:
-
-
Constructor Details
-
GoRttiMapper
public GoRttiMapper(Program program, GoBuildInfo buildInfo, int ptrSize, GoVer goVer, GoApiSnapshot apiSnapshot) throws IOException, BootstrapInfoException Creates a GoRttiMapper using the specified bootstrap information.- Parameters:
program-Programcontaining the Go binarybuildInfo-GoBuildInfoptrSize- size of pointersgoVer- version of GoapiSnapshot- json func signatures and data types- Throws:
IOException- if error linking a structure mapped structure to its matching ghidra structure, which is a programming error or invalid bootstrap infoBootstrapInfoException- if there is no bootstrap info for this specific type and version of Go binary
-
-
Method Details
-
getGoBinary
public static GoRttiMapper getGoBinary(Program program, TaskMonitor monitor) throws BootstrapInfoException, IOException Creates aGoRttiMapperrepresenting the specified program.- Parameters:
program-Programmonitor-TaskMonitor- Returns:
- new
GoRttiMapper, or null if basic Go information is not found in the binary - Throws:
BootstrapInfoException- if it is a Go binary and has an unsupported or unparseable version number or if Go bootstrap info was missingIOException- if there was an error in the Ghidra Go RTTI reading logic
-
isGolangProgram
Returns true if the specified Program is marked as "golang".- Parameters:
program-Program- Returns:
- boolean true if program is marked as golang
-
hasGolangSections
-
getGoSymbol
Returns a matching symbol from the specified program, using Go specific logic. -
getGoSection
-
getFirstGoSection
-
getZerobaseAddress
Return the address of the Go zerobase symbol, or an artificial substitute.The zerobase symbol is used as the location of parameters that are zero-length.
-
getAllSupportedVersions
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classDataTypeMapper
-
getType
Description copied from class:DataTypeMapperReturns a namedDataType, searching the registeredprogramandarchivecategory paths.DataTypes that were found in the attached archive gdt manager will be copied into the program's data type manager before being returned.
- Overrides:
getTypein classDataTypeMapper- Type Parameters:
T- DataType or derived type- Parameters:
name-DataTypenameclazz- expected DataType class- Returns:
- DataType or null if not found
-
isFieldPresent
Description copied from interface:DataTypeMapperContextTests if a field should be included when creating bindings between a structure and a class.- Specified by:
isFieldPresentin interfaceDataTypeMapperContext- Parameters:
presentWhen- free-form string that is interpreted by eachDataTypeMapper- Returns:
- boolean true if field should be bound, false if field should not be bound
-
getGoVer
ReturnsGo version.- Returns:
Go version
-
getRegInfo
Returns a sharedGoRegisterInfoinstance- Returns:
GoRegisterInfo
-
getBuildInfo
-
init
Finishes making this instance ready to be used.- Parameters:
monitor-TaskMonitor- Throws:
IOException- if error reading data
-
getGoTypes
-
getMinLC
Returns the minLC (pcquantum) value found in the pcln header structure.- Returns:
- the minLC (pcquantum) value found in the pcln header structure
- Throws:
IOException- if value has not been initialized yet
-
getFirstModule
Returns the firstGoModuledatamodule data instance.- Returns:
- the first
GoModuledatamodule data instance
-
getModules
-
newStorageAllocator
Returns newGoParamStorageAllocatorparam storage allocator instance.- Returns:
- new
GoParamStorageAllocatorparam storage allocator instance
-
isGolangAbi0Func
Returns true if the specified function uses the abi0 calling convention.- Parameters:
func-Functionto test- Returns:
- boolean true if function uses abi0 calling convention
-
isAbi0Func
-
getCallingConventionFor
-
hasCallingConvention
Returns true if the specified calling convention is defined for the program.- Parameters:
ccName- calling convention name- Returns:
- true if the specified calling convention is defined for the program
-
getDefaultCallingConventionName
-
createMarkupSession
Description copied from class:DataTypeMapperCreates aMarkupSessionthat is controlled by the specifiedTaskMonitor.- Overrides:
createMarkupSessionin classDataTypeMapper- Parameters:
monitor-TaskMonitor- Returns:
- new
MarkupSession
-
findContainingModule
Finds theGoModuledatathat contains the specified offset.Useful for finding the
GoModuledatato resolve a relative offset of the text, types or other area.- Parameters:
offset- absolute offset of a structure that aGoModuledatacontains- Returns:
GoModuledatainstance that contains the structure, or null if not found
-
findContainingModuleByFuncData
Finds theGoModuledatathat contains the specified func data offset.- Parameters:
offset- absolute offset of a func data structure- Returns:
GoModuledatainstance that contains the specified func data, or null if not found
-
getDefaultVariableLengthStructCategoryPath
Description copied from class:DataTypeMapperCategoryPath location (in the program) where new data types will be created to represent variable length structures.- Overrides:
getDefaultVariableLengthStructCategoryPathin classDataTypeMapper- Returns:
CategoryPath, default is ROOT
-
createProgramReader
Description copied from class:DataTypeMapperCreates a new BinaryReader that reads bytes from the current program's memory image.Address offsets and index offsets in the BinaryReader should be synonymous.
- Overrides:
createProgramReaderin classDataTypeMapper- Returns:
- new BinaryReader
-
getPtrSize
public int getPtrSize()Returns the size of pointers in this binary.- Returns:
- pointer size (ex. 4, or 8)
-
getFuncDefFor
Returns function definition information for a func.- Parameters:
funcData-GoFuncDatarepresenting a Go func- Returns:
GoRttiMapper.FuncDefResultrecord, or null if no information could be found or generated- Throws:
IOException- if error reading type info
-
getMethodInfoForFunction
Returns method info about the specified function.- Parameters:
funcAddr- function address- Returns:
GoMethod.GoMethodInfo, or null
-
getSafeName
public <T> GoName getSafeName(GoRttiMapper.GoNameSupplier supplier, T structInstance, String defaultValue) An exception handling wrapper around a "getName()" call that could throw an IOException.When there is an error fetching the GoName instance via the specified callback, a limited usage GoName instance will be created and returned that will provide a replacement name that is built using the calling structure's offset as the identifier.
- Type Parameters:
T- struct mapped instance type- Parameters:
supplier- Supplier callbackstructInstance- reference to the caller's struct-mapped instancedefaultValue- string value to return (wrapped in a GoName) if the GoName is simply missing- Returns:
- GoName, either from the callback, or a limited-functionality instance created to hold a fallback name string
-
resolveTextOff
Returns theAddressto an offset that is relative to the controlling GoModuledata's text value.- 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:
Address, or null if offset was special value -1
-
resolveNameOff
Returns theGoNamecorresponding 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:
GoName, or null if offset was special value 0- Throws:
IOException- if error reading name or unable to find containing module
-
getGoName
Returns theGoNameinstance at the specified offset.- Parameters:
offset- location to read- Returns:
GoNameinstance, or null if offset was special value 0- Throws:
IOException- if error reading
-
getFunctionData
Returns metadata about a function- Parameters:
funcAddr- entry point of a function- Returns:
GoFuncData, or null if function not found in lookup tables
-
getFunctionByName
Returns a function based on its name- Parameters:
funcName- name of function- Returns:
GoFuncData, or null if not found
-
getFunctionsByNamePattern
-
getAllFunctions
Returns list of all functions contained in the Go func metadata table.- Returns:
- list of all functions contained in the Go func metadata table
-
getStringStructRange
ReturnsAddressSetViewof range that is valid to find string structs in.- Returns:
AddressSetViewof range that is valid to find string structs in
-
getStringDataRange
ReturnsAddressSetViewof range that is valid for string char[] data.- Returns:
AddressSetViewof range that is valid for string char[] data
-
getTextAddresses
-
getUninitializedNoPtrDataRange
-
getGoSymbol
-
getGoSection