pub struct Pattern { /* private fields */ }Expand description
A wildcard byte pattern with parsed-from-string ergonomics.
Internally just a Vec<Option<u8>> for owned, runtime-built patterns.
For static / compile-time patterns prefer the crate::pattern! macro,
which produces a &'static [Option<u8>] with no allocation.
§Examples
use pe_sigscan::Pattern;
let p = Pattern::from_ida("48 8B 05 ?? ?? ?? ?? 48 89 41 08").unwrap();
assert_eq!(p.len(), 11);
assert_eq!(p.as_slice()[0], Some(0x48));
assert_eq!(p.as_slice()[3], None);Implementations§
Source§impl Pattern
impl Pattern
Sourcepub fn new(bytes: Vec<Option<u8>>) -> Self
pub fn new(bytes: Vec<Option<u8>>) -> Self
Construct a pattern from an existing Vec<Option<u8>>.
Useful when the pattern is built programmatically (e.g. mutating an
existing Vec<Option<u8>> to add wildcards before scanning).
Sourcepub fn from_ida(s: &str) -> Result<Self, ParsePatternError>
pub fn from_ida(s: &str) -> Result<Self, ParsePatternError>
Parse an IDA-style hex pattern string.
Accepted token shapes (case-insensitive, separated by ASCII whitespace):
XX— two hex digits, matches the literal byte0xXX.?or??— wildcard, matches any byte.
§Examples
use pe_sigscan::Pattern;
let p = Pattern::from_ida("48 8B ?? 89").unwrap();
assert_eq!(p.as_slice(), &[Some(0x48), Some(0x8B), None, Some(0x89)]);§Errors
Returns ParsePatternError if the input contains a token that is
neither two hex digits nor ? / ??, or if a token mixes ? with
hex characters (?A, 1?).
Sourcepub fn as_slice(&self) -> WildcardPattern<'_>
pub fn as_slice(&self) -> WildcardPattern<'_>
View the pattern as a WildcardPattern. Use this when calling the
scan functions: find_in_text(base, pat.as_slice()).