You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/6.plugins/3.polyhook/3.guide.md
+235-2Lines changed: 235 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,239 @@ description: A detailed guide on how to use the plugin effectively, ensuring you
4
4
icon: lucide:book-open-text
5
5
---
6
6
7
+
## Hooking C/C++ Functions Dynamically in Any Language
8
+
9
+
It is a plugin that enables dynamic runtime hooking of C++ functions — including both **virtual function table (vtable)** hooks and **code detour** hooks. It’s based on the powerful [polyhook2](https://github.com/stevemk14ebr/PolyHook_2_0) backend and is designed to be easily integrated into your plugin or scripting environment.
10
+
11
+
This guide covers:
12
+
13
+
- Hooking detour (raw function address) functions
14
+
- Hooking virtual functions (by index or by function pointer)
15
+
- Registering pre- and post-callbacks
16
+
- Inspecting and modifying function arguments and return values
17
+
- Unhooking and managing callbacks
18
+
19
+
---
20
+
21
+
## Basic Concepts
22
+
23
+
### What is a Hook?
24
+
25
+
A **hook** is a method to intercept function calls. You can:
26
+
27
+
- Inspect/modify function arguments before the call (**pre**)
28
+
- Observe/alter return value after the call (**post**)
29
+
- Override or entirely skip the original function (**supercede**)
30
+
31
+
### Types of Hooks
32
+
33
+
-`HookDetour`: Hooks a standalone or static function.
34
+
-`HookVirtual`: Hooks a class method via vtable index or function pointer.
35
+
36
+
---
37
+
38
+
## Data Types
39
+
40
+
Use `DataType` enum to describe argument and return types:
41
+
42
+
```
43
+
enum class DataType : uint8_t {
44
+
Void, Bool, Int8, UInt8, Int16, UInt16,
45
+
Int32, UInt32, Int64, UInt64,
46
+
Float, Double, Pointer, String
47
+
};
48
+
```
49
+
50
+
Use these consistently when describing function signatures to the hook APIs.
51
+
52
+
---
53
+
54
+
## Hooking Functions
55
+
56
+
### 1. Detour Hook
57
+
58
+
Use `HookDetour` to hook a global/static function:
59
+
60
+
```
61
+
Callback* HookDetour(void* pFunc, DataType returnType, const plg::vector<DataType>& args, int varIndex);
62
+
```
63
+
64
+
-`pFunc`: Pointer to the function to hook.
65
+
-`returnType`: Return type using `DataType`.
66
+
-`args`: List of argument types.
67
+
-`varIndex`: Use `-1` for normal calls; set if variable argument.
Getting the vtable index requires knowledge of the class layout and may not be portable across different compilers or platforms. Use with caution, works only if using C++ or C-like languages.
| Get Addresses |`GetFunctionAddr`, `GetOriginalAddr`|
239
+
240
+
---
241
+
242
+
Use this guide as a reference when developing with your PolyHook-based plugin. Always validate pointer arguments and ensure type safety when casting arguments or return values.
0 commit comments