Merge pull request #16 from Idov31/master

[New example] API Hooking
This commit is contained in:
Thanasis Tserpelis
2022-05-01 16:11:50 +03:00
committed by GitHub
2 changed files with 46 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
[package]
name = "apihooking"
version = "0.1.0"
authors = ["Idov31 <github.com/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"
+32
View File
@@ -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();
}
}