pub struct RawDetour(_);
Expand description
A raw detour.
Example
use detour::RawDetour;
use std::mem;
fn add5(val: i32) -> i32 {
val + 5
}
fn add10(val: i32) -> i32 {
val + 10
}
let mut hook = unsafe { RawDetour::new(add5 as *const (), add10 as *const ())? };
assert_eq!(add5(5), 10);
assert_eq!(hook.is_enabled(), false);
unsafe { hook.enable()? };
assert!(hook.is_enabled());
let original: fn(i32) -> i32 = unsafe { mem::transmute(hook.trampoline()) };
assert_eq!(add5(5), 15);
assert_eq!(original(5), 10);
unsafe { hook.disable()? };
assert_eq!(add5(5), 10);
Implementations
sourceimpl RawDetour
impl RawDetour
sourcepub unsafe fn new(target: *const (), detour: *const ()) -> Result<Self>
pub unsafe fn new(target: *const (), detour: *const ()) -> Result<Self>
Constructs a new inline detour patcher.
The hook is disabled by default. Even when this function is succesful, there is no guaranteee that the detour function will actually get called when the target function gets called. An invocation of the target function might for example get inlined in which case it is impossible to hook at runtime.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns whether the detour is enabled or not.
sourcepub fn trampoline(&self) -> &()
pub fn trampoline(&self) -> &()
Returns a reference to the generated trampoline.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for RawDetour
impl Send for RawDetour
impl Sync for RawDetour
impl Unpin for RawDetour
impl !UnwindSafe for RawDetour
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more