-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.h
39 lines (33 loc) · 1.14 KB
/
hook.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <stdio.h>
/**
* Opaque type containing hook metadata. Use it to revert hooks.
*/
typedef void* hook_t;
/**
* Install a hook that works by JMP-ing to the new implementation.
* This is handy for hooking existing functions, override their first bytes by a
* JMP and all the arguments will still be on the stack/in registries. C
* functions can just be used (with appropriate calling convention) as if they
* were called directly by the application.
*/
hook_t install_jmphook(void* orig_address, void* hook_address);
/**
* Install a hook that works by CALL-ing to the new implementation.
* Handy for hooking existing CALL-sites, overriding essentially just the
* address.
*/
hook_t install_callhook(void* orig_address, void* hook_address);
/**
* Install a hook that works by overriding a pointer in a vtable.
* Handy for hooking class methods.
*/
hook_t install_vtblhook(void* orig_address, void* hook_address);
/**
* Overwrite some arbitrary bytes, not necessarily a call/jmp/vtbl hook.
*/
hook_t install_bytes(void* orig_address, void* buffer, size_t buf_size);
/**
* Revert an existing hook.
*/
void revert_hook(hook_t hook);