API Hooking - Detours I
Theory
Detours
// FUNCTION TYPE DEFINITION
type fn_OpenProcess = unsafe extern "system" fn(u32, BOOL, u32) -> HANDLE;
// DEFINING OUR HOOK
static hook_OpenProcess: Lazy<GenericDetour<fn_OpenProcess>> = Lazy::new(|| unsafe {
let addr = get_module_symbol_address("Kernel32.dll", "OpenProcess").unwrap();
let og: fn_OpenProcess = std::mem::transmute(addr);
GenericDetour::new(og, custom_OpenProcess).unwrap()
});
// CUSTOM OpenProcess API
unsafe extern "system" fn custom_OpenProcess(dwDesiredAccess: u32, bInheritHandle: BOOL, dwProcessId: u32) -> HANDLE {
println!("\n####### [ OpenProcess ] ########\n");
let access = get_process_flags(dwDesiredAccess);
println!("[*] PID: {}", dwProcessId);
// println!("[*] Access: 0x{:X}", dwDesiredAccess);
println!("[*] Access: {}", access);
println!("\n####### ############### ########\n");
hook_OpenProcess.disable().unwrap();
let result = hook_OpenProcess.call(dwDesiredAccess, bInheritHandle, dwProcessId);
hook_OpenProcess.enable().unwrap();
result
}
References
Last updated