forked from rileytestut/N64iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubstrate.h
75 lines (59 loc) · 1.97 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef SUBSTRATE_H_
#define SUBSTRATE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <mach-o/nlist.h>
#ifdef __cplusplus
}
#endif
#include <objc/runtime.h>
#include <dlfcn.h>
#ifdef __cplusplus
#define _default(value) = value
#else
#define _default(value)
#endif
#ifdef __cplusplus
extern "C" {
#endif
void MSHookFunction(void *symbol, void *replace, void **result);
IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL));
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
template <typename Type_>
static inline Type_ *MSHookMessage(Class _class, SEL sel, Type_ *imp, const char *prefix = NULL) {
return reinterpret_cast<Type_ *>(MSHookMessage(_class, sel, reinterpret_cast<IMP>(imp), prefix));
}
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_f "/System/Library/Frameworks/Foundation.framework/Foundation"
#define UIKit_f "/System/Library/Frameworks/UIKit.framework/UIKit"
#define IOKit_f "/System/Library/Frameworks/IOKit.framework/IOKit"
#endif//SUBSTRATE_H_