pub struct Pattern { /* private fields */ }Expand description
A pattern that can be used to scan for matches in a byte array.
This is the main type of this crate, and you can create it
using the PatternBuilder struct.
Internally, a pattern is represented as a vector of bytes for the signature, a vector of booleans for the mask, and the number of threads to use.
Implementations
sourceimpl Pattern
impl Pattern
sourcepub fn get_threads(&self) -> usize
pub fn get_threads(&self) -> usize
Returns
The number of threads to use in scans of this pattern.
sourcepub fn scan(
&self,
data: &[u8],
callback: impl FnMut(usize) -> bool + Send + Sync
) -> bool
pub fn scan(
&self,
data: &[u8],
callback: impl FnMut(usize) -> bool + Send + Sync
) -> bool
Performs the AOB scan in the given slice.
If specified, this function will split the data into chunks and scan
each chunk in parallel.
Arguments
data- The data slice to scan.callback- The callback to execute when a match is found.- The callback receives the offset of the match as an argument.
- It should return
trueto continue scanning, orfalseto stop.
Returns
True if at least one match was found, otherwise false.
sourcepub fn scan_object(
&self,
data: &[u8],
section_name: &str,
callback: impl FnMut(SectionResult) -> bool + Send + Sync
) -> Result<bool, ObjectError>
pub fn scan_object(
&self,
data: &[u8],
section_name: &str,
callback: impl FnMut(SectionResult) -> bool + Send + Sync
) -> Result<bool, ObjectError>
Performs the AOB scan in the specified object section of the given slice.
This function is useful for restricting the scan to a specific section of
a binary file, such as the __text section.
This reduces the amount of data that needs to be scanned, and can
drastically improve the scan speed.
If the section is not found, the scan is not performed, and false is returned.
FAT Mach-O binaries are also supported, and in this case all the THIN binaries
are scanned for the given section.
Information about which THIN binary contains the match is returned in
the callback.
Arguments
data- The data slice to scan.section_name- The name of the section to scan. (e.g.__text)callback- The callback to execute when a match is found.- The callback receives a structure containing all the information of the match as argument.
- It should return
trueto continue scanning, orfalseto stop.
Returns
Ok(true) if at least one match was found, Ok(false) if no matches were found, Err if an error occurred.