Ejemplo n.º 1
0
        private void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
        {
            Log("Dumping...");
            var executor   = new Il2CppExecutor(metadata, il2Cpp);
            var decompiler = new Il2CppDecompiler(executor);

            decompiler.Decompile(config, outputDir);
            Log("Done!");
            if (config.GenerateStruct)
            {
                Log("Generate struct...");
                try
                {
                    var scriptGenerator = new StructGenerator(executor);
                    scriptGenerator.WriteScript(outputDir);
                    Log("Done!");
                }
                catch
                {
                    Log("There was an error trying to generate struct. Skipped", Color.Orange);
                }
            }
            if (config.GenerateDummyDll)
            {
                Log("Generate dummy dll...");
                DummyAssemblyExporter.Export(executor, outputDir, config.DummyDllAddToken);
                Log("Done!");
                Directory.SetCurrentDirectory(realPath); //Fix read-only directory permission
            }
        }
Ejemplo n.º 2
0
        private static void Dump(Metadata metadata, Il2Cpp il2Cpp)
        {
            Console.WriteLine("Dumping...");
            var writer     = new StreamWriter(new FileStream("dump.cs", FileMode.Create), new UTF8Encoding(false));
            var decompiler = new Il2CppDecompiler(metadata, il2Cpp);

            decompiler.Decompile(writer, config);
            Console.WriteLine("Done!");
            Console.WriteLine("Generate script...");
            var scriptwriter    = new StreamWriter(new FileStream("script.py", FileMode.Create), new UTF8Encoding(false));
            var scriptGenerator = new ScriptGenerator(decompiler);

            scriptGenerator.WriteScript(scriptwriter, config);
            Console.WriteLine("Done!");
            if (config.DummyDll)
            {
                Console.WriteLine("Generate dummy dll...");
                if (Directory.Exists("DummyDll"))
                {
                    Directory.Delete("DummyDll", true);
                }
                Directory.CreateDirectory("DummyDll");
                Directory.SetCurrentDirectory("DummyDll");
                var dummy = new DummyAssemblyGenerator(metadata, il2Cpp);
                foreach (var assembly in dummy.Assemblies)
                {
                    using (var stream = new MemoryStream())
                    {
                        assembly.Write(stream);
                        File.WriteAllBytes(assembly.MainModule.Name, stream.ToArray());
                    }
                }
                Console.WriteLine("Done!");
            }
        }
Ejemplo n.º 3
0
        public static bool PerformDump(string gameAssemblyPath, string metadataDatPath, string outputDirectoryPath,
                                       Config config, Action <string> reportProgressAction)
        {
            Init(gameAssemblyPath, metadataDatPath, config, reportProgressAction, out var metadata, out var il2Cpp);

            reportProgressAction("Dumping...");
            var executor   = new Il2CppExecutor(metadata, il2Cpp);
            var decompiler = new Il2CppDecompiler(executor);

            reportProgressAction("Done!");
            if (config.GenerateStruct)
            {
                decompiler.Decompile(config, outputDirectoryPath, reportProgressAction);
                reportProgressAction("Generate struct...");
                var scriptGenerator = new StructGenerator(executor);
                scriptGenerator.WriteScript(outputDirectoryPath);
                reportProgressAction("Done!");
            }
            if (config.GenerateDummyDll)
            {
                reportProgressAction("Generate dummy dll...");
                DummyAssemblyExporter.Export(executor, outputDirectoryPath, config.DummyDllAddToken);
                reportProgressAction("Done!");
            }

            return(true);
        }
Ejemplo n.º 4
0
        private static void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
        {
            Console.WriteLine("Dumping...");
            var executor   = new Il2CppExecutor(metadata, il2Cpp);
            var decompiler = new Il2CppDecompiler(executor);

            decompiler.Decompile(config, outputDir);
            Console.WriteLine("Done!");
        }
Ejemplo n.º 5
0
        public string GetGenericInstParams(Il2CppGenericInst genericInst)
        {
            var genericParameterNames = new List <string>();
            var pointers = il2Cpp.MapVATR <ulong>(genericInst.type_argv, genericInst.type_argc);

            for (int i = 0; i < genericInst.type_argc; i++)
            {
                var il2CppType = il2Cpp.GetIl2CppType(pointers[i]);
                genericParameterNames.Add(Il2CppDecompiler.deobfu(GetTypeName(il2CppType, true, false, false)));
            }
            return($"<{string.Join(", ", genericParameterNames)}>");
        }
Ejemplo n.º 6
0
        public string GetTypeDefName(Il2CppTypeDefinition typeDef, bool addNamespace, bool genericParameter, bool generic_decl = false)
        {
            var prefix = string.Empty;

            if (typeDef.declaringTypeIndex != -1)
            {
                prefix = GetTypeName(il2Cpp.types[typeDef.declaringTypeIndex], addNamespace, true) + "_";
            }
            else if (addNamespace)
            {
                var @namespace = metadata.GetStringFromIndex(typeDef.namespaceIndex);
                @namespace = @namespace.Replace(".", "::");
                if (@namespace != "")
                {
                    prefix = @namespace + "::";
                }
            }
            var typeName = metadata.GetStringFromIndex(typeDef.nameIndex);

            if (typeDef.genericContainerIndex >= 0)
            {
                var index = typeName.IndexOf("`");
                if (index != -1)
                {
                    typeName = typeName.Substring(0, index);
                    typeName = typeName.Replace("<", "_");
                    typeName = typeName.Replace(">", "_");
                }
                if (genericParameter)
                {
                    var genericContainer = metadata.genericContainers[typeDef.genericContainerIndex];
                    typeName += GetGenericContainerParams(genericContainer, generic_decl);
                    if (generic_decl)
                    {
                        return("template " + GetGenericContainerParams(genericContainer, generic_decl));
                    }
                }
            }
            else
            {
                typeName = typeName.Replace("<", "_");
                typeName = typeName.Replace(">", "_");
            }

            //typeName = Il2CppDecompiler.deobfu(typeName);

            return(Il2CppDecompiler.deobfu(prefix + typeName));
        }
