예제 #1
0
        private static string GetTypeName(Il2CppType pType)
        {
            string ret;

            switch (pType.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
            {
                var klass = metadata.typeDefs[pType.data.klassIndex];
                ret = metadata.GetStringFromIndex(klass.nameIndex);
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                var generic_class = il2cpp.MapVATR <Il2CppGenericClass>(pType.data.generic_class);
                var pMainDef      = metadata.typeDefs[generic_class.typeDefinitionIndex];
                ret = metadata.GetStringFromIndex(pMainDef.nameIndex);
                var typeNames = new List <string>();
                var pInst     = il2cpp.MapVATR <Il2CppGenericInst>(generic_class.context.class_inst);
                var pointers  = il2cpp.GetPointers(pInst.type_argv, (long)pInst.type_argc);
                for (uint i = 0; i < pInst.type_argc; ++i)
                {
                    var pOriType = il2cpp.GetIl2CppType(pointers[i]);
                    typeNames.Add(GetTypeName(pOriType));
                }
                ret += $"<{string.Join(", ", typeNames)}>";
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
            {
                var arrayType = il2cpp.MapVATR <Il2CppArrayType>(pType.data.array);
                var type      = il2cpp.GetIl2CppType(arrayType.etype);
                ret = $"{GetTypeName(type)}[{new string(',', arrayType.rank - 1)}]";
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
            {
                var type = il2cpp.GetIl2CppType(pType.data.type);
                ret = $"{GetTypeName(type)}[]";
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
            {
                var type = il2cpp.GetIl2CppType(pType.data.type);
                ret = $"{GetTypeName(type)}*";
                break;
            }

            default:
                ret = TypeString[(int)pType.type];
                break;
            }

            return(ret);
        }
        private static string GetGenericTypeParams(Il2CppGenericInst genericInst)
        {
            var typeNames = new List <string>();
            var pointers  = il2cpp.GetPointers(genericInst.type_argv, (long)genericInst.type_argc);

            for (uint i = 0; i < genericInst.type_argc; ++i)
            {
                var oriType = il2cpp.GetIl2CppType(pointers[i]);
                typeNames.Add(GetTypeName(oriType));
            }
            return($"<{string.Join(", ", typeNames)}>");
        }
예제 #3
0
        private static string GetTypeName(Il2CppType pType)
        {
            string ret;

            if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_CLASS || pType.type == Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE)
            {
                var klass = metadata.typeDefs[pType.data.klassIndex];
                ret = metadata.GetString(klass.nameIndex);
            }
            else if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST)
            {
                var generic_class = il2cpp.MapVATR <Il2CppGenericClass>(pType.data.generic_class);
                var pMainDef      = metadata.typeDefs[generic_class.typeDefinitionIndex];
                ret = metadata.GetString(pMainDef.nameIndex);
                var typeNames = new List <string>();
                var pInst     = il2cpp.MapVATR <Il2CppGenericInst>(generic_class.context.class_inst);
                var pointers  = il2cpp.GetPointers(pInst.type_argv, (long)pInst.type_argc);
                for (uint i = 0; i < pInst.type_argc; ++i)
                {
                    var pOriType = il2cpp.GetIl2CppType(pointers[i]);
                    typeNames.Add(GetTypeName(pOriType));
                }
                ret += $"<{string.Join(", ", typeNames)}>";
            }
            else if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_ARRAY)
            {
                var arrayType = il2cpp.MapVATR <Il2CppArrayType>(pType.data.array);
                var type      = il2cpp.GetIl2CppType(arrayType.etype);
                ret = $"{GetTypeName(type)}[]";
            }
            else if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY)
            {
                var type = il2cpp.GetIl2CppType(pType.data.type);
                ret = $"{GetTypeName(type)}[]";
            }
            else
            {
                if ((int)pType.type >= szTypeString.Length)
                {
                    ret = "unknow";
                }
                else
                {
                    ret = szTypeString[(int)pType.type];
                }
            }
            return(ret);
        }
