use crate::arch::Detour;
use crate::error::Result;
use crate::{Function, HookableWith};
use std::marker::PhantomData;
#[derive(Debug)]
pub struct GenericDetour<T: Function> {
phantom: PhantomData<T>,
detour: Detour,
}
impl<T: Function> GenericDetour<T> {
pub unsafe fn new<D>(target: T, detour: D) -> Result<Self>
where
T: HookableWith<D>,
D: Function,
{
Detour::new(target.to_ptr(), detour.to_ptr()).map(|detour| GenericDetour {
phantom: PhantomData,
detour,
})
}
pub unsafe fn enable(&self) -> Result<()> {
self.detour.enable()
}
pub unsafe fn disable(&self) -> Result<()> {
self.detour.disable()
}
pub fn is_enabled(&self) -> bool {
self.detour.is_enabled()
}
pub(crate) fn trampoline(&self) -> &() {
self.detour.trampoline()
}
}
unsafe impl<T: Function> Send for GenericDetour<T> {}
unsafe impl<T: Function> Sync for GenericDetour<T> {}