diff --git a/apihooking/Cargo.toml b/apihooking/Cargo.toml new file mode 100644 index 0000000..67d91ea --- /dev/null +++ b/apihooking/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "apihooking" +version = "0.1.0" +authors = ["Idov31 "] +edition = "2021" + +[[bin]] +name = "apihooking" +path = "src/main.rs" + +[dependencies] +winapi = {version = "0.3.9", features = ["winuser"]} +win32-error = "0.9.0" +detour = "0.8.1" \ No newline at end of file diff --git a/apihooking/src/main.rs b/apihooking/src/main.rs new file mode 100644 index 0000000..a82586c --- /dev/null +++ b/apihooking/src/main.rs @@ -0,0 +1,32 @@ +use std::ffi::CString; +use winapi::{ + um::{ + winuser::MessageBoxA, + }, + shared::{ + windef::HWND, + minwindef::{ + UINT + }, + ntdef::LPCSTR + } +}; +use detour::static_detour; + +static_detour! { + static MsgBox: unsafe extern "system" fn(HWND, LPCSTR, LPCSTR, UINT) -> i32; +} + + +fn main() { + unsafe { + MsgBox.initialize(MessageBoxA, |hwnd, lp_text, lp_caption, u_type| { + println!("Hooked MessageBoxA"); + MsgBox.call(hwnd, lp_text, lp_caption, u_type) + }); + MessageBoxA(0 as HWND, CString::new("Before").unwrap().as_ptr(), CString::new("Before").unwrap().as_ptr(), 0); + MsgBox.enable(); + MessageBoxA(0 as HWND, CString::new("After").unwrap().as_ptr(), CString::new("After").unwrap().as_ptr(), 0); + MsgBox.disable(); + } +}