Skip to main content

MacroHook

Struct MacroHook 

Source
pub struct MacroHook(/* private fields */);

Methods from Deref<Target = Hook<'static>>§

Source

pub unsafe fn apply_hook(&mut self) -> Result<()>

Examples found in repository?
examples/hook_puts.rs (line 28)
24fn main() {
25    let mut hook = unsafe { Hook::by_name(None, c"puts", hooked_puts as *mut u8).unwrap() };
26
27    unsafe {
28        hook.apply_hook().unwrap();
29    }
30
31    #[cfg(target_os = "linux")]
32    unsafe {
33        libc::puts(c"Am i hooked?".as_ptr());
34    }
35}
More examples
Hide additional examples
examples/hook_msgboxa.rs (line 55)
42fn main() {
43    let mut hook = unsafe {
44        Hook::by_name(
45            Some(c"user32.dll"),
46            c"MessageBoxA",
47            hook_destination as *mut _,
48        )
49        .unwrap()
50    };
51
52    println!("Applying hook");
53
54    unsafe {
55        hook.apply_hook().unwrap();
56        MessageBoxA(
57            std::ptr::null_mut(),
58            c"Am i hooked?".as_ptr(),
59            c"hooked-rs".as_ptr(),
60            0,
61        );
62    }
63
64    unsafe {
65        hook.remove_hook().unwrap();
66        MessageBoxA(
67            std::ptr::null_mut(),
68            c"Not hooked anymore".as_ptr(),
69            c"hooked-rs".as_ptr(),
70            0,
71        );
72    }
73}
Source

pub unsafe fn remove_hook(&mut self) -> Result<()>

Examples found in repository?
examples/hook_msgboxa.rs (line 65)
42fn main() {
43    let mut hook = unsafe {
44        Hook::by_name(
45            Some(c"user32.dll"),
46            c"MessageBoxA",
47            hook_destination as *mut _,
48        )
49        .unwrap()
50    };
51
52    println!("Applying hook");
53
54    unsafe {
55        hook.apply_hook().unwrap();
56        MessageBoxA(
57            std::ptr::null_mut(),
58            c"Am i hooked?".as_ptr(),
59            c"hooked-rs".as_ptr(),
60            0,
61        );
62    }
63
64    unsafe {
65        hook.remove_hook().unwrap();
66        MessageBoxA(
67            std::ptr::null_mut(),
68            c"Not hooked anymore".as_ptr(),
69            c"hooked-rs".as_ptr(),
70            0,
71        );
72    }
73}

Trait Implementations§

Source§

impl Debug for MacroHook

Source§

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

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

impl Deref for MacroHook

Source§

type Target = Hook<'static>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for MacroHook

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Send for MacroHook

Source§

impl Sync for MacroHook

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.