Skip to main content

HookWriter

Struct HookWriter 

Source
pub struct HookWriter<'a, M: MemoryController, A: HookAssembler> { /* private fields */ }

Implementations§

Source§

impl HookWriter<'static, DefaultMemoryController, DefaultHookAssembler>

Source

pub const fn from_static() -> Self

Examples found in repository?
examples/write_hook_table.rs (line 27)
26fn main() {
27    let hook_writer = HookWriter::from_static();
28    let hook = unsafe {
29        hook_writer
30            .create_hook(
31                NonNull::new(add_two_numbers_together as *mut _).unwrap(),
32                NonNull::new(hook as *mut _).unwrap(),
33            )
34            .unwrap()
35    };
36
37    let HookData {
38        trampoline_data, ..
39    } = hook.data;
40
41    println!("about to run hook");
42
43    unsafe {
44        #[cfg(target_os = "linux")]
45        asm! {
46            "mov rdi, 6",
47            "mov rsi, 7",
48            "call {}",
49            in(reg)trampoline_data.as_ptr()
50        }
51        #[cfg(target_os = "windows")]
52        asm! {
53            "mov rcx, 6",
54            "mov rdx, 7",
55            "call {}",
56            in(reg)trampoline_data.as_ptr()
57        }
58    }
59}
Source§

impl<'a, M: MemoryController, A: HookAssembler> HookWriter<'a, M, A>

Source

pub const fn new(hook_heap: &'a HookHeap<M>, assembler: A) -> Self

Source

pub unsafe fn create_hook_by_name( &self, module: Option<&CStr>, symbol: &CStr, destination: *mut u8, ) -> Result<Hook<'a, M>>

Source

pub unsafe fn create_hook( &self, target: NonNull<c_void>, destination: NonNull<c_void>, ) -> Result<Hook<'a, M>>

Examples found in repository?
examples/write_hook_table.rs (lines 30-33)
26fn main() {
27    let hook_writer = HookWriter::from_static();
28    let hook = unsafe {
29        hook_writer
30            .create_hook(
31                NonNull::new(add_two_numbers_together as *mut _).unwrap(),
32                NonNull::new(hook as *mut _).unwrap(),
33            )
34            .unwrap()
35    };
36
37    let HookData {
38        trampoline_data, ..
39    } = hook.data;
40
41    println!("about to run hook");
42
43    unsafe {
44        #[cfg(target_os = "linux")]
45        asm! {
46            "mov rdi, 6",
47            "mov rsi, 7",
48            "call {}",
49            in(reg)trampoline_data.as_ptr()
50        }
51        #[cfg(target_os = "windows")]
52        asm! {
53            "mov rcx, 6",
54            "mov rdx, 7",
55            "call {}",
56            in(reg)trampoline_data.as_ptr()
57        }
58    }
59}
Source

pub unsafe fn write_hook_table( &self, target: NonNull<c_void>, destination_fn: NonNull<c_void>, ) -> Result<HookData<'a, M>>

Auto Trait Implementations§

§

impl<'a, M, A> Freeze for HookWriter<'a, M, A>
where A: Freeze,

§

impl<'a, M, A> RefUnwindSafe for HookWriter<'a, M, A>

§

impl<'a, M, A> Send for HookWriter<'a, M, A>
where A: Send, M: Sync,

§

impl<'a, M, A> Sync for HookWriter<'a, M, A>
where A: Sync, M: Sync,

§

impl<'a, M, A> Unpin for HookWriter<'a, M, A>
where A: Unpin,

§

impl<'a, M, A> UnsafeUnpin for HookWriter<'a, M, A>
where A: UnsafeUnpin,

§

impl<'a, M, A> UnwindSafe for HookWriter<'a, M, A>

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<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.