#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
mod detours;
include!("detours.rs");
#[cfg(test)]
mod tests {
use windows::Win32::System::Threading::{GetCurrentThread, Sleep};
use super::*;
use std::ffi::c_void;
use std::time::Instant;
fn sleep_hook(ms: u32) {
println!("Not sleeping {}ms yet!", ms);
}
#[test]
fn attach_sleep() {
unsafe {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
let c_fn_ptr = &mut (Sleep as unsafe fn(_) -> _ as *mut c_void);
DetourAttach(
c_fn_ptr,
sleep_hook as fn(_) -> _ as *mut c_void,
);
DetourTransactionCommit();
let start = Instant::now();
Sleep(10_000u32);
let duration = start.elapsed();
assert!(duration.as_secs() < 10_000);
}
}
}