java.lang.Object
ghidra.app.util.bin.format.golang.structmapping.MarkupSession

public class MarkupSession extends Object
State and methods needed for structure mapped objects to add markup, comments, labels, etc to a program.
  • Field Details

  • Constructor Details

    • MarkupSession

      public MarkupSession(DataTypeMapper programContext, TaskMonitor monitor)
      Creates a new markup session
      Parameters:
      programContext - program-level structure mapping context
      monitor - allows user to cancel
  • Method Details

    • getProgram

      public Program getProgram()
      Returns the Ghidra program
      Returns:
      Ghidra Program
    • getMappingContext

      public DataTypeMapper getMappingContext()
      Returns the program level mapping context
      Returns:
      DataTypeMapper
    • getMarkedupAddresses

      public AddressSet getMarkedupAddresses()
    • markup

      public <T> void markup(T obj, boolean nested) throws IOException, CancelledException
      Decorates the specified object's memory using the various structure mapping tags that were applied the object's class definition.

      The object can be a structure mapped object, or a collection, array or iterator of structure mapped objects.

      Type Parameters:
      T - structure mapped object type
      Parameters:
      obj - structure mapped object instance
      nested - boolean flag, if true the specified object is contained inside another object who's data type has already been laid down in memory, removing the need for this object's data type to be applied to memory
      Throws:
      IOException - if error or cancelled
      CancelledException - if cancelled
      IllegalArgumentException - if object instance is not a supported type
    • markupAddress

      public void markupAddress(Address addr, DataType dt) throws IOException
      Applies the specified DataType to the specified Address.
      Parameters:
      addr - location to place DataType
      dt - DataType
      Throws:
      IOException - if error marking up address
    • markupAddress

      public void markupAddress(Address addr, DataType dt, int length) throws IOException
      Applies the specified DataType to the specified Address.
      Parameters:
      addr - location to place DataType
      dt - DataType
      length - length of the data type instance, or -1 if the data type is fixed length
      Throws:
      IOException - if error marking up address
    • markupAddressIfUndefined

      public void markupAddressIfUndefined(Address addr, DataType dt) throws IOException
      Applies the specified DataType to the specified Address.
      Parameters:
      addr - location to place DataType
      dt - DataType
      Throws:
      IOException - if error marking up address
    • labelStructure

      public <T> void labelStructure(T obj, String symbolName, String namespaceName) throws IOException
      Places a label at the specified structure mapped object's address.
      Type Parameters:
      T - structure mapped object type
      Parameters:
      obj - structure mapped object
      symbolName - name
      namespaceName - name of namespace to place the label symbol in, or null if root
      Throws:
      IOException - if error
    • labelAddress

      public void labelAddress(Address addr, String symbolName) throws IOException
      Places a label at the specified address.
      Parameters:
      addr - Address
      symbolName - name
      Throws:
      IOException - if error
    • labelAddress

      public void labelAddress(Address addr, String symbolName, String namespaceName) throws IOException
      Places a label at the specified address.
      Parameters:
      addr - Address
      symbolName - name
      namespaceName - name of namespace to place the label symbol in, or null if root
      Throws:
      IOException - if error
    • appendComment

      public void appendComment(FieldContext<?> fieldContext, int commentType, String prefix, String comment, String sep) throws IOException
      Adds a comment to the specified field, appending to any previous values already there. If the existing comment already contains the specified comment value, the operation is skipped.
      Parameters:
      fieldContext - the field
      commentType - CodeUnit.EOL_COMMENT, CodeUnit.PLATE_COMMENT, CodeUnit.POST_COMMENT, CodeUnit.PRE_COMMENT
      prefix - String prefix to place in front of the comment string
      comment - String value to append
      sep - separator to use between existing comments (for example, "\n")
      Throws:
      IOException - if error adding comment
    • appendComment

      public void appendComment(StructureContext<?> structureContext, int commentType, String prefix, String comment, String sep) throws IOException
      Adds a comment to the specified structure, appending to any previous values already there. If the existing comment already contains the specified comment value, the operation is skipped.
      Parameters:
      structureContext - the structure
      commentType - CodeUnit.EOL_COMMENT, CodeUnit.PLATE_COMMENT, CodeUnit.POST_COMMENT, CodeUnit.PRE_COMMENT
      prefix - String prefix to place in front of the comment string
      comment - String value to append
      sep - separator to use between existing comments (for example, "\n")
      Throws:
      IOException - if error adding comment
    • appendComment

      public void appendComment(Function func, String prefix, String comment)
    • markupStructure

      public <T> void markupStructure(StructureContext<T> structureContext, boolean nested) throws IOException, CancelledException
      Decorates a structure mapped structure, and everything it contains.
      Type Parameters:
      T - structure mapped type
      Parameters:
      structureContext - StructureContext
      nested - if true, it is assumed that the Ghidra data types have already been placed and only markup needs to be performed.
      Throws:
      IOException - if error marking up structure
      CancelledException - if cancelled
    • markupArrayElementReferences

      public void markupArrayElementReferences(Address arrayAddr, int elementSize, List<Address> targetAddrs) throws IOException
      Creates references from each element of an array to a list of target addresses.
      Parameters:
      arrayAddr - the address of the start of the array
      elementSize - the size of each array element
      targetAddrs - list of addresses that will receive references from each array elements
      Throws:
      IOException - if error
    • createFunctionIfMissing

      public Function createFunctionIfMissing(String name, Namespace ns, Address addr)
      Creates a default function at the specified address.
      Parameters:
      name - name of the new function
      ns - namespace function should be in
      addr - address of the new function
      Returns:
      Function that was created
    • addReference

      public void addReference(FieldContext<?> fieldContext, Address refDest)
      Creates a reference from the specified field to the specified address.
      Parameters:
      fieldContext - field, is the source of the reference
      refDest - destination address of the reference
    • logWarningAt

      public void logWarningAt(Address addr, String msg)
    • logWarningAt

      public static void logWarningAt(Program program, Address addr, String msg)