forked from loongly/PureScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathil2cpp_support.c
More file actions
174 lines (136 loc) · 4.18 KB
/
il2cpp_support.c
File metadata and controls
174 lines (136 loc) · 4.18 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "il2cpp_support.h"
#ifdef _WIN32
#include <Windows.h>
#endif
#define log_error(cat, msg, ...)
#if !defined(_WIN32)
void init_il2cpp()
{
}
#else
#define DO_API(r, n, p) _##n n
#include "il2cpp-api-functions.h"
#undef DO_API
void init_il2cpp()
{
bool symbols_missing = FALSE;
void* libHandle = LoadLibraryA("GameAssembly.dll");
#define DO_API(r, n, p) \
n = (_##n)GetProcAddress(libHandle, #n); \
if (n == NULL) \
{ \
symbols_missing = TRUE; \
}
#include "il2cpp-api-functions.h"
#undef DO_API
if (symbols_missing)
{
log_error(LOG_DEFAULT, "Failed to load il2cpp");
}
//il2cpp_resolve_icall = (_il2cpp_resolve_icall)GetProcAddress(libHandle, "il2cpp_resolve_icall");
//void* icall = il2cpp_resolve_icall("UnityEngine.GameObject::CreatePrimitive");
}
#endif
Il2CppImage* il2cpp_get_image(const char* assembly)
{
Il2CppAssembly* mono_assembly = il2cpp_domain_assembly_open(il2cpp_domain_get(), assembly);
//MonoAssemblyName* asm_name = mono_assembly_name_new(assembly);
//MonoAssembly* mono_assembly = mono_assembly_loaded(asm_name);
//mono_assembly_name_free(asm_name);
return il2cpp_assembly_get_image(mono_assembly);
}
Il2CppClass* il2cpp_get_class(Il2CppImage* image, const char* _namespace, const char* name)
{
return il2cpp_class_from_name(image, _namespace, name);
}
Il2CppClass* il2cpp_search_class(const char* assembly, const char* _namespace,const char* name)
{
Il2CppImage* image = il2cpp_get_image(assembly);
Il2CppClass* klass = il2cpp_get_class(image, _namespace, name);
return klass;
}
char*
il2cpp_array_addr_with_size(Il2CppArray *array, int32_t size, uintptr_t idx)
{
const size_t kIl2CppSizeOfArray = 3 * sizeof(void*) + sizeof(uintptr_t);
return ((char*)array) + kIl2CppSizeOfArray + size * idx;
}
typedef struct MethodHead
{
Il2CppMethodPointer methodPtr;
}MethodHead;
Il2CppMethodPointer hook_method(const char* assembly, const char* _namespace, const char* name,const char* method,int32_t param_count, Il2CppMethodPointer hook)
{
Il2CppClass* klass = il2cpp_search_class(assembly, _namespace, name);
return hook_method2(klass, method, param_count, hook);
}
Il2CppMethodPointer hook_method2(Il2CppClass* klass, const char* method, int32_t param_count, Il2CppMethodPointer hook)
{
MethodInfo* info = il2cpp_class_get_method_from_name(klass, method, param_count);//
if (info == NULL)
{
return NULL;
}
MethodHead* mh = (MethodHead*)info;
Il2CppMethodPointer orign = mh->methodPtr;
mh->methodPtr = hook;
return orign;
}
Il2CppMethodPointer hook_icall_method(const char* method, Il2CppMethodPointer hook)
{
Il2CppMethodPointer orign = il2cpp_resolve_icall(method);
il2cpp_add_internal_call(method, hook);
//MethodInfo* info = il2cpp_class_get_method_from_name(klass, method, param_count);//
//if (info == NULL)
//{
// return NULL;
//}
//MethodHead* mh = (MethodHead*)info;
//Il2CppMethodPointer orign = mh->methodPtr;
//mh->methodPtr = hook;
return orign;
}
Il2CppMethodPointer il2cpp_get_native_method_ptr(Il2CppClass* klass, const char* method, int32_t param_count)
{
MethodInfo* info = il2cpp_class_get_method_from_name(klass, method, param_count);//
if (info == NULL)
{
return NULL;
}
MethodHead* mh = (MethodHead*)info;
Il2CppMethodPointer orign = mh->methodPtr;
return orign;
}
Il2CppClass* il2cpp_get_exception_class()
{
static Il2CppClass* klass = NULL;
if (klass == NULL)
{
klass = il2cpp_get_class(il2cpp_get_corlib(), "System", "Exception");
}
return klass;
}
Il2CppObject * il2cpp_exception_property(Il2CppObject *obj, const char *name, char is_virtual)
{
Il2CppObject *get = NULL;
Il2CppObject *get_virt = NULL;
Il2CppObject *exc = NULL;
get = il2cpp_class_get_method_from_name(il2cpp_get_exception_class(), name, 0);
if (get) {
if (is_virtual) {
get_virt = il2cpp_object_get_virtual_method(obj, get);
if (get_virt)
get = get_virt;
}
return (Il2CppObject *)il2cpp_runtime_invoke(get, obj, NULL, &exc);
}
return NULL;
}
Il2CppThread** il2cpp_get_all_threads(size_t* thread_count)
{
return il2cpp_thread_get_all_attached_threads(thread_count);
}
void il2cpp_set_thread_callback(ThreadAttachDetachCallback attach, ThreadAttachDetachCallback detach)
{
il2cpp_set_thread_attach_detach_callback(attach, detach);
}