Package ghidra.util.bytesearch
Class BulkPatternSearcher<T extends BytePattern>
java.lang.Object
ghidra.util.bytesearch.BulkPatternSearcher<T>
- Type Parameters:
T- The specific pattern type
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 -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of unique states generated. Used for testing..voidSearches 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.voidSearches for the patterns in the given byte array, adding match results to the given list of results.voidSearches for the patterns in the given byte array, adding match results to the given list of results.voidsearch(ExtendedByteSequence bytes, List<Match<T>> results, int chunkOffset) Searches for the patterns in the givenExtendedByteSequence, adding match results to the given list of results.voidsearch(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.voidsearch(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.voidsetBufferSize(int bufferSize) Sets the buffer size used when using one of the search methods that takes an input stream.
-
Constructor Details
-
BulkPatternSearcher
Constructor- Parameters:
patterns- the list of patterns that can be search simultaneously using an internal finite state machine
-
-
Method Details
-
search
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
Search the given byte buffer up the specified length for any of this searcher's patterns.- Parameters:
input- the byte buffer to searchlength- the actual number of the bytes in the buffer to search.- Returns:
- An iterator that will return pattern matches one at a time.
-
search
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 patternsresults- the list of match results to populate
-
search
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 patternsnumBytes- the number of valid bytes in the input buffer to searchresults- the list of match results to populate
-
matches
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 patternsnumBytes- 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
Searches for the patterns in the givenExtendedByteSequence, adding match results to the given list of results.- Parameters:
bytes- the extended byte sequence to searchresults- the list of match results to populatechunkOffset- 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
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 patternsresults- the list of match results to populatemonitor- 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 patternsmaxRead- the maximum offset into the input stream where a match can start. Additional bytes can be read from the stream to complete patternsresults- the list of match results to populatemonitor- 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.
-