Ejemplo n.º 1
0
        private string include_path(Il2CppType type)
        {
            string output;
            string type_name = "";

            switch (type.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
            {
                return("cs/array");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
            {
                return("cs/string");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                Il2CppTypeDefinition typeDef;
                Il2CppGenericClass   genericClass = il2Cpp.MapVATR <Il2CppGenericClass>(type.data.generic_class);

                typeDef = executor.GetGenericClassTypeDefinition(genericClass);

                var @namespace = metadata.GetStringFromIndex(typeDef.namespaceIndex);
                if (@namespace != "")
                {
                    type_name += @namespace + ".";
                }

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

            default:
                type_name = executor.GetTypeName(type, true, false);
                break;
            }

            type_name = deobfu(type_name);
            type_name = type_name.Replace(".", "/");
            type_name = type_name.Replace("::", "/");
            type_name = type_name.Replace("*", "");
            output    = "au/" + type_name;

            return(output);
        }
Ejemplo n.º 2
0
 public Il2CppTypeDefinition GetGenericClassTypeDefinition(Il2CppGenericClass genericClass)
 {
     if (il2Cpp.Version >= 27)
     {
         var il2CppType = il2Cpp.GetIl2CppType(genericClass.type);
         return(GetTypeDefinitionFromIl2CppType(il2CppType));
     }
     if (genericClass.typeDefinitionIndex == 4294967295 || genericClass.typeDefinitionIndex == -1)
     {
         return(null);
     }
     return(metadata.typeDefs[genericClass.typeDefinitionIndex]);
 }
Ejemplo n.º 3
0
        private static string get_type_name(Il2CppType pType)
        {
            string ret;

            if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_CLASS || pType.type == Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE)
            {
                Il2CppTypeDefinition klass = metadata.typeDefs[pType.data.klassIndex];
                ret = metadata.GetString(klass.nameIndex);
            }
            else if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST)
            {
                Il2CppGenericClass   generic_class = il2cpp.MapVATR <Il2CppGenericClass>(pType.data.generic_class);
                Il2CppTypeDefinition pMainDef      = metadata.typeDefs[generic_class.typeDefinitionIndex];
                ret = metadata.GetString(pMainDef.nameIndex);
                var typeNames           = new List <string>();
                Il2CppGenericInst pInst = il2cpp.MapVATR <Il2CppGenericInst>(generic_class.context.class_inst);
                var pointers            = il2cpp.MapVATR <uint>(pInst.type_argv, (int)pInst.type_argc);
                for (int i = 0; i < pInst.type_argc; ++i)
                {
                    var pOriType = il2cpp.MapVATR <Il2CppType>(pointers[i]);
                    pOriType.Init();
                    typeNames.Add(get_type_name(pOriType));
                }
                ret += $"<{string.Join(", ", typeNames)}>";
            }
            else if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_ARRAY)
            {
                Il2CppArrayType arrayType = il2cpp.MapVATR <Il2CppArrayType>(pType.data.array);
                var             type      = il2cpp.MapVATR <Il2CppType>(arrayType.etype);
                type.Init();
                ret = $"{get_type_name(type)}[]";
            }
            else if (pType.type == Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY)
            {
                var type = il2cpp.MapVATR <Il2CppType>(pType.data.type);
                type.Init();
                ret = $"{get_type_name(type)}[]";
            }
            else
            {
                if ((int)pType.type >= szTypeString.Length)
                {
                    ret = "unknow";
                }
                else
                {
                    ret = szTypeString[(int)pType.type];
                }
            }
            return(ret);
        }
Ejemplo n.º 4
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]);
            }
        }
Ejemplo n.º 5
0
        private Il2CppTypeDefinitionInfo AddStruct(Il2CppTypeDefinition typeDef, TypeDefinitionMetadata metadata, Il2CppGenericClass genericClass = null)
        {
            var typeInfo = executor.GetTypeDefInfo(typeDef, genericClass);

            typeInfo.ImageName = metadata.ImageName;
            if (typeDefToAddress.ContainsKey(typeDef))
            {
                typeInfo.Type.Address = typeDefToAddress[typeDef];
            }
            TypeInfoList.Add(typeInfo);
            return(typeInfo);
        }
Ejemplo n.º 6
0
        private string header_include(Il2CppType type)
        {
            string output;
            string type_name     = "";
            string namespaze     = "";
            string template_decl = "";

            switch (type.type)
            {
            case Il2CppTypeEnum.IL2CPP_TYPE_ARRAY:
            case Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY:
            {
                return("#include <cs/array.hpp>");
            }


            case Il2CppTypeEnum.IL2CPP_TYPE_MVAR: return("");

            case Il2CppTypeEnum.IL2CPP_TYPE_VALUETYPE: return($"#include <{include_path(type)}.hpp>");

            case Il2CppTypeEnum.IL2CPP_TYPE_STRING:
            {
                return("#include <cs/string.hpp>");
            }

            case Il2CppTypeEnum.IL2CPP_TYPE_GENERICINST:
            {
                Il2CppTypeDefinition typeDef;
                Il2CppGenericClass   genericClass = il2Cpp.MapVATR <Il2CppGenericClass>(type.data.generic_class);

                typeDef = executor.GetGenericClassTypeDefinition(genericClass);

                var @namespace = metadata.GetStringFromIndex(typeDef.namespaceIndex);
                if (@namespace != "")
                {
                    type_name += @namespace + ".";
                }

                type_name += metadata.GetStringFromIndex(typeDef.nameIndex);
                var index = type_name.IndexOf("`");
                if (index != -1)
                {
                    type_name = type_name.Substring(0, index);
                }
                template_decl = "template <class...> ";        //Il2CppExecutor.GetGenericContainerParams(genericContainer, generic_decl)

                break;
            }

            default:
            {
                if (type.type > Il2CppTypeEnum.IL2CPP_TYPE_R8)
                {
                    type_name = executor.GetTypeName(type, true, false);
                }
                else
                {
                    return("");
                }
                break;
            }
            }

            type_name = type_name.Replace(".", "::");
            type_name = type_name.Replace("*", "");

            var nsindex = type_name.LastIndexOf("::");

            if (nsindex > 0)
            {
                namespaze = type_name.Substring(0, nsindex);
                type_name = type_name.Substring(nsindex + 2);
                output    = "namespace " + namespaze + "{ " + template_decl + "struct " + deobfu(type_name) + "; }";
            }
            else
            {
                output = "struct " + deobfu(type_name) + ";";
            }

            return(output);
        }
Ejemplo n.º 7
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]);
            }
        }