Class BulkPatternSearcher<T extends BytePattern>

java.lang.Object
ghidra.util.bytesearch.BulkPatternSearcher<T>
Type Parameters:
T - The specific pattern type

public class BulkPatternSearcher<T extends BytePattern> extends Object
State machine for searching for a list of BytePatterns simultaneously in a byte sequence. Once this BulkPatternMatcher is constructed from a list of patterns, it can be used any number of times to search byte sequences. There are an assortment of search methods to meet various client needs.

The search methods break down into the following categories: 1) Searching a byte buffer with the result being an iterator over matches. 2) Searching a byte buffer with the results being added to a given list. 3) Searching an input stream with the results being added to a given list. 4) Searching an ExtendedByteSequence with the results being added to a given list

In addition, the byte buffer methods all have a variation that takes an additional parameter stating how many of the bytes in the buffer are searchable. (The buffer is not full). Also, the input stream method has a variation where the max bytes to read from the stream is given.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the number of unique states generated. Used for testing..
    void
    matches(byte[] input, int numBytes, List<Match<T>> results)
    Searches for the patterns in the given byte array that start at the first byte in the array.
    search(byte[] input)
    Search the given byte buffer for any of this searcher's patterns.
    search(byte[] input, int length)
    Search the given byte buffer up the specified length for any of this searcher's patterns.
    void
    search(byte[] input, int numBytes, List<Match<T>> results)
    Searches for the patterns in the given byte array, adding match results to the given list of results.
    void
    search(byte[] input, List<Match<T>> results)
    Searches for the patterns in the given byte array, adding match results to the given list of results.
    void
    search(ExtendedByteSequence bytes, List<Match<T>> results, int chunkOffset)
    Searches for the patterns in the given ExtendedByteSequence, adding match results to the given list of results.
    void
    search(InputStream inputStream, long maxRead, List<Match<T>> results, TaskMonitor monitor)
    Searches for the patterns in the given input stream, adding match results to the given list of results.
    void
    search(InputStream is, List<Match<T>> results, TaskMonitor monitor)
    Searches for the patterns in the given input stream, adding match results to the given list of results.
    void
    setBufferSize(int bufferSize)
    Sets the buffer size used when using one of the search methods that takes an input stream.

    Methods inherited from class java.lang.Object

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

    • BulkPatternSearcher

      public BulkPatternSearcher(List<T> patterns)
      Constructor
      Parameters:
      patterns - the list of patterns that can be search simultaneously using an internal finite state machine
  • Method Details

    • search

      public Iterator<Match<T>> search(byte[] input)
      Search the given byte buffer for any of this searcher's patterns.
      Parameters:
      input - the byte buffer to search
      Returns:
      An iterator that will return pattern matches one at a time.
    • search

      public Iterator<Match<T>> search(byte[] input, int length)
      Search the given byte buffer up the specified length for any of this searcher's patterns.
      Parameters:
      input - the byte buffer to search
      length - the actual number of the bytes in the buffer to search.
      Returns:
      An iterator that will return pattern matches one at a time.
    • search

      public void search(byte[] input, List<Match<T>> results)
      Searches for the patterns in the given byte array, adding match results to the given list of results.
      Parameters:
      input - the byte array to search for patterns
      results - the list of match results to populate
    • search

      public void search(byte[] input, int numBytes, List<Match<T>> results)
      Searches for the patterns in the given byte array, adding match results to the given list of results.
      Parameters:
      input - the byte array to search for patterns
      numBytes - the number of valid bytes in the input buffer to search
      results - the list of match results to populate
    • matches

      public void matches(byte[] input, int numBytes, List<Match<T>> results)
      Searches for the patterns in the given byte array that start at the first byte in the array. Resulting matches are added to the given results list.
      Parameters:
      input - the byte array to search for patterns
      numBytes - the number of bytes to use from the given byte array. (The byte array might not be fully populated with valid data.)
      results - the list of match results to populate
    • search

      public void search(ExtendedByteSequence bytes, List<Match<T>> results, int chunkOffset)
      Searches for the patterns in the given ExtendedByteSequence, adding match results to the given list of results.
      Parameters:
      bytes - the extended byte sequence to search
      results - the list of match results to populate
      chunkOffset - a constant offset to add to the pattern starts found in this buffer. Users of this method may have split a larger byte sequence into chunks and the final match position needs to be the sum of the chunk offset plus the offset within this chunk.
    • search

      public void search(InputStream is, List<Match<T>> results, TaskMonitor monitor) throws IOException
      Searches for the patterns in the given input stream, adding match results to the given list of results.
      Parameters:
      is - the input stream of bytes to scan for patterns
      results - the list of match results to populate
      monitor - the task monitor
      Throws:
      IOException - if an exception occurs reading the input stream
    • search

      public void search(InputStream inputStream, long maxRead, List<Match<T>> results, TaskMonitor monitor) throws IOException
      Searches for the patterns in the given input stream, adding match results to the given list of results.

      Parameters:
      inputStream - the input stream of bytes to scan for patterns
      maxRead - the maximum offset into the input stream where a match can start. Additional bytes can be read from the stream to complete patterns
      results - the list of match results to populate
      monitor - the task monitor
      Throws:
      IOException - if an exception occurs reading the input stream
    • setBufferSize

      public void setBufferSize(int bufferSize)
      Sets the buffer size used when using one of the search methods that takes an input stream. Mostly used for testing.
      Parameters:
      bufferSize - the size of the buffers to use when searching input streams.
    • getUniqueStateCount

      public int getUniqueStateCount()
      Returns the number of unique states generated. Used for testing..
      Returns:
      the number of unique states generated. Used for testing.