예제 #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);
        }
예제 #2
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);
        }
예제 #3
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)));
            }
        }
예제 #4
0
        private string ParseType(Il2CppType il2CppType, Il2CppGenericContext context = null)
        {
            switch (il2CppType.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_VOID:
                return("void");

            case Il2CppTypeEnum.IL2CPP_TYPE_BOOLEAN:
                return("bool");

            case Il2CppTypeEnum.IL2CPP_TYPE_CHAR:
                return("uint16_t");    //Il2CppChar

            case Il2CppTypeEnum.IL2CPP_TYPE_I1:
                return("int8_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_U1:
                return("uint8_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_I2:
                return("int16_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_U2:
                return("uint16_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_I4:
                return("int32_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_U4:
                return("uint32_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_I8:
                return("int64_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_U8:
                return("uint64_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_R4:
                return("float");

            case Il2CppTypeEnum.IL2CPP_TYPE_R8:
                return("double");

            case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
                return("System_String_o*");

            case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
            {
                var oriType = il2Cpp.GetIl2CppType(il2CppType.data.type);
                return(ParseType(oriType) + "*");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
            {
                var typeDef = metadata.typeDefs[il2CppType.data.klassIndex];
                if (typeDef.IsEnum)
                {
                    return(ParseType(il2Cpp.types[typeDef.elementTypeIndex]));
                }
                return(structNameDic[typeDef] + "_o");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
            {
                var typeDef = metadata.typeDefs[il2CppType.data.klassIndex];
                return(structNameDic[typeDef] + "_o*");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_VAR:
            {
                if (context != null)
                {
                    var genericParameter = metadata.genericParameters[il2CppType.data.genericParameterIndex];
                    var genericInst      = il2Cpp.MapVATR <Il2CppGenericInst>(context.class_inst);
                    var pointers         = il2Cpp.MapVATR <ulong>(genericInst.type_argv, genericInst.type_argc);
                    var pointer          = pointers[genericParameter.num];
                    var type             = il2Cpp.GetIl2CppType(pointer);
                    return(ParseType(type));
                }
                return("Il2CppObject*");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
            {
                var arrayType         = il2Cpp.MapVATR <Il2CppArrayType>(il2CppType.data.array);
                var elementType       = il2Cpp.GetIl2CppType(arrayType.etype);
                var elementStructName = GetIl2CppStructName(elementType, context);
                var typeStructName    = elementStructName + "_array";
                if (structNameHashSet.Add(typeStructName))
                {
                    ParseArrayClassStruct(elementType, context);
                }
                return(typeStructName + "*");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                var genericClass = il2Cpp.MapVATR <Il2CppGenericClass>(il2CppType.data.generic_class);
                var typeDef      = metadata.typeDefs[genericClass.typeDefinitionIndex];
                if (!genericClassStructNameDic.TryGetValue(il2CppType.data.generic_class, out var typeStructName))
                {
                    var typeOriName       = structNameDic[typeDef];
                    var typeToReplaceName = FixName(executor.GetTypeDefName(typeDef, true, true));
                    var typeReplaceName   = FixName(executor.GetTypeName(il2CppType, true, false));
                    typeStructName = typeOriName.Replace(typeToReplaceName, typeReplaceName);
                    genericClassStructNameDic.Add(il2CppType.data.generic_class, typeStructName);
                    if (structNameHashSet.Add(typeStructName))
                    {
                        genericClassList.Add(il2CppType.data.generic_class);
                    }
                }
                if (typeDef.IsValueType)
                {
                    if (typeDef.IsEnum)
                    {
                        return(ParseType(il2Cpp.types[typeDef.elementTypeIndex]));
                    }
                    return(typeStructName + "_o");
                }
                return(typeStructName + "_o*");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_TYPEDBYREF:
                return("Il2CppObject*");

            case Il2CppTypeEnum.IL2CPP_TYPE_I:
                return("intptr_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_U:
                return("uintptr_t");

            case Il2CppTypeEnum.IL2CPP_TYPE_OBJECT:
                return("Il2CppObject*");

            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
            {
                var elementType       = il2Cpp.GetIl2CppType(il2CppType.data.type);
                var elementStructName = GetIl2CppStructName(elementType, context);
                var typeStructName    = elementStructName + "_array";
                if (structNameHashSet.Add(typeStructName))
                {
                    ParseArrayClassStruct(elementType, context);
                }
                return(typeStructName + "*");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
            {
                if (context != null)
                {
                    var genericParameter = metadata.genericParameters[il2CppType.data.genericParameterIndex];
                    var genericInst      = il2Cpp.MapVATR <Il2CppGenericInst>(context.method_inst);
                    var pointers         = il2Cpp.MapVATR <ulong>(genericInst.type_argv, genericInst.type_argc);
                    var pointer          = pointers[genericParameter.num];
                    var type             = il2Cpp.GetIl2CppType(pointer);
                    return(ParseType(type));
                }
                return("Il2CppObject*");
            }

            default:
                throw new NotSupportedException();
            }
        }
예제 #5
0
        public string GetTypeName(Il2CppType il2CppType, bool addNamespace, bool is_nested)
        {
            switch (il2CppType.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
            {
                var arrayType   = il2Cpp.MapVATR <Il2CppArrayType>(il2CppType.data.array);
                var elementType = il2Cpp.GetIl2CppType(arrayType.etype);
                return($"{GetTypeName(elementType, addNamespace, false)}[{new string(',', arrayType.rank - 1)}]");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
            {
                var elementType = il2Cpp.GetIl2CppType(il2CppType.data.type);
                return($"{GetTypeName(elementType, addNamespace, false)}[]");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
            {
                var oriType = il2Cpp.GetIl2CppType(il2CppType.data.type);
                return($"{GetTypeName(oriType, addNamespace, false)}*");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_VAR:
            case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
            {
                var param = GetGenericParameteFromIl2CppType(il2CppType);
                return(metadata.GetStringFromIndex(param.nameIndex));
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                string str = string.Empty;
                Il2CppTypeDefinition typeDef;
                Il2CppGenericClass   genericClass = null;
                if (il2CppType.type == Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST)
                {
                    genericClass = il2Cpp.MapVATR <Il2CppGenericClass>(il2CppType.data.generic_class);
                    typeDef      = GetGenericClassTypeDefinition(genericClass);
                }
                else
                {
                    typeDef = GetTypeDefinitionFromIl2CppType(il2CppType);
                }
                if (typeDef.declaringTypeIndex != -1)
                {
                    str += GetTypeName(il2Cpp.types[typeDef.declaringTypeIndex], addNamespace, true);
                    str += '.';
                }
                else if (addNamespace)
                {
                    var @namespace = metadata.GetStringFromIndex(typeDef.namespaceIndex);
                    if (@namespace != "")
                    {
                        str += @namespace + ".";
                    }
                }

                var typeName = metadata.GetStringFromIndex(typeDef.nameIndex);
                var index    = typeName.IndexOf("`");
                if (index != -1)
                {
                    str += typeName.Substring(0, index);
                }
                else
                {
                    str += typeName;
                }

                if (is_nested)
                {
                    return(str);
                }

                if (genericClass != null)
                {
                    var genericInst = il2Cpp.MapVATR <Il2CppGenericInst>(genericClass.context.class_inst);
                    str += GetGenericInstParams(genericInst);
                }
                else if (typeDef.genericContainerIndex >= 0)
                {
                    var genericContainer = metadata.genericContainers[typeDef.genericContainerIndex];
                    str += GetGenericContainerParams(genericContainer);
                }

                return(str);
            }

            default:
                return(TypeString[(int)il2CppType.type]);
            }
        }
예제 #6
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.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 (genericParameterDic.TryGetValue(il2CppType.data.genericParameterIndex, out var genericParameter))
                {
                    return(genericParameter);
                }
                if (memberReference is MethodDefinition methodDefinition)
                {
                    return(CreateGenericParameter(il2CppType.data.genericParameterIndex, methodDefinition.DeclaringType));
                }
                var typeDefinition = (TypeDefinition)memberReference;
                return(CreateGenericParameter(il2CppType.data.genericParameterIndex, typeDefinition));
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
            {
                if (genericParameterDic.TryGetValue(il2CppType.data.genericParameterIndex, out var genericParameter))
                {
                    return(genericParameter);
                }
                var methodDefinition = (MethodDefinition)memberReference;
                return(CreateGenericParameter(il2CppType.data.genericParameterIndex, methodDefinition));
            }

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private static string GetTypeName(Il2CppType type, bool fullName = false)
        {
            string ret;

            switch (type.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
            {
                var typeDef = metadata.typeDefs[type.data.klassIndex];
                ret = string.Empty;
                if (fullName)
                {
                    ret = metadata.GetStringFromIndex(typeDef.namespaceIndex);
                    if (ret != string.Empty)
                    {
                        ret += ".";
                    }
                }
                ret += GetTypeName(typeDef);
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                var generic_class = il2cpp.MapVATR <Il2CppGenericClass>(type.data.generic_class);
                var typeDef       = metadata.typeDefs[generic_class.typeDefinitionIndex];
                ret = metadata.GetStringFromIndex(typeDef.nameIndex);
                var genericInst = il2cpp.MapVATR <Il2CppGenericInst>(generic_class.context.class_inst);
                ret += GetGenericTypeParams(genericInst);
                break;
            }

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

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

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

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

            return(ret);
        }
예제 #8
0
        public string GetTypeName(Il2CppType il2CppType)
        {
            string ret;

            switch (il2CppType.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
            {
                var typeDef = metadata.typeDefs[il2CppType.data.klassIndex];
                ret = GetTypeDefName(typeDef);
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                var genericClass = il2Cpp.MapVATR <Il2CppGenericClass>(il2CppType.data.generic_class);
                var typeDef      = metadata.typeDefs[genericClass.typeDefinitionIndex];
                ret = metadata.GetStringFromIndex(typeDef.nameIndex);
                var genericInst = il2Cpp.MapVATR <Il2CppGenericInst>(genericClass.context.class_inst);
                ret  = ret.Replace($"`{genericInst.type_argc}", "");
                ret += GetGenericTypeParams(genericInst);
                break;
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_VAR:
            case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
            {
                var param = metadata.genericParameters[il2CppType.data.genericParameterIndex];
                ret = metadata.GetStringFromIndex(param.nameIndex);
                break;
            }

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

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

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

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

            return(ret);
        }
예제 #9
0
        public string GetTypeName(Il2CppType il2CppType, bool addNamespace, bool is_nested, bool is_pointer = true)
        {
            /*
             * if (il2CppType.data.klassIndex)
             * var typeDef = metadata.typeDefs[typeDefIndex];
             * var typeName = executor.GetTypeDefName(typeDef, false, true);*/

            switch (il2CppType.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
            {
                var arrayType   = il2Cpp.MapVATR <Il2CppArrayType>(il2CppType.data.array);
                var elementType = il2Cpp.GetIl2CppType(arrayType.etype);
                return($"{GetTypeName(elementType, addNamespace, false)}[{new string(',', arrayType.rank - 1)}]");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
            {
                var elementType = il2Cpp.GetIl2CppType(il2CppType.data.type);
                return($"cs::array<{GetTypeName(elementType, addNamespace, false, false)}>*");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_PTR:
            {
                var oriType = il2Cpp.GetIl2CppType(il2CppType.data.type);
                return($"{GetTypeName(oriType, addNamespace, false)}*");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_VAR:
            case Il2CppTypeEnum.IL2CPP_TYPE_MVAR:
            {
                var param = GetGenericParameteFromIl2CppType(il2CppType);
                return(metadata.GetStringFromIndex(param.nameIndex));
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_CLASS:
            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE:
            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                string str         = string.Empty;
                string str_params  = string.Empty;
                string str_pointer = "*";
                if (!is_pointer)
                {
                    str_pointer = "";
                }

                Il2CppTypeDefinition typeDef;
                Il2CppGenericClass   genericClass = null;
                if (il2CppType.type == Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST)
                {
                    genericClass = il2Cpp.MapVATR <Il2CppGenericClass>(il2CppType.data.generic_class);
                    typeDef      = GetGenericClassTypeDefinition(genericClass);
                }
                else
                {
                    typeDef = GetTypeDefinitionFromIl2CppType(il2CppType);
                }
                if (typeDef.declaringTypeIndex != -1)
                {
                    // nested
                    str += GetTypeName(il2Cpp.types[typeDef.declaringTypeIndex], addNamespace, true, true);
                    str += "_";
                }
                else if (addNamespace)
                {
                    var @namespace = metadata.GetStringFromIndex(typeDef.namespaceIndex);
                    if (@namespace != "")
                    {
                        @namespace = @namespace.Replace(".", "::");
                        str       += @namespace + "::";
                    }
                }

                var typeName = metadata.GetStringFromIndex(typeDef.nameIndex);

                var index = typeName.IndexOf("`");
                if (index != -1)
                {
                    str += typeName.Substring(0, index);
                }
                else
                {
                    str += typeName;
                }

                if (is_nested)
                {
                    return(str);
                }

                if (genericClass != null)
                {
                    var genericInst = il2Cpp.MapVATR <Il2CppGenericInst>(genericClass.context.class_inst);
                    str_params += GetGenericInstParams(genericInst);
                }
                else if (typeDef.genericContainerIndex >= 0)
                {
                    var genericContainer = metadata.genericContainers[typeDef.genericContainerIndex];
                    str_params += GetGenericContainerParams(genericContainer);
                }

                if (il2CppType.type == Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE)
                {
                    str_pointer = "";
                }

                str = str.Replace("<", "_");
                str = str.Replace(">", "_");
                str = Il2CppDecompiler.deobfu(str);
                return(str + str_params + str_pointer);
            }

            default:
                return(TypeString[(int)il2CppType.type]);
            }
        }