Class StructureContext<T>
java.lang.Object
ghidra.app.util.bin.format.golang.structmapping.StructureContext<T>
- Type Parameters:
T- a java class that has been tagged with aStructureMappingannotation.
Information about an instance of a structure that has been read from the memory of a
Ghidra program.
All StructureMapping tagged classes must have a ContextField tagged
StructureContext field for that class to be able to access meta-data about its self, and
for other classes to reference it when performing markup:
@StructureMapping(structureName = "mydatatype")
class MyDataType {
@ContextField
private StructureContext<MyDataType> context;
@FieldMapping
private long someField;
...
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DataTypeMapperprotected final StructureMappingInfo<T>protected final BinaryReaderprotected Structureprotected Tprotected final long -
Constructor Summary
ConstructorsConstructorDescriptionStructureContext(DataTypeMapper dataTypeMapper, StructureMappingInfo<T> mappingInfo, BinaryReader reader) Creates an instance of aStructureContext. -
Method Summary
Modifier and TypeMethodDescriptioncreateFieldContext(FieldMappingInfo<T> fmi, boolean includeReader) Creates a newFieldContextfor a specific field.Returns a reference to the rootDataTypeMapper, as a plain DataTypeMapper type.getFieldAddress(long fieldOffset) Returns the address of an offset from the start of this structure instance.longgetFieldLocation(long fieldOffset) Returns the stream location of an offset from the start of this structure instance.getFieldReader(long fieldOffset) Returns an independentBinaryReaderthat is positioned at the start of the specified field.Returns theStructureMappingInfofor this structure's class.Returns theBinaryReaderthat is used to deserialize this structure.Returns the address in the program of this structure instance.Returns the Ghidrastructure data typethat represents this object.longReturns the stream location of the end of this structure instance.Returns a reference to the object instance that was deserialized.intReturns the length of this structure instance.longReturns the stream location of this structure instance.Creates a new instance of the structure by deserializing the structure's marked fields into java fields.toString()
-
Field Details
-
dataTypeMapper
-
mappingInfo
-
reader
-
structureStart
protected final long structureStart -
structureInstance
-
structureDataType
-
-
Constructor Details
-
StructureContext
public StructureContext(DataTypeMapper dataTypeMapper, StructureMappingInfo<T> mappingInfo, BinaryReader reader) Creates an instance of aStructureContext.- Parameters:
dataTypeMapper- mapping context for the programmappingInfo- mapping information about this structurereader-BinaryReaderpositioned at the start of the structure to be read
-
-
Method Details
-
readNewInstance
Creates a new instance of the structure by deserializing the structure's marked fields into java fields.- Returns:
- new instance of structure
- Throws:
IOException- if error reading
-
getMappingInfo
Returns theStructureMappingInfofor this structure's class.- Returns:
StructureMappingInfofor this structure's class
-
getDataTypeMapper
Returns a reference to the rootDataTypeMapper, as a plain DataTypeMapper type. If a more specific DataTypeMapper type is needed, either type-cast this value, or use aContextFieldtag on a field in your class that specifies the correct DataTypeMapper type.- Returns:
- the program mapping context that control's this structure instance
-
getStructureAddress
Returns the address in the program of this structure instance.- Returns:
Address
-
getFieldAddress
Returns the address of an offset from the start of this structure instance.- Parameters:
fieldOffset- number of bytes from the beginning of this structure where a field (or other location of interest) starts- Returns:
Addressof specified offset
-
getFieldLocation
public long getFieldLocation(long fieldOffset) Returns the stream location of an offset from the start of this structure instance.- Parameters:
fieldOffset- number of bytes from the beginning of this structure where a field (or other location of interest) starts- Returns:
- absolute offset / position in the program / BinaryReader stream
-
getStructureStart
public long getStructureStart()Returns the stream location of this structure instance.- Returns:
- absolute offset / position in the program / BinaryReader stream of this structure
-
getStructureEnd
public long getStructureEnd()Returns the stream location of the end of this structure instance.- Returns:
- absolute offset / position in the program / BinaryReader stream of the byte after this structure
-
getStructureLength
public int getStructureLength()Returns the length of this structure instance.- Returns:
- length of this structure, or 0 if this structure is a variable length structure that does not have a fixed length
-
getStructureInstance
Returns a reference to the object instance that was deserialized.- Returns:
- reference to deserialized structure mapped object
-
getReader
Returns theBinaryReaderthat is used to deserialize this structure.- Returns:
BinaryReaderthat is used to deserialize this structure
-
getFieldReader
Returns an independentBinaryReaderthat is positioned at the start of the specified field.- Parameters:
fieldOffset- number of bytes from the beginning of this structure where a field (or other location of interest) starts- Returns:
- new
BinaryReaderpositioned at the specified relative offset
-
createFieldContext
Creates a newFieldContextfor a specific field.- Parameters:
fmi-fieldof interestincludeReader- boolean flag, if true create a BinaryReader for the field, if false no BinaryReader will be created- Returns:
- new
FieldContext
-
getStructureDataType
Returns the Ghidrastructure data typethat represents this object.If this is an instance of a variable length structure mapped class, a custom structure data type will be minted that exactly matches this instance's variable length fields.
- Returns:
- Ghidra
structure data typethat represents this object - Throws:
IOException- if error constructing new struct data type
-
toString
-