Struct detour::RawDetour
[−]
[src]
pub struct RawDetour(_);
A type-less wrapper around 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 ()).unwrap() }; assert_eq!(add5(5), 10); assert_eq!(hook.is_enabled(), false); unsafe { hook.enable().unwrap(); assert!(hook.is_enabled()); let original: fn(i32) -> i32 = mem::transmute(hook.trampoline()); assert_eq!(add5(5), 15); assert_eq!(original(5), 10); hook.disable().unwrap(); } assert_eq!(add5(5), 10);
Methods
impl RawDetour
[src]
pub unsafe fn new(target: *const (), detour: *const ()) -> Result<Self, Error>
[src]
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.
Methods from Deref<Target = Detour>
pub unsafe fn toggle(&mut self, enabled: bool) -> Result<(), Error>
[src]
Enables or disables the detour.
pub unsafe fn enable(&mut self) -> Result<(), Error>
[src]
Enables the detour.
pub unsafe fn disable(&mut self) -> Result<(), Error>
[src]
Disables the detour.
pub fn is_enabled(&self) -> bool
[src]
Returns whether the detour is enabled or not.
pub fn trampoline(&self) -> &()
[src]
Returns a reference to the generated trampoline.
Trait Implementations
impl Debug for RawDetour
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Deref for RawDetour
[src]
type Target = Detour
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
Dereferences the value.