1 个不稳定版本
0.1.0 | 2021 年 8 月 1 日 |
---|
#53 in #64-bit
15KB
235 行
trampoline
trampoline
是一个支持 32 位和 64 位的函数钩子库。
操作系统支持
操作系统 | 架构 |
---|---|
Windows | x32, x64 |
许可协议
本项目遵循 MIT 许可协议 (LICENSE-MIT)
lib.rs
:
trampoline - 一个支持 32 位和 64 位的函数钩子 Rust 库。
示例
[dependencies]
windows = "0.18.0"
once_cell = "1.8.0"
trampoline = "0.1.0"
[build-dependencies]
windows = "0.18.0"
fn main() {
windows::build!(
Windows::Win32::Foundation::{HANDLE, BOOL},
Windows::Win32::System::LibraryLoader::{GetProcAddress, GetModuleHandleA},
);
}
use crate::bindings::Windows::Win32::Foundation::{HANDLE, BOOL};
use crate::bindings::Windows::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
use std::ffi::c_void;
use std::sync::Mutex;
use std::mem::transmute;
use once_cell::sync::Lazy;
use trampoline::TrampolineHook;
mod bindings {
windows::include_bindings!();
}
static HOOK: Lazy<Mutex<Option<TrampolineHook>>> = Lazy::new(|| {
Mutex::new(None)
});
pub extern "stdcall" fn wgl_swap_buffers(hdc: HANDLE) -> BOOL {
let gateway = HOOK
.lock()
.unwrap()
.as_ref()
.unwrap()
.gateway();
let gateway_call: extern "stdcall" fn(hdc: HANDLE) -> BOOL;
gateway_call = unsafe { transmute(gateway) };
gateway_call(hdc);
BOOL::from(true)
}
fn main() {
let module = unsafe { GetModuleHandleA("opengl32.dll") };
let src_wgl_swap_buffers = unsafe {
GetProcAddress(module, "wglSwapBuffers")
}.unwrap();
let hook = TrampolineHook::hook(
src_wgl_swap_buffers as *mut c_void,
wgl_swap_buffers as *mut c_void,
21
).unwrap();
*HOOK
.lock()
.unwrap() = Some(hook);
}
依赖
~123MB
~2M SLoC