bmatcher_core

Trait MatchTarget

Source
pub trait MatchTarget {
    // Required methods
    fn match_length(&self) -> usize;
    fn subrange(&self, offset: usize, byte_count: usize) -> Option<&[u8]>;
    fn translate_absolute_address(&self, address: u64) -> Option<usize>;
}
Expand description

A trait for targets that can be matched against a binary pattern.

Implementing this trait allows matching against data sources that may not be continuous (e.g., fragmented data or packed representations), offering greater flexibility compared to directly using a u8 slice.

By default a u8 slice does implement this trait.

Required Methods§

Source

fn match_length(&self) -> usize

Returns the total length of the data which will be scaned when matching a binary pattern.

Source

fn subrange(&self, offset: usize, byte_count: usize) -> Option<&[u8]>

Retrieves a subrange of the data, starting at the specified offset and spanning the given number of bytes.

§Parameters
  • offset: The starting position within the data.
  • byte_count: The number of bytes to include in the subrange.
§Returns

An Option containing a slice of the data if the range is valid; otherwise, None.

Source

fn translate_absolute_address(&self, address: u64) -> Option<usize>

Translates an absolute address to an index within the matchable data.

§Parameters
  • address: The absolute address to translate.
§Returns

An Option containing the translated index if the address is valid; otherwise, None.

Implementations on Foreign Types§

Source§

impl MatchTarget for &[u8]

Source§

fn match_length(&self) -> usize

Source§

fn subrange(&self, offset: usize, byte_count: usize) -> Option<&[u8]>

Source§

fn translate_absolute_address(&self, address: u64) -> Option<usize>

Implementors§