xxhertz/zig-vmt-hook
A VMT hook implementation in Zig. Works on x64 and x86 architectures. Windows only.
master
// Fetch the library via `zig fetch --save=vmthook git+https://github.com/xxhertz/zig-vmt-hook#main`
// build.zig
const vmthook_dep = b.dependency("vmthook", .{});
// for dll/lib
lib.root_module.addImport("vmthook", vmthook_dep.module("hooking"));
// for exe
exe.addImport("vmthook", vmthook_dep.module("hooking"));
// for modules
exe.addImport("vmthook", vmthook_dep.module("hooking"));
// Import the library
const hooking = @import("vmthook");
// Initialize the library at runtime
hooking.init(allocator);
// Hook a function
original_func = @ptrCast(hooking.virtual_hook(vtable, 10, &hook));
// Release all hooks
hooking.deinit();
This works for both x86 and x64, you can see examples in my recent projects: