Expand description
Searches for a contiguous array of bytes determined by a given pattern. The pattern can include supported wildcard characters, as seen below.
§Wildcards
?match any byte
§Example Patterns
fe 00 68 98- matches onlyfe 00 68 988d 11 ? ? 8f- could match8d 11 9e ef 8for8d 11 0 0 8ffor example
§Example Usage
The scan function is used to scan for a pattern within the output of a Read. Using a
Cursor to scan within a byte array in memory could look as follows:
use patternscan::scan;
use std::io::Cursor;
let bytes = [0x10, 0x20, 0x30, 0x40, 0x50];
let pattern = "20 30 40";
let locs = scan(Cursor::new(bytes), &pattern).unwrap(); // Will equal vec![1], the index of
// the patternAny struct implementing Read can be passed as the reader which should be scanned for
ocurrences of a pattern, so one could scan for a byte sequence within an executable as follows:
ⓘ
use patternscan::scan;
use std::fs::File;
let reader = File::open("somebinary.exe").unwrap();
let instruction = "A3 ? ? ? ?";
let locs = scan(reader, &instruction).unwrap();For more example uses of this module, see the tests
Structs§
- Error
- Represents an error which occurred while scanning for a pattern.
- Matches
- Iterator over locations of matches for a pattern found within a byte string.
- Pattern
- Represents a pattern to search for in a byte string.
Enums§
- Pattern
Byte - Represents a single byte in a search pattern.
Constants§
- CHUNK_
SIZE - Size of chunks to be read from
readerwhen looking for patterns.
Functions§
- pattern_
matches - Determine whether a byte slice matches a pattern.
- scan
- Scan for any instances of
patternin the bytes read byreader. - scan_
first_ match - Scan for the first instance of
patternin the bytes read byreader.