-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcutils.h
More file actions
91 lines (68 loc) · 3.03 KB
/
cutils.h
File metadata and controls
91 lines (68 loc) · 3.03 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef MODLOADER_CUTILS_H
#define MODLOADER_CUTILS_H
#include <modloader/hook.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#ifndef RTLD_DEFAULT
#define RTLD_DEFAULT NULL
#endif
#define SYM(sym) \
dlsym(RTLD_DEFAULT, sym)
#define SYMCALL(sym, func_proto, ...) \
((func_proto) \
(SYM(sym))) \
(__VA_ARGS__)
#define VIRTUAL_CALL(ptr, func_proto, ...) \
((func_proto) \
((void *)ptr)) \
(__VA_ARGS__)
#define DEREFERENCE(type, ptr, offset) \
(*(type*)((uintptr_t)ptr + offset))
#define REFERENCE(type, ptr, offset) \
(type*)((uintptr_t)ptr + offset)
// for uintptr_t
#define PTR_OFFSET(ptr, offset) \
((uintptr_t)ptr + offset)
#define THOOK(name, ret_type, sym, ...) \
typedef ret_type (*_##name##_t)(__VA_ARGS__); \
ret_type _detour_##name(__VA_ARGS__); \
void _install_##name(void) __attribute__((constructor));\
void _destroy_##name(void); \
\
struct _##name { \
modloader_hook_t *hook; \
_##name##_t detour; \
_##name##_t original; \
void (*install)(void); \
void (*destroy)(void); \
} name = {NULL, _detour_##name, NULL, \
_install_##name, _destroy_##name}; \
\
void _install_##name(void) \
{ \
name.hook = modloader_hook(SYM(sym), \
name.detour, \
(void**)&name.original); \
} \
\
void _destroy_##name(void) \
{ \
modloader_destroy_hook(name.hook); \
} \
\
ret_type _detour_##name(__VA_ARGS__)
#ifdef __cplusplus
extern "C" {
#endif
// void *sstr = std::string::basic_string(const char *c_str)
void std_string_string(void **sstr, const char *c_str);
// std::string::c_str()
const char *std_string_c_str(void *sstr);
// std::string::~basic_string()
void std_string_destroy(void *sstr, bool should_free);
#ifdef __cplusplus
}
#endif
#endif