Skip to main content

Pattern

Struct Pattern 

Source
pub struct Pattern { /* private fields */ }
Expand description

A byte pattern to find, where to look for it, and how to get from the match to the address wanted.

See the module docs for the syntax.

§Examples

use imping_hook::scan::Pattern;

// The match starts four bytes into the function.
let function = Pattern::new("48 83 EC 20 33 DB").offset(-4).find()?;
// The function called at the match, in another module.
let callee = Pattern::new("E8 ?? ?? ?? ?? 48 8B D8")
    .in_module("engine.dll")
    .follow_call()
    .find()?;

Implementations§

Source§

impl Pattern

Source

pub fn new(pattern: &str) -> Self

Creates a pattern to find in the main module, such as "48 89 5C 24 ?? 57".

It’s parsed by find.

Source

pub fn in_module(self, module: &str) -> Self

Searches a loaded module such as "engine.dll" instead of the main module.

Source

pub fn offset(self, bytes: isize) -> Self

Moves the address this many bytes on from the start of the match, or back for a negative count.

Source

pub fn follow_call(self) -> Self

Follows the call or jmp at the address to where it goes.

For a pattern that matches a call site rather than the function itself. The pattern must spell out the instruction’s E8 (call) or E9 (jmp) opcode at the offset, and cover its 4-byte displacement, which may be wildcards: "E8 ?? ?? ?? ?? 48 8B D8".

Source

pub fn find(&self) -> Result<*const ()>

Finds the one place the pattern matches and returns the address it leads to.

The module must stay loaded while it’s searched.

§Errors

Trait Implementations§

Source§

impl Clone for Pattern

Source§

fn clone(&self) -> Pattern

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Pattern

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.