Class ExtendedByteSequence

java.lang.Object
ghidra.util.bytesearch.ExtendedByteSequence
All Implemented Interfaces:
ByteSequence

public class ExtendedByteSequence extends Object implements ByteSequence
A class for accessing a contiguous sequence of bytes from some underlying byte source to be used for searching for a byte pattern within the byte source. This sequence of bytes consists of three parts; the primary sequence, a pre sequence, and an extended sequence. Search matches must begin in the primary sequence, but may extend into the extended sequence. The pre-sequence is used for searching that supports look-behind such as some regular expressions.

Searching large ranges of memory can be partitioned into searching smaller chunks. But to handle search sequences that span chunks, three chunks are presented at a time. Look-behind patterns can use the pre-chunk to see the bytes before the main chunk. Actual matches must start in the main chunk, but can extend into the extended chunk. On the next iteration of the search loop, the main chunk becomes the pre-chunk and the extended chunk becomes the main chunk and a new post-chunk is read from the input source.

  • Constructor Details

    • ExtendedByteSequence

      public ExtendedByteSequence(ByteSequence main, ByteSequence pre, ByteSequence post, int overlap)
      Constructs an extended byte sequence from two ByteSequences.
      Parameters:
      main - the byte sequence where search matches may start
      pre - the byte sequence bytes before the main byte sequence used by searchers that support "look behind"
      post - the byte sequence where search matches may extend into
      overlap - specifies how much of the extended byte sequence to allow search matches to extend into. (The extended buffer will be the primary buffer next time, so it is a full size buffer, but we only need to use a portion of it to support overlap.
  • Method Details

    • getLength

      public int getLength()
      Description copied from interface: ByteSequence
      Returns the length of available bytes.
      Specified by:
      getLength in interface ByteSequence
      Returns:
      the length of the sequence of bytes
    • getExtendedLength

      public int getExtendedLength()
      Returns the overall length of sequence of available bytes. This will be the length of the primary sequence as returned by getLength() plus the length of the available extended bytes, if any.
      Returns:
      the
    • getPreLength

      public int getPreLength()
    • getByte

      public byte getByte(int i)
      Description copied from interface: ByteSequence
      Returns the byte at the given index. The index must between 0 and the extended length.
      Specified by:
      getByte in interface ByteSequence
      Parameters:
      i - the index in the byte sequence to retrieve a byte value
      Returns:
      the byte at the given index
    • getBytes

      public byte[] getBytes(int index, int size)
      Description copied from interface: ByteSequence
      Returns a byte array containing the bytes from the given range.
      Specified by:
      getBytes in interface ByteSequence
      Parameters:
      index - the start index of the range to get bytes
      size - the number of bytes to get
      Returns:
      a byte array containing the bytes from the given range
    • hasAvailableBytes

      public boolean hasAvailableBytes(int index, int length)
      Description copied from interface: ByteSequence
      A convenience method for checking if this sequence can provide a range of bytes from some offset.
      Specified by:
      hasAvailableBytes in interface ByteSequence
      Parameters:
      index - the index of the start of the range to check for available bytes
      length - the length of the range to check for available bytes
      Returns:
      true if bytes are available for the given range