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 a StructureMapping annotation.

public class StructureContext<T> extends Object
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 Details

    • dataTypeMapper

      protected final DataTypeMapper dataTypeMapper
    • mappingInfo

      protected final StructureMappingInfo<T> mappingInfo
    • reader

      protected final BinaryReader reader
    • structureStart

      protected final long structureStart
    • structureInstance

      protected T structureInstance
    • structureDataType

      protected Structure structureDataType
  • Constructor Details

  • Method Details

    • readNewInstance

      public T readNewInstance() throws IOException
      Throws:
      IOException
    • getMappingInfo

      public StructureMappingInfo<T> getMappingInfo()
      Returns the StructureMappingInfo for this structure's class.
      Returns:
    • getDataTypeMapper

      public DataTypeMapper getDataTypeMapper()
      Returns a reference to the root DataTypeMapper, as a plain DataTypeMapper type. If a more specific DataTypeMapper type is needed, either type-cast this value, or use a ContextField tag on a field in your class that specifies the correct DataTypeMapper type.
      Returns:
    • getProgram

      public Program getProgram()
    • getStructureAddress

      public Address getStructureAddress()
      Returns the address in the program of this structure instance.
      Returns:
      Address
    • getFieldAddress

      public Address getFieldAddress(long fieldOffset)
      Returns the address of an offset from the start of this structure instance.
      Parameters:
      fieldOffset -
      Returns:
    • getFieldLocation

      public long getFieldLocation(long fieldOffset)
      Returns the stream location of an offset from the start of this structure instance.
      Parameters:
      fieldOffset -
      Returns:
    • getStructureStart

      public long getStructureStart()
      Returns the stream location of this structure instance.
      Returns:
    • getStructureEnd

      public long getStructureEnd()
      Returns the stream location of the end of this structure instance.
      Returns:
    • getStructureLength

      public int getStructureLength()
      Returns the length of this structure instance.
      Returns:
    • getStructureInstance

      public T getStructureInstance()
    • getReader

      public BinaryReader getReader()
    • getFieldReader

      public BinaryReader getFieldReader(long fieldOffset)
      Returns an independent BinaryReader that is positioned at the start of the specified field.
      Parameters:
      fieldOffset -
      Returns:
    • createFieldContext

      public FieldContext<T> createFieldContext(FieldMappingInfo<T> fmi, boolean includeReader)
    • appendComment

      public void appendComment(int commentType, String prefix, String comment, String sep) throws IOException
      Places a comment at the start of this structure, appending to any previous values already there.
      Parameters:
      commentType -
      prefix -
      comment -
      sep -
      Throws:
      IOException
    • isAlreadyMarkedup

      public boolean isAlreadyMarkedup()
    • markupStructure

      public void markupStructure(boolean nested) throws IOException
      Parameters:
      nested - if true, it is assumed that the Ghidra data types have already been placed and only markup needs to be performed.
      Throws:
      IOException
    • markupFields

      public void markupFields() throws IOException
      Throws:
      IOException
    • getStructureDataType

      public Structure getStructureDataType() throws IOException
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object