Class PackedEncode

java.lang.Object
ghidra.program.model.pcode.PackedEncode
All Implemented Interfaces:
Encoder, PatchEncoder
Direct Known Subclasses:
PackedEncodeOverlay

public class PackedEncode extends Object implements PatchEncoder
A byte-based encoder designed to marshal to the decompiler efficiently See PackedDecode for details of the encoding format
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear any state associated with the encoder The encoder should be ready to write a new document after this call.
    void
    End the current element in the encoding The current element must match the given annotation or an exception is thrown.
    boolean
    The encoder is considered empty if the writeTo() method would output zero bytes
    void
    Begin a new element in the encoding The element will have the given ElementId annotation and becomes the \e current element.
    boolean
    patchIntegerAttribute(int pos, AttributeId attribId, long val)
    Replace an integer attribute for the element at the given position.
    int
    The returned value can be used as a position for later modification
    void
    writeBool(AttributeId attribId, boolean val)
    Write an annotated boolean value into the encoding The boolean data is associated with the given AttributeId annotation and the current open element.
    void
    writeSignedInteger(AttributeId attribId, long val)
    Write an annotated signed integer value into the encoding The integer is associated with the given AttributeId annotation and the current open element.
    void
    Write an address space reference into the encoding The address space is associated with the given AttributeId annotation and the current open element.
    void
    writeSpaceId(AttributeId attribId, long spaceId)
    Write a given raw spaceid (as returned by AddressSpace.getSpaceID()) as an attribute.
    void
    writeString(AttributeId attribId, String val)
    Write an annotated string into the encoding The string is associated with the given AttributeId annotation and the current open element.
    void
    writeStringIndexed(AttributeId attribId, int index, String val)
    Write an annotated string, using an indexed attribute, into the encoding.
    void
    Dump all the accumulated bytes in this encoder to the stream.
    void
    writeUnsignedInteger(AttributeId attribId, long val)
    Write an annotated unsigned integer value into the encoding The integer is associated with the given AttributeId annotation and the current open element.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PackedEncode

      public PackedEncode()
  • Method Details

    • clear

      public void clear()
      Description copied from interface: Encoder
      Clear any state associated with the encoder The encoder should be ready to write a new document after this call.
      Specified by:
      clear in interface Encoder
    • openElement

      public void openElement(ElementId elemId) throws IOException
      Description copied from interface: Encoder
      Begin a new element in the encoding The element will have the given ElementId annotation and becomes the \e current element.
      Specified by:
      openElement in interface Encoder
      Parameters:
      elemId - is the given ElementId annotation
      Throws:
      IOException - for errors in the underlying stream
    • closeElement

      public void closeElement(ElementId elemId) throws IOException
      Description copied from interface: Encoder
      End the current element in the encoding The current element must match the given annotation or an exception is thrown.
      Specified by:
      closeElement in interface Encoder
      Parameters:
      elemId - is the given (expected) annotation for the current element
      Throws:
      IOException - for errors in the underlying stream
    • writeBool

      public void writeBool(AttributeId attribId, boolean val) throws IOException
      Description copied from interface: Encoder
      Write an annotated boolean value into the encoding The boolean data is associated with the given AttributeId annotation and the current open element.
      Specified by:
      writeBool in interface Encoder
      Parameters:
      attribId - is the given AttributeId annotation
      val - is boolean value to encode
      Throws:
      IOException - for errors in the underlying stream
    • writeSignedInteger

      public void writeSignedInteger(AttributeId attribId, long val) throws IOException
      Description copied from interface: Encoder
      Write an annotated signed integer value into the encoding The integer is associated with the given AttributeId annotation and the current open element.
      Specified by:
      writeSignedInteger in interface Encoder
      Parameters:
      attribId - is the given AttributeId annotation
      val - is the signed integer value to encode
      Throws:
      IOException - for errors in the underlying stream
    • writeUnsignedInteger

      public void writeUnsignedInteger(AttributeId attribId, long val) throws IOException
      Description copied from interface: Encoder
      Write an annotated unsigned integer value into the encoding The integer is associated with the given AttributeId annotation and the current open element.
      Specified by:
      writeUnsignedInteger in interface Encoder
      Parameters:
      attribId - is the given AttributeId annotation
      val - is the unsigned integer value to encode
      Throws:
      IOException - for errors in the underlying stream
    • writeString

      public void writeString(AttributeId attribId, String val) throws IOException
      Description copied from interface: Encoder
      Write an annotated string into the encoding The string is associated with the given AttributeId annotation and the current open element.
      Specified by:
      writeString in interface Encoder
      Parameters:
      attribId - is the given AttributeId annotation
      val - is the string to encode
      Throws:
      IOException - for errors in the underlying stream
    • writeStringIndexed

      public void writeStringIndexed(AttributeId attribId, int index, String val) throws IOException
      Description copied from interface: Encoder
      Write an annotated string, using an indexed attribute, into the encoding. Multiple attributes with a shared name can be written to the same element by calling this method multiple times with a different index value. The encoding will use attribute ids up to the base id plus the maximum index passed in. Implementors must be careful to not use other attributes with ids bigger than the base id within the element taking the indexed attribute.
      Specified by:
      writeStringIndexed in interface Encoder
      Parameters:
      attribId - is the shared AttributeId
      index - is the unique index to associated with the string
      val - is the string to encode
      Throws:
      IOException - for errors in the underlying stream
    • writeSpace

      public void writeSpace(AttributeId attribId, AddressSpace spc) throws IOException
      Description copied from interface: Encoder
      Write an address space reference into the encoding The address space is associated with the given AttributeId annotation and the current open element.
      Specified by:
      writeSpace in interface Encoder
      Parameters:
      attribId - is the given AttributeId annotation
      spc - is the address space to encode
      Throws:
      IOException - for errors in the underlying stream
    • writeTo

      public void writeTo(OutputStream stream) throws IOException
      Description copied from interface: Encoder
      Dump all the accumulated bytes in this encoder to the stream.
      Specified by:
      writeTo in interface Encoder
      Parameters:
      stream - is the output stream
      Throws:
      IOException - for errors during the write operation
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Encoder
      The encoder is considered empty if the writeTo() method would output zero bytes
      Specified by:
      isEmpty in interface Encoder
      Returns:
      true if there are no bytes in the encoder
    • size

      public int size()
      Description copied from interface: PatchEncoder
      The returned value can be used as a position for later modification
      Specified by:
      size in interface PatchEncoder
      Returns:
      the number of bytes written to this stream so far
    • writeSpaceId

      public void writeSpaceId(AttributeId attribId, long spaceId)
      Description copied from interface: PatchEncoder
      Write a given raw spaceid (as returned by AddressSpace.getSpaceID()) as an attribute. The effect is the same as if writeSpace() was called with the AddressSpace matching the spaceid, i.e. the decoder will read this as just space attribute.
      Specified by:
      writeSpaceId in interface PatchEncoder
      Parameters:
      attribId - is the attribute
      spaceId - is the given spaceid
    • patchIntegerAttribute

      public boolean patchIntegerAttribute(int pos, AttributeId attribId, long val)
      Description copied from interface: PatchEncoder
      Replace an integer attribute for the element at the given position. The position is assumed to be at an open directive for the element containing the attribute to be patched.
      Specified by:
      patchIntegerAttribute in interface PatchEncoder
      Parameters:
      pos - is the given position
      attribId - is the attribute to be patched
      val - is the new value to insert
      Returns:
      true if the attribute is successfully patched