Ejemplo n.º 7
0
        private static void Dump(Metadata metadata, Il2Cpp il2Cpp)
        {
            Console.WriteLine("Dumping...");
            var writer     = new StreamWriter(new FileStream("dump.cs", FileMode.Create), new UTF8Encoding(false));
            var decompiler = new Il2CppDecompiler(metadata, il2Cpp);

            decompiler.Decompile(writer, config);
            Console.WriteLine("Done!");
            Console.WriteLine("Generate script...");
            var scriptwriter    = new StreamWriter(new FileStream("script.py", FileMode.Create), new UTF8Encoding(false));
            var scriptGenerator = new ScriptGenerator(metadata, il2Cpp);

            scriptGenerator.WriteScript(scriptwriter, config);
            Console.WriteLine("Done!");
            if (config.DummyDll)
            {
                Console.WriteLine("Generate dummy dll...");
                Console.WriteLine("Select style: 1.Original 2.Original+NET_SDK");
                string netSDKPath = "";
                switch (int.Parse(Console.ReadKey(true).KeyChar.ToString()))
                {
                case 2:
                    Console.WriteLine("Enter path to NET_SDK.dll: ");
                    netSDKPath = Console.ReadLine().Trim();
                    break;
                }
                if (Directory.Exists("DummyDll"))
                {
                    Directory.Delete("DummyDll", true);
                }
                Directory.CreateDirectory("DummyDll");
                Directory.SetCurrentDirectory("DummyDll");
                var dummy = new DummyAssemblyGenerator(metadata, il2Cpp, netSDKPath);
                foreach (var assembly in dummy.Assemblies)
                {
                    using (var stream = new MemoryStream())
                    {
                        assembly.Write(stream);
                        File.WriteAllBytes(assembly.MainModule.Name, stream.ToArray());
                    }
                }
                Console.WriteLine("Done!");
            }
        }
Ejemplo n.º 8
0
        private static void Dump(Metadata metadata, Il2Cpp il2Cpp)
        {
            Console.WriteLine("Dumping...");
            var decompiler = new Il2CppDecompiler(metadata, il2Cpp);

            decompiler.Decompile(config);
            Console.WriteLine("Done!");
            Console.WriteLine("Generate script...");
            var scriptGenerator = new ScriptGenerator(metadata, il2Cpp);

            scriptGenerator.WriteScript(config);
            Console.WriteLine("Done!");
            if (config.DummyDll)
            {
                Console.WriteLine("Generate dummy dll...");
                DummyAssemblyExporter.Export(metadata, il2Cpp);
                Console.WriteLine("Done!");
            }
        }
Ejemplo n.º 9
0
        private static void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
        {
            Console.WriteLine("Dumping...");
            var executor   = new Il2CppExecutor(metadata, il2Cpp);
            var decompiler = new Il2CppDecompiler(executor);

            decompiler.Decompile(config, outputDir);
            Console.WriteLine("Done!");
            if (config.GenerateStruct)
            {
                Console.WriteLine("Generate struct...");
                var scriptGenerator = new StructGenerator(executor);
                scriptGenerator.WriteScript(outputDir);
                Console.WriteLine("Done!");
            }
            if (config.GenerateDummyDll)
            {
                Console.WriteLine("Generate dummy dll...");
                DummyAssemblyExporter.Export(executor, outputDir, config.DummyDllAddToken);
                Console.WriteLine("Done!");
            }
        }
Ejemplo n.º 10
0
        private void Dump(Metadata metadata, Il2Cpp il2Cpp, string outputDir)
        {
            WriteLine("Dumping...");
            var executor   = new Il2CppExecutor(metadata, il2Cpp);
            var decompiler = new Il2CppDecompiler(executor);

            decompiler.Decompile(config, outputDir);
            WriteLine("Done!");
            if (config.GenerateStruct)
            {
                WriteLine("Generate struct...");
                var scriptGenerator = new StructGenerator(executor);
                scriptGenerator.WriteScript(outputDir);
                WriteLine("Done!");
            }
            if (config.GenerateDummyDll)
            {
                WriteLine("Generate dummy dll...");
                DummyAssemblyExporter.Export(executor, outputDir, config.DummyDllAddToken);
                WriteLine("Done!");
                Directory.SetCurrentDirectory(RealPath); //Fix read-only directory permission
            }
        }
Ejemplo n.º 11
0
 public ScriptGenerator(Il2CppDecompiler decompiler)
 {
     this.decompiler = decompiler;
 }
Ejemplo n.º 12
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]);
            }
        }