Struct memflex::Pattern

source ·
pub struct Pattern<const N: usize>(/* private fields */);
Expand description

Represents a staticly built sequence of bytes to match against.

let data = b"\x11\x22\x33";
let ida = ida_pat!("11 ? 33");
let peid = peid_pat!("11 ?? 33");
let code = code_pat!(b"\x11\x00\x33", "x?x");
assert!(ida.matches(data) && peid.matches(data) && code.matches(data));

Implementations§

source§

impl<const N: usize> Pattern<N>

source

pub fn to_ida_style(&self) -> String

Converts pattern to IDA style string.

source

pub fn to_peid_style(&self) -> String

Converts pattern to PEID style string.

source

pub fn to_code_style(&self) -> (String, String)

Converts pattern to code style string, returing pattern and mask.

source

pub const fn matches(&self, data: &[u8]) -> bool

Checks if pattern matches byte slice.

let data = b"\x11\x22\x33";
let pat = ida_pat!("11 ? 33");
assert!(pat.matches(data));
source

pub const fn from_ida_style(pat: &'static str) -> Pattern<N>

Creates pattern from IDA style string.

// Pattern parsing is a contant call and happens at compile time.
let ida = ida_pat!("13 ? D1");
let data = b"\x13\x01\xD1";
assert!(ida.matches(data));
source

pub const fn from_peid_style(pat: &'static str) -> Pattern<N>

Creates pattern from PEID style string.

// Pattern parsing is a contant call and happens at compile time.
let peid = peid_pat!("13 ?? D1");
let data = b"\x13\x01\xD1";
assert!(peid.matches(data));
source

pub const fn from_code_style( pat: &'static [u8], mask: &'static str ) -> Pattern<N>

Creates pattern from code style strings.

let pat = code_pat!(b"\x11\x55\xE2", "x?x");
let data = b"\x11\x01\xE2";
assert!(pat.matches(data));

Trait Implementations§

source§

impl<const N: usize> Clone for Pattern<N>

source§

fn clone(&self) -> Pattern<N>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const N: usize> Debug for Pattern<N>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const N: usize> Hash for Pattern<N>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<const N: usize> Matcher for Pattern<N>

source§

fn matches(&self, seq: &[u8]) -> bool

Matches byte sequence agains the pattern
source§

fn len(&self) -> usize

Size of the pattern
source§

impl<const N: usize> PartialEq<Pattern<N>> for Pattern<N>

source§

fn eq(&self, other: &Pattern<N>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const N: usize> Copy for Pattern<N>

source§

impl<const N: usize> Eq for Pattern<N>

source§

impl<const N: usize> StructuralEq for Pattern<N>

source§

impl<const N: usize> StructuralPartialEq for Pattern<N>

Auto Trait Implementations§

§

impl<const N: usize> RefUnwindSafe for Pattern<N>

§

impl<const N: usize> Send for Pattern<N>

§

impl<const N: usize> Sync for Pattern<N>

§

impl<const N: usize> Unpin for Pattern<N>

§

impl<const N: usize> UnwindSafe for Pattern<N>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.