https://github.com/soratenshi/zig-bait
A Zig Hooking Library
https://github.com/soratenshi/zig-bait
hooking-library vmt-hooking
Last synced: 2 months ago
JSON representation
A Zig Hooking Library
- Host: GitHub
- URL: https://github.com/soratenshi/zig-bait
- Owner: SoraTenshi
- License: mit
- Created: 2023-05-10T22:27:34.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-09T00:41:02.000Z (3 months ago)
- Last Synced: 2025-04-10T23:28:28.304Z (2 months ago)
- Topics: hooking-library, vmt-hooking
- Language: Zig
- Homepage:
- Size: 176 KB
- Stars: 16
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

A native Hooking library with support for all common hooking mechanisms.
Detour & IAT hooks are not yet supported, but VMT are fully implemented.If you have any ideas for how to automatically test this library, please let me know, considering
ASLR and the difference in possible multiple Compilers, i am not really sure how to effectively assure
this.## Usage:
### Install:
In your project just add the dependency to your Zig dependencies: `zig fetch --save https://github.com/SoraTenshi/zig-bait/archive/main.tar.gz`And then in your `build.zig`:
```zig
const bait = b.dependency("zig_bait", .{});your_project.root_module.addImport("bait", bait.module("zig-bait"));
```### Using in your Project:
1. Make sure that your target uses the C calling convention. Implicitly `fastcall`, `stdcall` and all the ones
defined within Zig are supported.```zig
// ...
const bait = @import("bait");
const HookManager = @import("bait").HookManager;var hook_manager: HookManager = undefined;
fn hooked(abc: usize) callconv(.C) void {
const original = hook_manager.getOriginalFunction(&hooked).?;std.debug.print("I am hooked {s}\n", .{ "on you ;)" });
original(abc);
}pub fn main() !void {
const alloc = std.heap.page_allocator;
hook_manager = HookManager.init(alloc);
defer hook_manager.deinit();const victim_vtable: usize = @intFromPtr(getSymbolByName("your_target_func"));
try hook_manager.append(
bait.Method{
.vmt = .{
.object_address = victim_table,
.positions = &.{ 1 },
.targets = &.{ @intFromPtr(&hooked) },
}
}
);
try hook_manager.hookAll()
}
```