This repository has been archived by the owner on Sep 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathil2cpp-mono-api.cpp
1693 lines (1395 loc) · 46.3 KB
/
il2cpp-mono-api.cpp
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file implements the Mono embedding API that the debugger code requires.
// It should not include any Mono headers.
#include "il2cpp-config.h"
#include "il2cpp-api.h"
#include "il2cpp-mono-api.h"
#include "il2cpp-class-internals.h"
#include "gc/GCHandle.h"
#include "gc/WriteBarrier.h"
#include "metadata/GenericMetadata.h"
#include "vm/Assembly.h"
#include "vm/Class.h"
#include "vm/Domain.h"
#include "vm/Field.h"
#include "vm/GenericClass.h"
#include "vm/GenericContainer.h"
#include "vm/Image.h"
#include "vm/MetadataCache.h"
#include "vm/Method.h"
#include "vm/Object.h"
#include "vm/Property.h"
#include "vm/Reflection.h"
#include "vm/Runtime.h"
#include "vm/String.h"
#include "vm/Thread.h"
#include "vm/ThreadPoolMs.h"
#include "vm/Type.h"
#include "vm-utils/Debugger.h"
#include "utils/Il2CppHashMap.h"
#include "utils/Memory.h"
#include <cstring>
#if IL2CPP_TARGET_XBOXONE
#define strdup _strdup
#endif
// These types must match the layout of types defined in Mono headers
struct Il2CppGPtrArray
{
void** pdata;
uint32_t len;
};
struct Il2CppGPtrArrayPriv
{
void** pdata;
uint32_t len;
uint32_t size;
};
struct Il2CppMonoError
{
unsigned short error_code;
unsigned short flags;
void *hidden_1[12];
};
struct Il2CppMonoMethodSignature
{
Il2CppType *ret;
uint16_t param_count;
int16_t sentinalpos_unused;
uint32_t generic_param_count : 16;
uint32_t call_convention_unused : 6;
uint32_t hasthis : 1;
uint32_t explicit_this_unused : 1;
uint32_t pinvoke_unused : 1;
uint32_t is_inflated_unused : 1;
uint32_t has_type_parameters_unused : 1;
Il2CppType* params[IL2CPP_ZERO_LEN_ARRAY];
};
struct Il2CppMonoMethodHeader
{
const unsigned char* code_unused;
uint32_t code_size;
uint16_t max_stack_unused : 15;
uint32_t is_transient_unsued : 1;
uint32_t num_clauses_unused : 15;
uint32_t init_locals_unused : 1;
uint16_t num_locals;
void* clauses_unused; // Actually a MonoExceptionClause in Mono,but we don't use it
Il2CppType* locals[IL2CPP_ZERO_LEN_ARRAY];
};
struct Il2CppMonoDebugCodeBlock
{
int32_t parent;
int32_t type;
int32_t start_offset;
int32_t end_offset;
};
struct Il2CppMonoDebugLocalVar
{
char *name;
int32_t index;
Il2CppMonoDebugCodeBlock *block;
};
struct Il2CppMonoDebugLocalsInfo
{
int32_t num_locals;
Il2CppMonoDebugLocalVar *locals;
int32_t num_blocks;
Il2CppMonoDebugCodeBlock *code_blocks;
};
struct Il2CppMonoDebugLineNumberEntry
{
uint32_t il_offset;
uint32_t native_offset;
};
struct Il2CppMonoDebugVarInfo
{
uint32_t index;
uint32_t offset;
uint32_t size;
uint32_t begin_scope;
uint32_t end_scope;
Il2CppType *type;
};
struct Il2CppMonoDebugMethodJitInfo
{
const uint8_t *code_start;
uint32_t code_size;
uint32_t prologue_end;
uint32_t epilogue_begin;
const uint8_t *wrapper_addr;
uint32_t num_line_numbers;
Il2CppMonoDebugLineNumberEntry *line_numbers;
uint32_t has_var_info;
uint32_t num_params;
Il2CppMonoDebugVarInfo *this_var;
Il2CppMonoDebugVarInfo *params;
uint32_t num_locals;
Il2CppMonoDebugVarInfo *locals;
Il2CppMonoDebugVarInfo *gsharedvt_info_var;
Il2CppMonoDebugVarInfo *gsharedvt_locals_var;
};
enum
{
BFLAGS_IgnoreCase = 1,
BFLAGS_DeclaredOnly = 2,
BFLAGS_Instance = 4,
BFLAGS_Static = 8,
BFLAGS_Public = 0x10,
BFLAGS_NonPublic = 0x20,
BFLAGS_FlattenHierarchy = 0x40,
BFLAGS_InvokeMethod = 0x100,
BFLAGS_CreateInstance = 0x200,
BFLAGS_GetField = 0x400,
BFLAGS_SetField = 0x800,
BFLAGS_GetProperty = 0x1000,
BFLAGS_SetProperty = 0x2000,
BFLAGS_ExactBinding = 0x10000,
BFLAGS_SuppressChangeType = 0x20000,
BFLAGS_OptionalParamBinding = 0x40000
};
struct Il2CppMonoTypeNameParse
{
char *name_space_unused;
char *name_unused;
Il2CppAssemblyName assembly;
void *il2cppTypeNameParseInfo; // really GList *modifiers, but IL2CPP re-uses this field
void *type_arguments_unused;
void *nested_unused;
};
struct Il2CppMonoJitExceptionInfo
{
uint32_t flags;
int32_t exvar_offset;
void* try_start;
void* try_end;
void* handler_start;
/*
* For LLVM compiled code, this is the index of the il clause
* associated with this handler.
*/
int clause_index;
uint32_t try_offset;
uint32_t try_len;
uint32_t handler_offset;
uint32_t handler_len;
union
{
MonoClass *catch_class;
void* filter;
void* handler_end;
} data;
};
struct Il2CppMonoJitInfo
{
/* NOTE: These first two elements (method and
next_jit_code_hash) must be in the same order and at the
same offset as in RuntimeMethod, because of the jit_code_hash
internal hash table in MonoDomain. */
union
{
MonoMethod *method;
MonoImage *image;
void* aot_info;
void* tramp_info;
} d;
union
{
void *next_jit_code_hash;
void *next_tombstone;
} n;
void* code_start;
uint32_t unwind_info;
int code_size;
uint32_t num_clauses : 15;
/* Whenever the code is domain neutral or 'shared' */
int32_t domain_neutral : 1;
int32_t has_generic_jit_info : 1;
int32_t has_try_block_holes : 1;
int32_t has_arch_eh_info : 1;
int32_t has_thunk_info : 1;
int32_t has_unwind_info : 1;
int32_t from_aot : 1;
int32_t from_llvm : 1;
int32_t dbg_attrs_inited : 1;
int32_t dbg_hidden : 1;
/* Whenever this jit info was loaded in async context */
int32_t async : 1;
int32_t dbg_step_through : 1;
int32_t dbg_non_user_code : 1;
/*
* Whenever this jit info refers to a trampoline.
* d.tramp_info contains additional data in this case.
*/
int32_t is_trampoline : 1;
/* Whenever this jit info refers to an interpreter method */
int32_t is_interp : 1;
/* FIXME: Embed this after the structure later*/
void* gc_info; /* Currently only used by SGen */
Il2CppMonoJitExceptionInfo clauses[IL2CPP_ZERO_LEN_ARRAY];
/* There is an optional MonoGenericJitInfo after the clauses */
/* There is an optional MonoTryBlockHoleTableJitInfo after MonoGenericJitInfo clauses*/
/* There is an optional MonoArchEHJitInfo after MonoTryBlockHoleTableJitInfo */
/* There is an optional MonoThunkJitInfo after MonoArchEHJitInfo */
};
// End of mirrored types
static void initialize_il2cpp_mono_method_signature(Il2CppMonoMethodSignature* signature, MethodInfo* method)
{
signature->hasthis = il2cpp::vm::Method::IsInstance(method);
signature->ret = (Il2CppType*)il2cpp::vm::Method::GetReturnType(method);
signature->generic_param_count = 0;
if (method->is_generic)
{
signature->generic_param_count = il2cpp::vm::Method::GetGenericParamCount(method);
}
else if (method->is_inflated)
{
if (method->genericMethod->context.method_inst)
signature->generic_param_count += method->genericMethod->context.method_inst->type_argc;
if (method->genericMethod->context.class_inst)
signature->generic_param_count += method->genericMethod->context.class_inst->type_argc;
}
signature->param_count = il2cpp::vm::Method::GetParamCount(method);
for (int i = 0; i < signature->param_count; ++i)
signature->params[i] = (Il2CppType*)il2cpp::vm::Method::GetParam(method, i);
}
// We need to allocate the Il2CppMonoMethodSignature struct with C-style allocators because it is
// a mirror of _MonoMethodSignature, which end in a zero-length array. So wrap it in this C++
// struct that we can insert into a hash map and get proper memory management.
struct Il2CppMonoMethodSignatureWrapper
{
Il2CppMonoMethodSignatureWrapper(MethodInfo* method)
{
// We need the size of Il2CppMonoMethodSignature plus one pointer for each parameter of the method.
size_t methodSignatureSize = sizeof(Il2CppMonoMethodSignature) + (sizeof(Il2CppType*) * il2cpp::vm::Method::GetParamCount(method));
signature = (Il2CppMonoMethodSignature*)IL2CPP_CALLOC(1, methodSignatureSize);
initialize_il2cpp_mono_method_signature(signature, method);
}
~Il2CppMonoMethodSignatureWrapper()
{
IL2CPP_FREE(signature);
}
Il2CppMonoMethodSignature* signature;
};
typedef Il2CppHashMap<MethodInfo*, Il2CppMonoMethodSignatureWrapper*, il2cpp::utils::PointerHash<MethodInfo> > MethodSignatureMap;
static MethodSignatureMap* method_signatures;
static void error_init(MonoError* error)
{
auto il2CppError = (Il2CppMonoError*)error;
il2CppError->error_code = 0;
il2CppError->flags = 0;
}
uint32_t mono_image_get_entry_point(MonoImage *image)
{
const MethodInfo* entryPoint = il2cpp::vm::Image::GetEntryPoint((Il2CppImage*)image);
return entryPoint == NULL ? 0 : entryPoint->token;
}
const char* mono_image_get_filename(MonoImage *image)
{
return il2cpp_image_get_filename((Il2CppImage *)image);
}
const char* mono_image_get_guid(MonoImage *image)
{
return "00000000-0000-0000-0000-000000000000"; //IL2CPP doesn't have image GUIDs
}
int32_t mono_image_is_dynamic(MonoImage *image)
{
return false;
}
MonoAssembly* mono_image_get_assembly(MonoImage *image)
{
return (MonoAssembly*)il2cpp_image_get_assembly((Il2CppImage *)image);
}
const char* mono_image_get_name(MonoImage *image)
{
return il2cpp_image_get_name((Il2CppImage *)image);
}
MonoDomain* mono_get_root_domain(void)
{
return (MonoDomain*)il2cpp::vm::Domain::GetCurrent();
}
MonoDomain* mono_domain_get(void)
{
return mono_get_root_domain();
}
int32_t mono_domain_set(MonoDomain *domain, int32_t force)
{
IL2CPP_ASSERT(domain == mono_get_root_domain());
return true;
}
void mono_domain_foreach(MonoDomainFunc func, void* user_data)
{
func((MonoDomain*)mono_get_root_domain(), user_data);
}
void mono_domain_lock(MonoDomain* domain)
{
}
void mono_domain_unlock(MonoDomain* domain)
{
}
const MonoAssembly* mono_domain_get_corlib(MonoDomain *domain)
{
return (MonoAssembly*)il2cpp::vm::Image::GetAssembly((Il2CppImage*)il2cpp_defaults.corlib);
}
MonoAssembly* mono_domain_get_assemblies_iter(MonoAppDomain *domain, void** iter)
{
if (!iter)
return NULL;
il2cpp::vm::AssemblyVector* assemblies = il2cpp::vm::Assembly::GetAllAssemblies();
if (!*iter)
{
il2cpp::vm::AssemblyVector::iterator *pIter = new il2cpp::vm::AssemblyVector::iterator();
*pIter = assemblies->begin();
*iter = pIter;
return (MonoAssembly*)**pIter;
}
il2cpp::vm::AssemblyVector::iterator *pIter = (il2cpp::vm::AssemblyVector::iterator*)*iter;
(*pIter)++;
if (*pIter != assemblies->end())
{
return (MonoAssembly*)(**pIter);
}
else
{
delete pIter;
*iter = NULL;
}
return NULL;
}
MonoClass* mono_type_get_class(MonoType *type)
{
return (MonoClass*)il2cpp::vm::Type::GetClass((Il2CppType*)type);
}
MonoGenericClass* m_type_get_generic_class(MonoType* type)
{
return (MonoGenericClass*)((Il2CppType*)type)->data.generic_class;
}
int32_t mono_type_is_struct(MonoType *type)
{
return il2cpp::vm::Type::IsStruct((Il2CppType*)type);
}
int32_t mono_type_is_reference(MonoType *type)
{
return il2cpp::vm::Type::IsReference((Il2CppType*)type);
}
int32_t mono_type_generic_inst_is_valuetype(MonoType *monoType)
{
static const int kBitIsValueType = 1;
Il2CppType *type = (Il2CppType*)monoType;
Il2CppMetadataTypeHandle handle = il2cpp::vm::MetadataCache::GetTypeHandleFromType(type->data.generic_class->type);
return il2cpp::vm::MetadataCache::TypeIsValueType(handle);
}
char* mono_type_full_name(MonoType* type)
{
std::string name = il2cpp::vm::Type::GetName((Il2CppType*)type, IL2CPP_TYPE_NAME_FORMAT_FULL_NAME);
return strdup(name.c_str());
}
char* mono_type_get_name_full(MonoType* type, MonoTypeNameFormat format)
{
std::string name = il2cpp::vm::Type::GetName((Il2CppType*)type, (Il2CppTypeNameFormat)format);
return strdup(name.c_str());
}
MonoReflectionType* mono_type_get_object_checked(MonoDomain* domain, MonoType* type, MonoError* error)
{
error_init(error);
return (MonoReflectionType*)il2cpp::vm::Reflection::GetTypeObject((const Il2CppType*)type);
}
int mono_type_get_type(MonoType* type)
{
return il2cpp_type_get_type((const Il2CppType*)type);
}
int32_t mono_type_is_byref(MonoType* type)
{
return il2cpp_type_is_byref((const Il2CppType*)type);
}
uint32_t mono_type_get_attrs(MonoType* type)
{
return il2cpp_type_get_attrs((const Il2CppType*)type);
}
MonoVTable* mono_class_vtable(MonoDomain *domain, MonoClass *klass)
{
return (MonoVTable*)((Il2CppClass*)klass)->vtable;
}
int32_t mono_class_instance_size(MonoClass *klass)
{
il2cpp::vm::Class::Init((Il2CppClass*)klass);
return il2cpp_class_instance_size((Il2CppClass*)klass);
}
int32_t mono_class_value_size(MonoClass *klass, uint32_t *align)
{
return il2cpp::vm::Class::GetValueSize((Il2CppClass*)klass, align);
}
int32_t mono_class_is_assignable_from(MonoClass *klass, MonoClass *oklass)
{
return il2cpp::vm::Class::IsAssignableFrom((Il2CppClass*)klass, (Il2CppClass*)oklass);
}
MonoClass* mono_class_from_mono_type(MonoType *type)
{
return (MonoClass*)il2cpp::vm::Class::FromIl2CppType((Il2CppType*)type);
}
uint32_t mono_class_get_flags(MonoClass * klass)
{
return il2cpp_class_get_flags((Il2CppClass*)klass);
}
int mono_class_num_fields(MonoClass *klass)
{
return (int)il2cpp::vm::Class::GetNumFields((Il2CppClass*)klass);
}
int mono_class_num_methods(MonoClass *klass)
{
return (int)il2cpp::vm::Class::GetNumMethods((Il2CppClass*)klass);
}
int mono_class_num_properties(MonoClass *klass)
{
return (int)il2cpp::vm::Class::GetNumProperties((Il2CppClass*)klass);
}
MonoClassField* mono_class_get_fields(MonoClass* klass, void* *iter)
{
return (MonoClassField*)il2cpp::vm::Class::GetFields((Il2CppClass*)klass, iter);
}
MonoMethod* mono_class_get_methods(MonoClass* klass, void* *iter)
{
return (MonoMethod*)il2cpp::vm::Class::GetMethods((Il2CppClass*)klass, iter);
}
MonoProperty* mono_class_get_properties(MonoClass* klass, void* *iter)
{
return (MonoProperty*)il2cpp::vm::Class::GetProperties((Il2CppClass*)klass, iter);
}
MonoClass* mono_class_get_nested_types(MonoClass *monoClass, void* *iter)
{
Il2CppClass *klass = (Il2CppClass*)monoClass;
if (klass->generic_class)
return NULL;
return (MonoClass*)il2cpp::vm::Class::GetNestedTypes(klass, iter);
}
void mono_class_setup_methods(MonoClass* klass)
{
il2cpp::vm::Class::SetupMethods((Il2CppClass*)klass);
}
void mono_class_setup_vtable(MonoClass* klass)
{
il2cpp::vm::Class::Init((Il2CppClass*)klass);
}
static int32_t method_nonpublic(MethodInfo* method, int32_t start_klass)
{
switch (method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK)
{
case METHOD_ATTRIBUTE_ASSEM:
return (start_klass || il2cpp_defaults.generic_ilist_class);
case METHOD_ATTRIBUTE_PRIVATE:
return start_klass;
case METHOD_ATTRIBUTE_PUBLIC:
return false;
default:
return true;
}
}
static Il2CppGPtrArray* il2cpp_g_ptr_array_new()
{
Il2CppGPtrArrayPriv* array = (Il2CppGPtrArrayPriv*)IL2CPP_CALLOC(1, sizeof(Il2CppGPtrArrayPriv));
array->pdata = NULL;
array->len = 0;
array->size = 0;
return (Il2CppGPtrArray *)array;
}
static void il2cpp_g_ptr_array_grow(Il2CppGPtrArrayPriv* array, uint32_t length)
{
uint32_t new_length = array->len + length;
IL2CPP_ASSERT(array != NULL);
if (new_length <= array->size)
return;
array->size = 1;
while (array->size < new_length)
array->size <<= 1;
array->size = std::max(array->size, 16U);
array->pdata = (void**)IL2CPP_REALLOC(array->pdata, array->size * sizeof(void*));
}
static void il2cpp_g_ptr_array_add(Il2CppGPtrArray* array, void* data)
{
IL2CPP_ASSERT(array != NULL);
il2cpp_g_ptr_array_grow((Il2CppGPtrArrayPriv *)array, 1);
array->pdata[array->len++] = data;
}
static int32_t il2cpp_g_ascii_strcasecmp(const char *s1, const char *s2)
{
const char *sp1 = s1;
const char *sp2 = s2;
if (s1 == NULL)
return 0;
if (s2 == NULL)
return 0;
while (*sp1 != '\0')
{
char c1 = tolower(*sp1++);
char c2 = tolower(*sp2++);
if (c1 != c2)
return c1 - c2;
}
return (*sp1) - (*sp2);
}
GPtrArray* mono_class_get_methods_by_name(MonoClass* il2cppMonoKlass, const char* name, uint32_t bflags, int32_t ignore_case, int32_t allow_ctors, MonoError* error)
{
#if IL2CPP_MONO_DEBUGGER
Il2CppGPtrArray *array;
Il2CppClass *klass = (Il2CppClass*)il2cppMonoKlass;
Il2CppClass *startklass;
MethodInfo *method;
void* iter;
int match;
int (*compare_func) (const char *s1, const char *s2) = NULL;
array = il2cpp_g_ptr_array_new();
startklass = klass;
error_init(error);
if (name != NULL)
compare_func = (ignore_case) ? il2cpp_g_ascii_strcasecmp : strcmp;
handle_parent:
mono_class_setup_methods((MonoClass*)klass);
mono_class_setup_vtable((MonoClass*)klass);
iter = NULL;
while ((method = (MethodInfo*)mono_class_get_methods((MonoClass*)klass, &iter)))
{
match = 0;
if (!allow_ctors && method->name[0] == '.' && (strcmp(method->name, ".ctor") == 0 || strcmp(method->name, ".cctor") == 0))
continue;
if ((method->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)
{
if (bflags & BFLAGS_Public)
match++;
}
else if ((bflags & BFLAGS_NonPublic) && method_nonpublic(method, (klass == startklass)))
{
match++;
}
if (!match)
continue;
match = 0;
if (method->flags & METHOD_ATTRIBUTE_STATIC)
{
if (bflags & BFLAGS_Static)
if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
match++;
}
else
{
if (bflags & BFLAGS_Instance)
match++;
}
if (!match)
continue;
if (name != NULL)
{
if (compare_func(name, method->name))
continue;
}
match = 0;
il2cpp_g_ptr_array_add(array, method);
}
if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
goto handle_parent;
return (GPtrArray*)array;
#else
return NULL;
#endif
}
MonoMethod* mono_class_get_method_from_name(MonoClass * klass, const char* name, int argsCount)
{
return (MonoMethod*)il2cpp_class_get_method_from_name((Il2CppClass*)klass, name, argsCount);
}
int32_t mono_class_is_abstract(MonoClass * klass)
{
return il2cpp_class_is_abstract((Il2CppClass*)klass);
}
int32_t mono_class_field_is_special_static(MonoClassField* field)
{
return il2cpp::vm::Field::IsNormalStatic((FieldInfo*)field) ? 0 : 1;
}
MonoGenericContext* mono_class_get_context(MonoClass* klass)
{
return (MonoGenericContext*)&((Il2CppClass*)klass)->generic_class->context;
}
MonoMethod* mono_class_inflate_generic_method_full_checked(MonoMethod* method, MonoClass* klass_hint, MonoGenericContext* context, MonoError* error)
{
error_init(error);
return (MonoMethod*)il2cpp::metadata::GenericMetadata::Inflate((MethodInfo*)method, (Il2CppGenericContext*)context);
}
MonoMethod* mono_class_inflate_generic_method_checked(MonoMethod* method, MonoGenericContext* context, MonoError* error)
{
error_init(error);
return (MonoMethod*)il2cpp::metadata::GenericMetadata::Inflate((MethodInfo*)method, (Il2CppGenericContext*)context);
}
int32_t mono_class_is_nullable(MonoClass* klass)
{
return il2cpp::vm::Class::IsNullable((Il2CppClass*)klass);
}
MonoGenericContainer* mono_class_get_generic_container(MonoClass* klass)
{
return (MonoGenericContainer*)il2cpp::vm::Class::GetGenericContainer((Il2CppClass*)klass);
}
void mono_class_setup_interfaces(MonoClass* klass, MonoError* error)
{
error_init(error);
il2cpp::vm::Class::SetupInterfaces((Il2CppClass*)klass);
}
int32_t mono_class_is_valuetype(MonoClass* klass)
{
return il2cpp_class_is_valuetype((Il2CppClass*)klass);
}
MonoClass* mono_class_from_generic_parameter_internal(MonoGenericParam* param)
{
return (MonoClass*)il2cpp::vm::Class::FromGenericParameter((Il2CppMetadataGenericParameterHandle)param);
}
MonoGenericClass* mono_class_get_generic_class(MonoClass* monoClass)
{
Il2CppClass *klass = (Il2CppClass*)monoClass;
return (MonoGenericClass*)klass->generic_class;
}
MonoClass* mono_class_try_load_from_name(MonoImage* image, const char* namespaze, const char* name)
{
return (MonoClass*)il2cpp_class_from_name((const Il2CppImage*)image, namespaze, name);
}
int32_t mono_class_is_gtd(MonoClass* klass)
{
return il2cpp_class_is_generic((Il2CppClass*)klass);
}
int32_t mono_class_is_ginst(MonoClass* klass)
{
return il2cpp_class_is_inflated((Il2CppClass*)klass);
}
const char* mono_class_get_namespace(MonoClass * klass)
{
return il2cpp_class_get_namespace((Il2CppClass*)klass);
}
const char* mono_class_get_name(MonoClass * klass)
{
return il2cpp_class_get_name((Il2CppClass*)klass);
}
MonoClass* mono_class_get_parent(MonoClass * klass)
{
return (MonoClass*)il2cpp_class_get_parent((Il2CppClass*)klass);
}
MonoType* mono_class_get_type(MonoClass * klass)
{
return (MonoType*)il2cpp_class_get_type((Il2CppClass*)klass);
}
uint32_t mono_class_get_type_token(MonoClass * klass)
{
return il2cpp_class_get_type_token((Il2CppClass*)klass);
}
MonoType* mono_class_get_byref_type(MonoClass *klass)
{
return (MonoType*)il2cpp::vm::Class::GetByrefType((Il2CppClass*)klass);
}
MonoImage* mono_class_get_image(MonoClass * klass)
{
return (MonoImage*)il2cpp_class_get_image((Il2CppClass*)klass);
}
MonoClass* mono_class_get_interfaces(MonoClass * klass, void* *iter)
{
return (MonoClass*)il2cpp_class_get_interfaces((Il2CppClass*)klass, iter);
}
int32_t mono_class_is_interface(MonoClass * klass)
{
return il2cpp_class_is_interface((Il2CppClass*)klass);
}
int mono_class_get_rank(MonoClass * klass)
{
return il2cpp_class_get_rank((Il2CppClass*)klass);
}
MonoClass* mono_class_get_element_class(MonoClass * klass)
{
return (MonoClass*)il2cpp_class_get_element_class((Il2CppClass*)klass);
}
int32_t mono_class_is_enum(MonoClass * klass)
{
return il2cpp_class_is_enum((Il2CppClass*)klass);
}
MonoMethodSignature* mono_method_signature(MonoMethod *m)
{
MethodInfo* method = (MethodInfo*)m;
if (method_signatures == NULL)
method_signatures = new MethodSignatureMap();
auto entry = method_signatures->find(method);
if (entry != method_signatures->end())
return (MonoMethodSignature*)entry->second->signature;
Il2CppMonoMethodSignatureWrapper* wrapper = new Il2CppMonoMethodSignatureWrapper(method);
method_signatures->add(method, wrapper);
return (MonoMethodSignature*)wrapper->signature;
}
void mono_free_method_signatures()
{
delete method_signatures;
method_signatures = NULL;
}
MonoDebugLocalsInfo* mono_debug_lookup_locals(MonoMethod *method)
{
#if IL2CPP_MONO_DEBUGGER
uint32_t executionContextInfoCount;
const Il2CppMethodExecutionContextInfo * executionContextInfo;
const Il2CppMethodHeaderInfo *headerInfo;
const Il2CppMethodScope *scopes;
il2cpp::utils::Debugger::GetMethodExecutionContextInfo((const MethodInfo*)method, &executionContextInfoCount, &executionContextInfo, &headerInfo, &scopes);
Il2CppMonoDebugLocalsInfo* locals = (Il2CppMonoDebugLocalsInfo*)IL2CPP_CALLOC(1, sizeof(Il2CppMonoDebugLocalsInfo));
locals->num_locals = executionContextInfoCount;
locals->locals = (Il2CppMonoDebugLocalVar*)IL2CPP_CALLOC(executionContextInfoCount, sizeof(Il2CppMonoDebugLocalVar));
for (int i = 0; i < locals->num_locals; ++i)
{
locals->locals[i].name = (char*)il2cpp::utils::Debugger::GetLocalName((const MethodInfo*)method, executionContextInfo[i].nameIndex);
locals->locals[i].index = i;
/* hack we should point to blocks allocated below? */
locals->locals[i].block = (Il2CppMonoDebugCodeBlock*)IL2CPP_CALLOC(1, sizeof(Il2CppMonoDebugCodeBlock));
const Il2CppMethodScope* scope = il2cpp::utils::Debugger::GetLocalScope((const MethodInfo*)method, executionContextInfo[i].scopeIndex);
locals->locals[i].block->start_offset = scope->startOffset;
locals->locals[i].block->end_offset = scope->endOffset;
}
locals->num_blocks = headerInfo->numScopes;
locals->code_blocks = (Il2CppMonoDebugCodeBlock*)IL2CPP_CALLOC(headerInfo->numScopes, sizeof(Il2CppMonoDebugCodeBlock));
for (int i = 0; i < headerInfo->numScopes; ++i)
{
locals->code_blocks[i].start_offset = scopes[i].startOffset;
locals->code_blocks[i].end_offset = scopes[i].endOffset;
}
return (MonoDebugLocalsInfo*)locals;
#else
return NULL;
#endif
}
void mono_debug_free_locals(MonoDebugLocalsInfo *info)
{
#if IL2CPP_MONO_DEBUGGER
Il2CppMonoDebugLocalsInfo* locals = (Il2CppMonoDebugLocalsInfo*)info;
for (int i = 0; i < locals->num_locals; ++i)
{
IL2CPP_FREE(locals->locals[i].block);
}
IL2CPP_FREE(locals->locals);
IL2CPP_FREE(locals->code_blocks);
IL2CPP_FREE(locals);
#endif
}
MonoDebugMethodJitInfo* mono_debug_find_method(MonoMethod *method, MonoDomain *domain)
{
#if IL2CPP_MONO_DEBUGGER
Il2CppMonoDebugMethodJitInfo* jit = (Il2CppMonoDebugMethodJitInfo*)IL2CPP_CALLOC(1, sizeof(Il2CppMonoDebugMethodJitInfo));
Il2CppMonoDebugLocalsInfo* locals_info = (Il2CppMonoDebugLocalsInfo*)mono_debug_lookup_locals(method);
jit->num_locals = locals_info->num_locals;
Il2CppMonoMethodSignature* sig = (Il2CppMonoMethodSignature*)mono_method_signature(method);
jit->num_params = sig->param_count;
return (MonoDebugMethodJitInfo*)jit;
#else
return NULL;
#endif
}
void mono_method_get_param_names(MonoMethod *m, const char **names)
{
MethodInfo* method = (MethodInfo*)m;
uint32_t numberOfParameters = il2cpp::vm::Method::GetParamCount(method);
for (uint32_t i = 0; i < numberOfParameters; ++i)
names[i] = il2cpp::vm::Method::GetParamName(method, i);
}
MonoGenericContext* mono_method_get_context(MonoMethod* monoMethod)
{
MethodInfo* method = (MethodInfo*)monoMethod;
if (!method->is_inflated || method->is_generic)
return NULL;
return (MonoGenericContext*)&((MethodInfo*)method)->genericMethod->context;
}
MonoMethodHeader* mono_method_get_header_checked(MonoMethod *method, MonoError *error)
{
#if IL2CPP_MONO_DEBUGGER
if (error)
error_init(error);
uint32_t executionContextInfoCount;
const Il2CppMethodExecutionContextInfo *executionContextInfo;
const Il2CppMethodHeaderInfo *headerInfo;
const Il2CppMethodScope *scopes;
MonoGenericContext* context = mono_method_get_context(method);
il2cpp::utils::Debugger::GetMethodExecutionContextInfo((const MethodInfo*)method, &executionContextInfoCount, &executionContextInfo, &headerInfo, &scopes);
Il2CppMonoMethodHeader* header = (Il2CppMonoMethodHeader*)IL2CPP_CALLOC(1, sizeof(Il2CppMonoMethodHeader) + (executionContextInfoCount * sizeof(Il2CppType*)));
header->code_size = headerInfo->code_size;
header->num_locals = executionContextInfoCount;
for (uint32_t i = 0; i < executionContextInfoCount; i++)
header->locals[i] = (Il2CppType*)il2cpp::metadata::GenericMetadata::InflateIfNeeded(il2cpp::vm::MetadataCache::GetIl2CppTypeFromIndex(NULL, executionContextInfo[i].typeIndex), (const Il2CppGenericContext *)context, true);
return (MonoMethodHeader*)header;
#else
return NULL;
#endif
}
void mono_metadata_free_mh(MonoMethodHeader *mh)
{
IL2CPP_FREE(mh);
}
char* mono_method_full_name(MonoMethod* method, int32_t signature)
{
return strdup(((MethodInfo*)method)->name);
}
MonoGenericContainer* mono_method_get_generic_container(MonoMethod* monoMethod)
{
MethodInfo * method = (MethodInfo*)monoMethod;
if (method->is_inflated || !method->is_generic)
return NULL;
return (MonoGenericContainer*)method->genericContainerHandle;
}