Class StructureContext<T>
- Type Parameters:
T
- a java class that has been tagged with aStructureMapping
annotation.
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
Modifier and TypeFieldDescriptionprotected final DataType
protected final DataTypeMapper
protected final StructureMappingInfo
<T> protected final BinaryReader
protected Structure
protected T
protected final long
-
Constructor Summary
ConstructorDescriptionStructureContext
(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 newFieldContext
for a specific field.Returns theDataType
of 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.long
getFieldLocation
(long fieldOffset) Returns the stream location of an offset from the start of this structure instance.getFieldReader
(long fieldOffset) Returns an independentBinaryReader
that is positioned at the start of the specified field.Returns theStructureMappingInfo
for this structure's class.Returns theBinaryReader
that is used to deserialize this structure.Returns the address in the program of this structure instance.Returns the Ghidrastructure data type
that represents this object.long
Returns the stream location of the end of this structure instance.Returns a reference to the object instance that was deserialized.int
Returns the length of this structure instance.long
Returns 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
-BinaryReader
positioned 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
-BinaryReader
positioned 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 theStructureMappingInfo
for this structure's class.- Returns:
StructureMappingInfo
for 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 aContextField
tag 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 theDataType
of 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:
DataType
of 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:
Address
of 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 theBinaryReader
that is used to deserialize this structure.- Returns:
BinaryReader
that is used to deserialize this structure
-
getFieldReader
Returns an independentBinaryReader
that 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
BinaryReader
positioned at the specified relative offset
-
createFieldContext
Creates a newFieldContext
for a specific field.- Parameters:
fmi
-field
of 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 type
that 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 type
that represents this object - Throws:
IOException
- if error constructing new struct data type
-
toString
-