-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.cpp
64 lines (58 loc) · 1.58 KB
/
example.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <optional>
#include <cstdio>
#include <uwhook.hpp>
__declspec(noinline) // Will not hook inlined functions
void actual_test0(int a) {
printf("actual_test0(%d) called\n", a);
fflush(stdout);
}
__declspec(noinline)
void actual_test1(int a) {
printf("actual_test1(%d) called\n", a);
fflush(stdout);
}
std::optional<UWHook> hook0, hook1;
void test_hook0(int a) {
printf("test_hook0(%d) called\n", a);
fflush(stdout);
}
void test_hook1(int a) {
printf("test_hook1(%d) called\n", a);
fflush(stdout);
UWHookRelease HR(hook0.value());
auto actual_fnc = hook0->getFunction<void (int)>();
actual_fnc(a*2);
}
#ifdef UWHOOK_TRAMPOLINE_SUPPORT
void test_hook2(int a) {
printf("test_hook2(%d) called instead of function at 0x%p\n", a, UWHook::getTrampolineCaller());
fflush(stdout);
UWHookRelease HR(hook0.value());
hook0->getFunction<void (int)>()(a);
}
UWHOOK_TRAMPOLINE(test_hook2)
#endif
int main() {
printf("actual_test0 is at 0x%p\n", actual_test0);
printf("actual_test1 is at 0x%p\n", actual_test1);
printf("\n");
actual_test0(1);
printf("\n");
hook0.emplace(actual_test0, test_hook0);
actual_test0(2);
printf("\n");
hook0.emplace(actual_test0, test_hook1);
actual_test0(3);
printf("\n");
#ifdef UWHOOK_TRAMPOLINE_SUPPORT
hook0.emplace(actual_test0, uwHookTrampoline_test_hook2, true);
hook1.emplace(actual_test1, uwHookTrampoline_test_hook2, true);
actual_test0(4);
printf("\n");
actual_test1(4);
printf("\n");
actual_test1(5);
printf("\n");
#endif
puts("End");
}