-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsubstrate.h
59 lines (45 loc) · 1.52 KB
/
substrate.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef SUBSTRATE_H_
#define SUBSTRATE_H_
extern "C" {
#include <mach-o/nlist.h>
}
#include <objc/runtime.h>
#include <dlfcn.h>
#ifdef __cplusplus
extern "C" {
#endif
void MSHookFunction(void *symbol, void *replace, void **result);
void MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
template <typename Type_>
static inline void MSHookFunction(Type_ *symbol, Type_ *replace, Type_ **result) {
return MSHookFunction(
reinterpret_cast<void *>(symbol),
reinterpret_cast<void *>(replace),
reinterpret_cast<void **>(result)
);
}
template <typename Type_>
static inline void MSHookFunction(Type_ *symbol, Type_ *replace) {
return MSHookFunction(symbol, replace, reinterpret_cast<Type_ **>(NULL));
}
template <typename Type_>
static inline void MSHookSymbol(Type_ *&value, const char *name, void *handle) {
value = reinterpret_cast<Type_ *>(dlsym(handle, name));
}
template <typename Type_>
static inline Type_ &MSHookIvar(id self, const char *name) {
Ivar ivar(class_getInstanceVariable([self class], name));
void *pointer(ivar == NULL ? NULL : reinterpret_cast<char *>(self) + ivar_getOffset(ivar));
return *reinterpret_cast<Type_ *>(pointer);
}
#endif
#define MSHook(type, name, args...) \
static type (*_ ## name)(args); \
static type $ ## name(args)
#define Foundation "/System/Library/Frameworks/Foundation.framework/Foundation"
#define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
#endif//SUBSTRATE_H_