forked from actboy168/lua-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththunk.cpp
More file actions
36 lines (30 loc) · 826 Bytes
/
thunk.cpp
File metadata and controls
36 lines (30 loc) · 826 Bytes
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
#include "thunk/thunk.cpp"
#include <assert.h>
struct HHI {
int a = 0x1;
};
int add(HHI* h, void* a, void* b) {
h->a = 2;
assert(a == (void*)0x1);
assert(b == (void*)0x2);
return 1;
}
void* add1(HHI* h, void* a, size_t b, size_t c) {
h->a = 3;
assert(a == (void*)0x1);
assert(b == 2);
assert(c == 3);
return (void*)4;
}
int main() {
HHI hhi;
auto* thunk = thunk_create_hook((intptr_t)&hhi, (intptr_t)&add);
int ret = ((int (*)(void* a, void* b))thunk->data)((void*)0x1, (void*)0x2);
assert(hhi.a == 2);
assert(ret == 1);
auto* thunk1 = thunk_create_allocf((intptr_t)&hhi, (intptr_t)&add1);
auto ret1 = ((void* (*)(void* a, size_t b, size_t c))thunk1->data)((void*)0x1, 2, 3);
assert(hhi.a == 3);
assert(ret1 == (void*)4);
return 0;
}