Class ExtendedByteSequence

java.lang.Object
ghidra.features.base.memsearch.bytesequence.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 two parts; the primary sequence and an extended sequence. Search matches must begin in the primary sequence, but may extend into the extended sequence.

Searching large ranges of memory can be partitioned into searching smaller chunks. But to handle search sequences that span chunks, two chunks are presented at a time, with the second chunk being the extended bytes. On the next iteration of the search loop, the extended chunk will become the primary chunk, with the next chunk after that becoming the extended sequence and so on.

  • Constructor Details

    • ExtendedByteSequence

      public ExtendedByteSequence(ByteSequence main, ByteSequence extended, int extendedLimit)
      Constructs an extended byte sequence from two ByteSequences.
      Parameters:
      main - the byte sequence where search matches may start
      extended - the byte sequence where search matches may extend into
      extendedLimit - 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
    • 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