Struct detour::RawDetour[][src]

pub struct RawDetour(_);

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

impl RawDetour[src]

pub unsafe fn new(target: *const (), detour: *const ()) -> Result<Self>[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.

pub unsafe fn enable(&self) -> Result<()>[src]

Enables the detour.

pub unsafe fn disable(&self) -> Result<()>[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, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.