123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- #pragma once
- #include "InterpreterImage.h"
- #include "AOTHomologousImage.h"
- #include "Assembly.h"
- namespace hybridclr
- {
- namespace metadata
- {
- class MetadataModule
- {
- public:
- static void Initialize();
- static InterpreterImage* GetImage(uint32_t imageIndex)
- {
- return InterpreterImage::GetImage(imageIndex);
- }
- static InterpreterImage* GetImage(const Il2CppImage* image)
- {
- return GetImage(DecodeImageIndex(image->token));
- }
- static InterpreterImage* GetImage(const Il2CppClass* klass)
- {
- return GetImage(klass->image);
- }
- static InterpreterImage* GetImage(const Il2CppTypeDefinition* typeDef)
- {
- return GetImage(DecodeImageIndex(typeDef->byvalTypeIndex));
- }
- static InterpreterImage* GetImage(const Il2CppMethodDefinition* method)
- {
- return GetImage(DecodeImageIndex(method->nameIndex));
- }
- static InterpreterImage* GetImage(const MethodInfo* method)
- {
- return GetImage(method->klass->image);
- }
- static InterpreterImage* GetImageByEncodedIndex(uint32_t encodedIndex)
- {
- return GetImage(DecodeImageIndex(encodedIndex));
- }
-
- static Image* GetUnderlyingInterpreterImage(const MethodInfo* method);
- static const char* GetStringFromEncodeIndex(StringIndex index)
- {
- uint32_t imageIndex = DecodeImageIndex(index);
- return GetImage(imageIndex)->GetStringFromRawIndex(DecodeMetadataIndex(index));
- }
- static uint32_t GetTypeEncodeIndex(const Il2CppTypeDefinition* typeDef)
- {
- InterpreterImage* image = GetImage(typeDef);
- return hybridclr::metadata::EncodeImageAndMetadataIndex(image->GetIndex(), image->GetTypeRawIndex(typeDef));
- }
- static Il2CppMetadataTypeHandle GetAssemblyTypeHandleFromRawIndex(const Il2CppImage* image, AssemblyTypeIndex index)
- {
- return GetImage(image)->GetAssemblyTypeHandleFromRawIndex(index);
- }
- static Il2CppMetadataTypeHandle GetAssemblyTypeHandleFromEncodeIndex(AssemblyTypeIndex index)
- {
- uint32_t imageIndex = DecodeImageIndex(index);
- return GetImage(imageIndex)->GetAssemblyTypeHandleFromRawIndex(DecodeMetadataIndex(index));
- }
- static Il2CppMetadataTypeHandle GetAssemblyExportedTypeHandleFromEncodeIndex(AssemblyTypeIndex index)
- {
- uint32_t imageIndex = DecodeImageIndex(index);
- return GetImage(imageIndex)->GetAssemblyExportedTypeHandleFromRawIndex(DecodeMetadataIndex(index));
- }
- static const Il2CppTypeDefinitionSizes* GetTypeDefinitionSizesFromEncodeIndex(TypeDefinitionIndex index)
- {
- uint32_t imageIndex = DecodeImageIndex(index);
- return GetImage(imageIndex)->GetTypeDefinitionSizesFromRawIndex(DecodeMetadataIndex(index));
- }
- static const Il2CppType* GetIl2CppTypeFromEncodeIndex(uint32_t index)
- {
- uint32_t imageIndex = DecodeImageIndex(index);
- IL2CPP_ASSERT(imageIndex > 0);
- uint32_t rawIndex = DecodeMetadataIndex(index);
- return GetImage(imageIndex)->GetIl2CppTypeFromRawIndex(rawIndex);
- }
- static Il2CppClass* GetTypeInfoFromTypeDefinitionEncodeIndex(TypeDefinitionIndex index)
- {
- uint32_t imageIndex = DecodeImageIndex(index);
- IL2CPP_ASSERT(imageIndex > 0);
- uint32_t rawIndex = DecodeMetadataIndex(index);
- return GetImage(imageIndex)->GetTypeInfoFromTypeDefinitionRawIndex(rawIndex);
- }
- static const Il2CppFieldDefinition* GetFieldDefinitionFromEncodeIndex(uint32_t index)
- {
- uint32_t imageIndex = DecodeImageIndex(index);
- return GetImage(imageIndex)->GetFieldDefinitionFromRawIndex(DecodeMetadataIndex(index));
- }
- static const Il2CppMethodDefinition* GetMethodDefinitionFromIndex(MethodIndex index)
- {
- uint32_t imageIndex = DecodeImageIndex(index);
- return GetImage(imageIndex)->GetMethodDefinitionFromRawIndex(DecodeMetadataIndex(index));
- }
- static uint32_t GetFieldOffset(const Il2CppClass* klass, int32_t fieldIndexInType, FieldInfo* field)
- {
- return GetImage(klass)->GetFieldOffset(klass, fieldIndexInType);
- }
- static const MethodInfo* GetMethodInfoFromMethodDefinitionIndex(uint32_t index)
- {
- uint32_t imageIndex = DecodeImageIndex(index);
- return GetImage(imageIndex)->GetMethodInfoFromMethodDefinitionRawIndex(DecodeMetadataIndex(index));
- }
- static const MethodInfo* GetMethodInfoFromMethodDefinition(const Il2CppMethodDefinition* methodDef)
- {
- uint32_t imageIndex = DecodeImageIndex(methodDef->nameIndex);
- return GetImage(imageIndex)->GetMethodInfoFromMethodDefinition(methodDef);
- }
- static const MethodInfo* GetMethodInfoFromVTableSlot(const Il2CppClass* klass, int32_t vTableSlot)
- {
- return GetImage(klass)->GetMethodInfoFromVTableSlot(klass, vTableSlot);
- }
- static const Il2CppMethodDefinition* GetMethodDefinitionFromVTableSlot(const Il2CppTypeDefinition* typeDefine, int32_t vTableSlot)
- {
- return GetImage(typeDefine)->GetMethodDefinitionFromVTableSlot(typeDefine, vTableSlot);
- }
- static Il2CppMethodPointer GetAdjustorThunk(const Il2CppImage* image, uint32_t token)
- {
- uint32_t imageIndex = DecodeImageIndex(image->token);
- return GetImage(imageIndex)->GetAdjustorThunk(token);
- }
- static Il2CppMethodPointer GetMethodPointer(const Il2CppImage* image, uint32_t token)
- {
- uint32_t imageIndex = DecodeImageIndex(image->token);
- return GetImage(imageIndex)->GetMethodPointer(token);
- }
- static InvokerMethod GetMethodInvoker(const Il2CppImage* image, uint32_t token)
- {
- uint32_t imageIndex = DecodeImageIndex(image->token);
- return GetImage(imageIndex)->GetMethodInvoker(token);
- }
- static const Il2CppParameterDefinition* GetParameterDefinitionFromIndex(const Il2CppImage* image, ParameterIndex index)
- {
- uint32_t imageIndex = DecodeImageIndex(image->token);
- return GetImage(imageIndex)->GetParameterDefinitionFromIndex(index);
- }
- static const Il2CppType* GetInterfaceFromIndex(const Il2CppClass* klass, TypeInterfaceIndex index)
- {
- return GetImage(klass)->GetInterfaceFromIndex(klass, index);
- }
- static const Il2CppType* GetInterfaceFromOffset(const Il2CppClass* klass, TypeInterfaceIndex offset)
- {
- return GetImage(klass)->GetInterfaceFromOffset(klass, offset);
- }
- static const Il2CppType* GetInterfaceFromOffset(const Il2CppTypeDefinition* typeDefine, TypeInterfaceIndex offset)
- {
- return GetImage(typeDefine)->GetInterfaceFromOffset(typeDefine, offset);
- }
- static Il2CppInterfaceOffsetInfo GetInterfaceOffsetInfo(const Il2CppTypeDefinition* typeDefine, TypeInterfaceOffsetIndex index)
- {
- return GetImage(typeDefine)->GetInterfaceOffsetInfo(typeDefine, index);
- }
- static Il2CppClass* GetNestedTypeFromOffset(const Il2CppClass* klass, TypeNestedTypeIndex offset)
- {
- return GetImage(klass)->GetNestedTypeFromOffset(klass, offset);
- }
- static Il2CppClass* GetNestedTypeFromOffset(const Il2CppTypeDefinition* typeDefinition, TypeNestedTypeIndex offset)
- {
- return GetImage(typeDefinition)->GetNestedTypeFromOffset(typeDefinition, offset);
- }
- static Il2CppMetadataTypeHandle GetNestedTypes(Il2CppMetadataTypeHandle handle, void** iter)
- {
- Il2CppTypeDefinition* typeDef = (Il2CppTypeDefinition*)handle;
- return (Il2CppMetadataTypeHandle)(GetImage(typeDef)->GetNestedTypes(typeDef, iter));
- }
- static const Il2CppGenericContainer* GetGenericContainerFromEncodeIndex(uint32_t index)
- {
- return GetImage(DecodeImageIndex(index))->GetGenericContainerByRawIndex(DecodeMetadataIndex(index));
- }
- static const Il2CppFieldDefaultValue* GetFieldDefaultValueEntry(uint32_t index)
- {
- return GetImage(DecodeImageIndex(index))->GetFieldDefaultValueEntryByRawIndex(DecodeMetadataIndex(index));
- }
- static const uint8_t* GetFieldOrParameterDefalutValue(uint32_t index)
- {
- return GetImage(DecodeImageIndex(index))->GetFieldOrParameterDefalutValueByRawIndex(DecodeMetadataIndex(index));
- }
- #if HYBRIDCLR_UNITY_2020
- static bool HasAttribute(const Il2CppImage* image, uint32_t token, Il2CppClass* attribute)
- {
- return GetImage(image)->HasAttributeByToken(token, attribute);
- }
- static std::tuple<void*, void*> GetCustomAttributeDataRange(const Il2CppImage* image, uint32_t token)
- {
- return GetImage(image)->GetCustomAttributeDataRange(token);
- }
- #endif
- static bool IsImplementedByInterpreter(MethodInfo* method)
- {
- Il2CppClass* klass = method->klass;
- Il2CppClass* parent = klass->parent;
- if (parent != il2cpp_defaults.multicastdelegate_class && parent != il2cpp_defaults.delegate_class)
- {
- return AOTHomologousImage::FindImageByAssembly(klass->image->assembly);
- }
- else
- {
- return strcmp(method->name, "Invoke") == 0;
- }
- }
- static LoadImageErrorCode LoadMetadataForAOTAssembly(const void* dllBytes, uint32_t dllSize, HomologousImageMode mode);
- private:
- };
- }
- }
|