private void IndexMetadataUsage() { if (il2Cpp.Version <= 16 || il2Cpp.Version >= 27) { return; } foreach (var(metadataUsageIndex, typeIndex) in metadata.metadataUsageDic[1]) //kIl2CppMetadataUsageTypeInfo { var type = il2Cpp.types[typeIndex]; var typeDef = executor.GetTypeDefinitionFromIl2CppType(type); if (typeDef != null) { typeDefToAddress[typeDef] = il2Cpp.GetRVA(il2Cpp.metadataUsages[metadataUsageIndex]); } } foreach (var(metadataUsageIndex, methodDefIndex) in metadata.metadataUsageDic[3]) //kIl2CppMetadataUsageMethodDef { var methodDef = metadata.methodDefs[methodDefIndex]; var typeDef = metadata.typeDefs[methodDef.declaringType]; var staticMethod = new StructStaticMethodInfo(); var typeName = executor.GetTypeDefName(typeDef, true, true); staticMethod.Address = il2Cpp.GetRVA(il2Cpp.metadataUsages[metadataUsageIndex]); staticMethod.Name = metadata.GetStringFromIndex(methodDef.nameIndex); if (!TypeNameToStaticMethods.ContainsKey(typeName)) { TypeNameToStaticMethods.Add(typeName, new List <StructStaticMethodInfo>()); } TypeNameToStaticMethods[typeName].Add(staticMethod); } foreach (var(metadataUsageIndex, methodSpecIndex) in metadata.metadataUsageDic[6]) //kIl2CppMetadataUsageMethodRef { var methodSpec = il2Cpp.methodSpecs[methodSpecIndex]; var methodDef = metadata.methodDefs[methodSpec.methodDefinitionIndex]; var typeDef = metadata.typeDefs[methodDef.declaringType]; var staticMethod = new StructStaticMethodInfo(); staticMethod.Address = il2Cpp.GetRVA(il2Cpp.metadataUsages[metadataUsageIndex]); var(typeName, methodSpecMethodName, typeArgs) = executor.GetMethodSpecName(methodSpec, true); staticMethod.Name = methodSpecMethodName; staticMethod.TypeArgs = typeArgs; if (!TypeNameToStaticMethods.ContainsKey(typeName)) { TypeNameToStaticMethods.Add(typeName, new List <StructStaticMethodInfo>()); } TypeNameToStaticMethods[typeName].Add(staticMethod); } }
private TypeReference GetTypeReference(MemberReference memberReference, Il2CppType il2CppType) { var moduleDefinition = memberReference.Module; switch (il2CppType.type) { case Il2CppTypeEnum.IL2CPP_TYPE_OBJECT: return(moduleDefinition.ImportReference(typeof(object))); case Il2CppTypeEnum.IL2CPP_TYPE_VOID: return(moduleDefinition.ImportReference(typeof(void))); case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN: return(moduleDefinition.ImportReference(typeof(bool))); case Il2CppTypeEnum.IL2CPP_TYPE_CHAR: return(moduleDefinition.ImportReference(typeof(char))); case Il2CppTypeEnum.IL2CPP_TYPE_I1: return(moduleDefinition.ImportReference(typeof(sbyte))); case Il2CppTypeEnum.IL2CPP_TYPE_U1: return(moduleDefinition.ImportReference(typeof(byte))); case Il2CppTypeEnum.IL2CPP_TYPE_I2: return(moduleDefinition.ImportReference(typeof(short))); case Il2CppTypeEnum.IL2CPP_TYPE_U2: return(moduleDefinition.ImportReference(typeof(ushort))); case Il2CppTypeEnum.IL2CPP_TYPE_I4: return(moduleDefinition.ImportReference(typeof(int))); case Il2CppTypeEnum.IL2CPP_TYPE_U4: return(moduleDefinition.ImportReference(typeof(uint))); case Il2CppTypeEnum.IL2CPP_TYPE_I: return(moduleDefinition.ImportReference(typeof(IntPtr))); case Il2CppTypeEnum.IL2CPP_TYPE_U: return(moduleDefinition.ImportReference(typeof(UIntPtr))); case Il2CppTypeEnum.IL2CPP_TYPE_I8: return(moduleDefinition.ImportReference(typeof(long))); case Il2CppTypeEnum.IL2CPP_TYPE_U8: return(moduleDefinition.ImportReference(typeof(ulong))); case Il2CppTypeEnum.IL2CPP_TYPE_R4: return(moduleDefinition.ImportReference(typeof(float))); case Il2CppTypeEnum.IL2CPP_TYPE_R8: return(moduleDefinition.ImportReference(typeof(double))); case Il2CppTypeEnum.IL2CPP_TYPE_STRING: return(moduleDefinition.ImportReference(typeof(string))); case Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF: return(moduleDefinition.ImportReference(typeof(TypedReference))); case Il2CppTypeEnum.IL2CPP_TYPE_CLASS: case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE: { var typeDef = executor.GetTypeDefinitionFromIl2CppType(il2CppType); var typeDefinition = typeDefinitionDic[typeDef]; return(moduleDefinition.ImportReference(typeDefinition)); } case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY: { var arrayType = il2Cpp.MapVATR <Il2CppArrayType>(il2CppType.data.array); var oriType = il2Cpp.GetIl2CppType(arrayType.etype); return(new ArrayType(GetTypeReference(memberReference, oriType), arrayType.rank)); } case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST: { var genericClass = il2Cpp.MapVATR <Il2CppGenericClass>(il2CppType.data.generic_class); var typeDef = executor.GetGenericClassTypeDefinition(genericClass); var typeDefinition = typeDefinitionDic[typeDef]; var genericInstanceType = new GenericInstanceType(moduleDefinition.ImportReference(typeDefinition)); var genericInst = il2Cpp.MapVATR <Il2CppGenericInst>(genericClass.context.class_inst); var pointers = il2Cpp.MapVATR <ulong>(genericInst.type_argv, genericInst.type_argc); foreach (var pointer in pointers) { var oriType = il2Cpp.GetIl2CppType(pointer); genericInstanceType.GenericArguments.Add(GetTypeReference(memberReference, oriType)); } return(genericInstanceType); } case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY: { var oriType = il2Cpp.GetIl2CppType(il2CppType.data.type); return(new ArrayType(GetTypeReference(memberReference, oriType))); } case Il2CppTypeEnum.IL2CPP_TYPE_VAR: { if (memberReference is MethodDefinition methodDefinition) { return(CreateGenericParameter(executor.GetGenericParameteFromIl2CppType(il2CppType), methodDefinition.DeclaringType)); } var typeDefinition = (TypeDefinition)memberReference; return(CreateGenericParameter(executor.GetGenericParameteFromIl2CppType(il2CppType), typeDefinition)); } case Il2CppTypeEnum.IL2CPP_TYPE_MVAR: { var methodDefinition = (MethodDefinition)memberReference; return(CreateGenericParameter(executor.GetGenericParameteFromIl2CppType(il2CppType), methodDefinition)); } case Il2CppTypeEnum.IL2CPP_TYPE_PTR: { var oriType = il2Cpp.GetIl2CppType(il2CppType.data.type); return(new PointerType(GetTypeReference(memberReference, oriType))); } default: throw new ArgumentOutOfRangeException(); } }