Class StructureContext<T>
- Type Parameters:
T- a java class that has been tagged with aStructureMappingannotation.
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 DataTypeprotected 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.StructureContext(DataTypeMapper dataTypeMapper, StructureMappingInfo<T> mappingInfo, DataType containingFieldDataType, BinaryReader reader) Creates an instance of aStructureContext. -
Method Summary
Modifier and TypeMethodDescriptioncreateFieldContext(FieldMappingInfo<T> fmi, boolean includeReader) Creates a newFieldContextfor a specific field.Returns theDataTypeof the field that this object instance was contained inside of, or null if this instance was not a field inside another structure.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
-
containingFieldDataType
-
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, or null if this is a limited-use context object
-
StructureContext
public StructureContext(DataTypeMapper dataTypeMapper, StructureMappingInfo<T> mappingInfo, DataType containingFieldDataType, BinaryReader reader) Creates an instance of aStructureContext.- Parameters:
dataTypeMapper- mapping context for the programmappingInfo- mapping information about this structurecontainingFieldDataType- optional, the DataType of the field that contained the instance being deserializedreader-BinaryReaderpositioned at the start of the structure to be read, or null if this is a limited-use context object
-
-
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
-
getContainingFieldDataType
Returns theDataTypeof the field that this object instance was contained inside of, or null if this instance was not a field inside another structure.For instance, if a structure was being deserialized because it was a field inside another structure, the actual Ghidra data type of the field may be slightly different than the structure data type defined at the top of the structmapped class (ie.
@StructureMapping(structureName='struct'). The containing field's data type could allow custom logic to enrich or modify this struct's behavior.- Returns:
DataTypeof the field that this object instance was contained inside of
-
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
-