예제 #4
0
        private TypeReference GetTypeReference(MemberReference memberReference, Il2CppType pType)
        {
            var moduleDefinition = memberReference.Module;

            switch (pType.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_OBJECT:
                return(moduleDefinition.Import(typeof(Object)));

            case Il2CppTypeEnum.IL2CPP_TYPE_VOID:
                return(moduleDefinition.Import(typeof(void)));

            case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
                return(moduleDefinition.Import(typeof(Boolean)));

            case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
                return(moduleDefinition.Import(typeof(Char)));

            case Il2CppTypeEnum.IL2CPP_TYPE_I1:
                return(moduleDefinition.Import(typeof(SByte)));

            case Il2CppTypeEnum.IL2CPP_TYPE_U1:
                return(moduleDefinition.Import(typeof(Byte)));

            case Il2CppTypeEnum.IL2CPP_TYPE_I2:
                return(moduleDefinition.Import(typeof(Int16)));

            case Il2CppTypeEnum.IL2CPP_TYPE_U2:
                return(moduleDefinition.Import(typeof(UInt16)));

            case Il2CppTypeEnum.IL2CPP_TYPE_I4:
                return(moduleDefinition.Import(typeof(Int32)));

            case Il2CppTypeEnum.IL2CPP_TYPE_U4:
                return(moduleDefinition.Import(typeof(UInt32)));

            case Il2CppTypeEnum.IL2CPP_TYPE_I:
                return(moduleDefinition.Import(typeof(IntPtr)));

            case Il2CppTypeEnum.IL2CPP_TYPE_U:
                return(moduleDefinition.Import(typeof(UIntPtr)));

            case Il2CppTypeEnum.IL2CPP_TYPE_I8:
                return(moduleDefinition.Import(typeof(Int64)));

            case Il2CppTypeEnum.IL2CPP_TYPE_U8:
                return(moduleDefinition.Import(typeof(UInt64)));

            case Il2CppTypeEnum.IL2CPP_TYPE_R4:
                return(moduleDefinition.Import(typeof(Single)));

            case Il2CppTypeEnum.IL2CPP_TYPE_R8:
                return(moduleDefinition.Import(typeof(Double)));

            case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
                return(moduleDefinition.Import(typeof(String)));

            case Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF:
                return(moduleDefinition.Import(typeof(TypedReference)));

            case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
            {
                var typeDefinition = typeDefinitionDic[pType.data.klassIndex];
                return(moduleDefinition.Import(typeDefinition));
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
            {
                var arrayType = il2cpp.MapVATR <Il2CppArrayType>(pType.data.array);
                var type      = il2cpp.GetIl2CppType(arrayType.etype);
                return(new ArrayType(GetTypeReference(memberReference, type), arrayType.rank));
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                var generic_class       = il2cpp.MapVATR <Il2CppGenericClass>(pType.data.generic_class);
                var typeDefinition      = typeDefinitionDic[generic_class.typeDefinitionIndex];
                var genericInstanceType = new GenericInstanceType(moduleDefinition.Import(typeDefinition));
                var pInst    = il2cpp.MapVATR <Il2CppGenericInst>(generic_class.context.class_inst);
                var pointers = il2cpp.GetPointers(pInst.type_argv, (long)pInst.type_argc);
                foreach (var pointer in pointers)
                {
                    var pOriType = il2cpp.GetIl2CppType(pointer);
                    genericInstanceType.GenericArguments.Add(GetTypeReference(memberReference, pOriType));
                }
                return(genericInstanceType);
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
            {
                var type = il2cpp.GetIl2CppType(pType.data.type);
                return(new ArrayType(GetTypeReference(memberReference, type)));
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_VAR:
            {
                if (genericParameterDic.TryGetValue(pType, out var genericParameter))
                {
                    return(genericParameter);
                }
                if (memberReference is MethodDefinition methodDefinition)
                {
                    var genericName = "T" + (methodDefinition.DeclaringType.GenericParameters.Count + 1);
                    genericParameter = new GenericParameter(genericName, methodDefinition.DeclaringType);
                    methodDefinition.DeclaringType.GenericParameters.Add(genericParameter);
                    genericParameterDic.Add(pType, genericParameter);
                    return(genericParameter);
                }
                var typeDefinition = (TypeDefinition)memberReference;
                var genericName2   = "T" + (typeDefinition.GenericParameters.Count + 1);
                genericParameter = new GenericParameter(genericName2, typeDefinition);
                typeDefinition.GenericParameters.Add(genericParameter);
                genericParameterDic.Add(pType, genericParameter);
                return(genericParameter);
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
            {
                if (genericParameterDic.TryGetValue(pType, out var genericParameter))
                {
                    return(genericParameter);
                }
                var methodDefinition = (MethodDefinition)memberReference;
                var genericName      = "T" + (methodDefinition.GenericParameters.Count + 1);
                genericParameter = new GenericParameter(genericName, methodDefinition);
                methodDefinition.GenericParameters.Add(genericParameter);
                genericParameterDic.Add(pType, genericParameter);
                return(genericParameter);
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
            {
                var type = il2cpp.GetIl2CppType(pType.data.type);
                return(new PointerType(GetTypeReference(memberReference, type)));
            }

            default:
                return(moduleDefinition.Import(typeof(Object)));
            }
        }
예제 #5
0
        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 typeDefinition = typeDefinitionDic[il2CppType.data.klassIndex];
                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 typeDefinition      = typeDefinitionDic[genericClass.typeDefinitionIndex];
                var genericInstanceType = new GenericInstanceType(moduleDefinition.ImportReference(typeDefinition));
                var genericInst         = il2cpp.MapVATR <Il2CppGenericInst>(genericClass.context.class_inst);
                var pointers            = il2cpp.GetPointers(genericInst.type_argv, (long)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 (genericParameterDic.TryGetValue(il2CppType.data.genericParameterIndex, out var genericParameter))
                {
                    return(genericParameter);
                }
                var param       = metadata.genericParameters[il2CppType.data.genericParameterIndex];
                var genericName = metadata.GetStringFromIndex(param.nameIndex);
                if (memberReference is MethodDefinition methodDefinition)
                {
                    genericParameter = new GenericParameter(genericName, methodDefinition.DeclaringType);
                    methodDefinition.DeclaringType.GenericParameters.Add(genericParameter);
                    genericParameterDic.Add(il2CppType.data.genericParameterIndex, genericParameter);
                    return(genericParameter);
                }
                var typeDefinition = (TypeDefinition)memberReference;
                genericParameter = new GenericParameter(genericName, typeDefinition);
                typeDefinition.GenericParameters.Add(genericParameter);
                genericParameterDic.Add(il2CppType.data.genericParameterIndex, genericParameter);
                return(genericParameter);
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
            {
                if (genericParameterDic.TryGetValue(il2CppType.data.genericParameterIndex, out var genericParameter))
                {
                    return(genericParameter);
                }
                var methodDefinition = (MethodDefinition)memberReference;
                var param            = metadata.genericParameters[il2CppType.data.genericParameterIndex];
                var genericName      = metadata.GetStringFromIndex(param.nameIndex);
                genericParameter = new GenericParameter(genericName, methodDefinition);
                methodDefinition.GenericParameters.Add(genericParameter);
                genericParameterDic.Add(il2CppType.data.genericParameterIndex, genericParameter);
                return(genericParameter);
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
            {
                var oriType = il2cpp.GetIl2CppType(il2CppType.data.type);
                return(new PointerType(GetTypeReference(memberReference, oriType)));
            }

            default:
                return(moduleDefinition.ImportReference(typeof(object)));
            }
        }