Exemplo n.º 1
0
        private static bool Init(string il2cppPath, string metadataPath, out Metadata metadata, out Il2Cpp il2Cpp)
        {
            Console.WriteLine("Initializing metadata...");
            var metadataBytes = File.ReadAllBytes(metadataPath);

            metadata = new Metadata(new MemoryStream(metadataBytes));
            Console.WriteLine($"Metadata Version: {metadata.Version}");

            Console.WriteLine("Initializing il2cpp file...");
            var il2cppBytes  = File.ReadAllBytes(il2cppPath);
            var il2cppMagic  = BitConverter.ToUInt32(il2cppBytes, 0);
            var il2CppMemory = new MemoryStream(il2cppBytes);

            switch (il2cppMagic)
            {
            default:
                throw new NotSupportedException("ERROR: il2cpp file not supported.");

            case 0x6D736100:
                var web = new WebAssembly(il2CppMemory);
                il2Cpp = web.CreateMemory();
                break;

            case 0x304F534E:
                var nso = new NSO(il2CppMemory);
                il2Cpp = nso.UnCompress();
                break;

            case 0x905A4D:     //PE
                il2Cpp = new PE(il2CppMemory);
                break;

            case 0x464c457f:             //ELF
                if (il2cppBytes[4] == 2) //ELF64
                {
                    il2Cpp = new Elf64(il2CppMemory);
                }
                else
                {
                    il2Cpp = new Elf(il2CppMemory);
                }
                break;

            case 0xCAFEBABE:     //FAT Mach-O
            case 0xBEBAFECA:
                var machofat = new MachoFat(new MemoryStream(il2cppBytes));
                Console.Write("Select Platform: ");
                for (var i = 0; i < machofat.fats.Length; i++)
                {
                    var fat = machofat.fats[i];
                    Console.Write(fat.magic == 0xFEEDFACF ? $"{i + 1}.64bit " : $"{i + 1}.32bit ");
                }
                Console.WriteLine();
                var key   = Console.ReadKey(true);
                var index = int.Parse(key.KeyChar.ToString()) - 1;
                var magic = machofat.fats[index % 2].magic;
                il2cppBytes  = machofat.GetMacho(index % 2);
                il2CppMemory = new MemoryStream(il2cppBytes);
                if (magic == 0xFEEDFACF)
                {
                    goto case 0xFEEDFACF;
                }
                else
                {
                    goto case 0xFEEDFACE;
                }

            case 0xFEEDFACF:     // 64bit Mach-O
                il2Cpp = new Macho64(il2CppMemory);
                break;

            case 0xFEEDFACE:     // 32bit Mach-O
                il2Cpp = new Macho(il2CppMemory);
                break;
            }
            var version = config.ForceIl2CppVersion ? config.ForceVersion : metadata.Version;

            il2Cpp.SetProperties(version, metadata.maxMetadataUsages);
            Console.WriteLine($"Il2Cpp Version: {il2Cpp.Version}");
            if (il2Cpp.Version >= 27 && il2Cpp is ElfBase elf && elf.IsDumped)
            {
                Console.WriteLine("Input global-metadata.dat dump address:");
                metadata.Address = Convert.ToUInt64(Console.ReadLine(), 16);
            }


            Console.WriteLine("Searching...");
            try
            {
                //var flag = il2Cpp.PlusSearch(metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length);
                var flag = false;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (!flag && il2Cpp is PE)
                    {
                        Console.WriteLine("Use custom PE loader");
                        il2Cpp = PELoader.Load(il2cppPath);
                        il2Cpp.SetProperties(version, metadata.maxMetadataUsages);
                        //flag = il2Cpp.PlusSearch(metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length);
                    }
                }

                /*if (!flag)
                 * {
                 *  flag = il2Cpp.Search();
                 * }
                 * if (!flag)
                 * {
                 *  flag = il2Cpp.SymbolSearch();
                 * }*/
                if (true)
                {
                    /*Console.WriteLine("ERROR: Can't use auto mode to process file, try manual mode.");
                     * Console.Write("Input CodeRegistration: ");
                     * var codeRegistration = Convert.ToUInt64(Console.ReadLine(), 16);
                     * Console.Write("Input MetadataRegistration: ");
                     * var metadataRegistration = Convert.ToUInt64(Console.ReadLine(), 16);*/
                    ProcessModuleCollection pms = Process.GetCurrentProcess().Modules;
                    ulong baseaddr = 0;
                    foreach (ProcessModule pm in pms)
                    {
                        if (pm.ModuleName == "UserAssembly.dll")
                        {
                            baseaddr = (ulong)pm.BaseAddress;
                            break;
                        }
                    }
                    Console.WriteLine("baseadr: 0x" + baseaddr.ToString("x2"));
                    var codeRegistration     = baseaddr + 0x72A0810;
                    var metadataRegistration = baseaddr + 0x7FBF040;
                    il2Cpp.Init(codeRegistration, metadataRegistration);
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("ERROR: An error occurred while processing.");
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        private static bool Init(byte[] il2cppBytes, byte[] metadataBytes, string stringVersion, int mode, out Metadata metadata, out Il2Cpp il2Cpp)
        {
            var sanity = BitConverter.ToUInt32(metadataBytes, 0);

            if (sanity != 0xFAB11BAF)
            {
                throw new Exception("ERROR: Metadata file supplied is not valid metadata file.");
            }
            float fixedMetadataVersion;
            var   metadataVersion = BitConverter.ToInt32(metadataBytes, 4);

            if (metadataVersion == 24)
            {
                if (stringVersion == null)
                {
                    Console.WriteLine("Input Unity version: ");
                    stringVersion = Console.ReadLine();
                }
                try
                {
                    var versionSplit = Array.ConvertAll(Regex.Replace(stringVersion, @"\D", ".").Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries), int.Parse);
                    var unityVersion = new Version(versionSplit[0], versionSplit[1]);
                    if (unityVersion >= Unity20191)
                    {
                        fixedMetadataVersion = 24.2f;
                    }
                    else if (unityVersion >= Unity20183)
                    {
                        fixedMetadataVersion = 24.1f;
                    }
                    else
                    {
                        fixedMetadataVersion = metadataVersion;
                    }
                }
                catch
                {
                    throw new Exception("You must enter the correct Unity version number");
                }
            }
            else
            {
                fixedMetadataVersion = metadataVersion;
            }
            Console.WriteLine("Initializing metadata...");
            metadata = new Metadata(new MemoryStream(metadataBytes), fixedMetadataVersion);
            //判断il2cpp的magic
            var il2cppMagic = BitConverter.ToUInt32(il2cppBytes, 0);
            var isElf       = false;
            var isPE        = false;
            var is64bit     = false;
            var isNSO       = false;

            switch (il2cppMagic)
            {
            default:
                throw new Exception("ERROR: il2cpp file not supported.");

            case 0x304F534E:
                isNSO   = true;
                is64bit = true;
                break;

            case 0x905A4D:     //PE
                isPE = true;
                break;

            case 0x464c457f:             //ELF
                isElf = true;
                if (il2cppBytes[4] == 2) //ELF64
                {
                    is64bit = true;
                }
                break;

            case 0xCAFEBABE:     //FAT Mach-O
            case 0xBEBAFECA:
                var machofat = new MachoFat(new MemoryStream(il2cppBytes));
                Console.Write("Select Platform: ");
                for (var i = 0; i < machofat.fats.Length; i++)
                {
                    var fat = machofat.fats[i];
                    Console.Write(fat.magic == 0xFEEDFACF ? $"{i + 1}.64bit " : $"{i + 1}.32bit ");
                }
                Console.WriteLine();
                var key   = Console.ReadKey(true);
                var index = int.Parse(key.KeyChar.ToString()) - 1;
                var magic = machofat.fats[index % 2].magic;
                il2cppBytes = machofat.GetMacho(index % 2);
                if (magic == 0xFEEDFACF)
                {
                    goto case 0xFEEDFACF;
                }
                else
                {
                    goto case 0xFEEDFACE;
                }

            case 0xFEEDFACF:     // 64bit Mach-O
                is64bit = true;
                break;

            case 0xFEEDFACE:     // 32bit Mach-O
                break;
            }

            var version = config.ForceIl2CppVersion ? config.ForceVersion : metadata.version;

            Console.WriteLine("Initializing il2cpp file...");
            if (isNSO)
            {
                var nso = new NSO(new MemoryStream(il2cppBytes), version, metadata.maxMetadataUsages);
                il2Cpp = nso.UnCompress();
            }
            else if (isPE)
            {
                il2Cpp = new PE(new MemoryStream(il2cppBytes), version, metadata.maxMetadataUsages);
            }
            else if (isElf)
            {
                if (is64bit)
                {
                    il2Cpp = new Elf64(new MemoryStream(il2cppBytes), version, metadata.maxMetadataUsages);
                }
                else
                {
                    il2Cpp = new Elf(new MemoryStream(il2cppBytes), version, metadata.maxMetadataUsages);
                }
            }
            else if (is64bit)
            {
                il2Cpp = new Macho64(new MemoryStream(il2cppBytes), version, metadata.maxMetadataUsages);
            }
            else
            {
                il2Cpp = new Macho(new MemoryStream(il2cppBytes), version, metadata.maxMetadataUsages);
            }

            if (mode == 0)
            {
                Console.WriteLine("Select Mode: 1.Manual 2.Auto 3.Auto(Plus) 4.Auto(Symbol)");
                var modeKey = Console.ReadKey(true);
                mode = int.Parse(modeKey.KeyChar.ToString());
            }
            if (mode != 1)
            {
                Console.WriteLine("Searching...");
            }
            try
            {
                bool flag;
                switch (mode)
                {
                case 1:     //Manual
                    Console.Write("Input CodeRegistration: ");
                    var codeRegistration = Convert.ToUInt64(Console.ReadLine(), 16);
                    Console.Write("Input MetadataRegistration: ");
                    var metadataRegistration = Convert.ToUInt64(Console.ReadLine(), 16);
                    il2Cpp.Init(codeRegistration, metadataRegistration);
                    flag = true;
                    break;

                case 2:     //Auto
                    flag = il2Cpp.Search();
                    break;

                case 3:     //Auto(Plus)
                    flag = il2Cpp.PlusSearch(metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length);
                    break;

                case 4:     //Auto(Symbol)
                    flag = il2Cpp.SymbolSearch();
                    break;

                default:
                    Console.WriteLine("ERROR: You have to choose a mode.");
                    return(false);
                }
                if (!flag)
                {
                    throw new Exception();
                }
            }
            catch
            {
                throw new Exception("ERROR: Can't use this mode to process file, try another mode.");
            }
            return(true);
        }
Exemplo n.º 3
0
        private bool Init(string il2cppPath, string metadataPath, out Metadata metadata, out Il2Cpp il2Cpp)
        {
            string Mach_O = "2";

            Invoke(new Action(delegate()
            {
                if (!iOSSwitch.Value)
                {
                    Mach_O = "1";
                }
            }));

            LogOutput("Read config...");
            if (File.Exists(RealPath + "config.json"))
            {
                config = JsonConvert.DeserializeObject <Config>(File.ReadAllText(Application.StartupPath + Path.DirectorySeparatorChar + @"config.json"));
            }
            else
            {
                config = new Config();
                LogOutput("config.json file does not exist. Using defaults", Color.Yellow);
            }

            LogOutput("Initializing metadata...");
            var metadataBytes = File.ReadAllBytes(metadataPath);

            metadata = new Metadata(new MemoryStream(metadataBytes));
            LogOutput($"Metadata Version: {metadata.Version}");
            LogOutput("Initializing il2cpp file...");
            var il2cppBytes  = File.ReadAllBytes(il2cppPath);
            var il2cppMagic  = BitConverter.ToUInt32(il2cppBytes, 0);
            var il2CppMemory = new MemoryStream(il2cppBytes);

            switch (il2cppMagic)
            {
            default:
                throw new NotSupportedException("ERROR: il2cpp file not supported.");

            case 0x6D736100:
                var web = new WebAssembly(il2CppMemory);
                il2Cpp = web.CreateMemory();
                break;

            case 0x304F534E:
                var nso = new NSO(il2CppMemory);
                il2Cpp = nso.UnCompress();
                break;

            case 0x905A4D:     //PE
                il2Cpp = new PE(il2CppMemory);
                break;

            case 0x464c457f:             //ELF
                if (il2cppBytes[4] == 2) //ELF64
                {
                    il2Cpp = new Elf64(il2CppMemory);
                }
                else
                {
                    il2Cpp = new Elf(il2CppMemory);
                }
                break;

            case 0xCAFEBABE:     //FAT Mach-O
            case 0xBEBAFECA:
                var machofat = new MachoFat(new MemoryStream(il2cppBytes));
                for (var i = 0; i < machofat.fats.Length; i++)
                {
                    var fat = machofat.fats[i];
                    //Console.Write(fat.magic == 0xFEEDFACF ? $"{i + 1}.64bit " : $"{i + 1}.32bit ");
                }
                var index = int.Parse(Mach_O) - 1;
                var magic = machofat.fats[index % 2].magic;
                il2cppBytes  = machofat.GetMacho(index % 2);
                il2CppMemory = new MemoryStream(il2cppBytes);
                if (magic == 0xFEEDFACF)
                {
                    goto case 0xFEEDFACF;
                }
                else
                {
                    goto case 0xFEEDFACE;
                }

            case 0xFEEDFACF:     // 64bit Mach-O
                il2Cpp = new Macho64(il2CppMemory);
                break;

            case 0xFEEDFACE:     // 32bit Mach-O
                il2Cpp = new Macho(il2CppMemory);
                break;
            }

            var version = config.ForceIl2CppVersion ? config.ForceVersion : metadata.Version;

            il2Cpp.SetProperties(version, metadata.maxMetadataUsages);
            LogOutput($"Il2Cpp Version: {il2Cpp.Version}");
            if (il2Cpp.Version >= 27 && il2Cpp is ElfBase elf && elf.IsDumped)
            {
                FormDump form = new FormDump();
                form.dumpNoteLbl.Text = "Input global-metadata.dat dump address:";
                form.Message          = 0;
                if (form.ShowDialog() == DialogResult.OK)
                {
                    metadata.Address = Convert.ToUInt64(Console.ReadLine(), 16);
                    LogOutput("Inputted address: " + metadata.Address.ToString("X"));
                }
            }

            LogOutput("Searching...");
            try
            {
                var flag = il2Cpp.PlusSearch(metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length, metadata.imageDefs.Length);
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (!flag && il2Cpp is PE)
                    {
                        LogOutput("Use custom PE loader");
                        il2Cpp = PELoader.Load(il2cppPath);
                        il2Cpp.SetProperties(version, metadata.maxMetadataUsages);
                        flag = il2Cpp.PlusSearch(metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length, metadata.imageDefs.Length);
                    }
                }
                if (!flag)
                {
                    flag = il2Cpp.Search();
                }
                if (!flag)
                {
                    flag = il2Cpp.SymbolSearch();
                }
                if (!flag)
                {
                    LogOutput("ERROR: Can't use auto mode to process file, input offset pointers to try manual mode.", Color.Yellow);
                    var codeRegistration     = Convert.ToUInt64(CodeRegistrationTxtBox.Text, 16);
                    var metadataRegistration = Convert.ToUInt64(metadataRegistrationTxtBox.Text, 16);
                    il2Cpp.Init(codeRegistration, metadataRegistration);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogOutput("An error occurred while processing.", Color.Red);
#if DEBUG
                LogOutput(ex.ToString());
#else
                LogOutput(ex.Message, Color.Red);
#endif
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        private static bool Init(byte[] il2cppBytes, byte[] metadataBytes, out Metadata metadata, out Il2Cpp il2Cpp)
        {
            var sanity = BitConverter.ToUInt32(metadataBytes, 0);

            if (sanity != 0xFAB11BAF)
            {
                throw new InvalidDataException("ERROR: Metadata file supplied is not valid metadata file.");
            }
            Console.WriteLine("Initializing metadata...");
            metadata = new Metadata(new MemoryStream(metadataBytes));
            Console.WriteLine($"Metadata Version: {metadata.Version}");

            Console.WriteLine("Initializing il2cpp file...");
            var il2cppMagic  = BitConverter.ToUInt32(il2cppBytes, 0);
            var il2CppMemory = new MemoryStream(il2cppBytes);

            switch (il2cppMagic)
            {
            default:
                throw new NotSupportedException("ERROR: il2cpp file not supported.");

            case 0x6D736100:
                var web = new WebAssembly(il2CppMemory);
                il2Cpp = web.CreateMemory();
                break;

            case 0x304F534E:
                var nso = new NSO(il2CppMemory);
                il2Cpp = nso.UnCompress();
                break;

            case 0x905A4D:     //PE
                il2Cpp = new PE(il2CppMemory);
                break;

            case 0x464c457f:             //ELF
                if (il2cppBytes[4] == 2) //ELF64
                {
                    il2Cpp = new Elf64(il2CppMemory);
                }
                else
                {
                    il2Cpp = new Elf(il2CppMemory);
                }
                break;

            case 0xCAFEBABE:     //FAT Mach-O
            case 0xBEBAFECA:
                var machofat = new MachoFat(new MemoryStream(il2cppBytes));
                Console.Write("Select Platform: ");
                for (var i = 0; i < machofat.fats.Length; i++)
                {
                    var fat = machofat.fats[i];
                    Console.Write(fat.magic == 0xFEEDFACF ? $"{i + 1}.64bit " : $"{i + 1}.32bit ");
                }
                Console.WriteLine();
                var key   = Console.ReadKey(true);
                var index = int.Parse(key.KeyChar.ToString()) - 1;
                var magic = machofat.fats[index % 2].magic;
                il2cppBytes  = machofat.GetMacho(index % 2);
                il2CppMemory = new MemoryStream(il2cppBytes);
                if (magic == 0xFEEDFACF)
                {
                    goto case 0xFEEDFACF;
                }
                else
                {
                    goto case 0xFEEDFACE;
                }

            case 0xFEEDFACF:     // 64bit Mach-O
                il2Cpp = new Macho64(il2CppMemory);
                break;

            case 0xFEEDFACE:     // 32bit Mach-O
                il2Cpp = new Macho(il2CppMemory);
                break;
            }
            var version = config.ForceIl2CppVersion ? config.ForceVersion : metadata.Version;

            il2Cpp.SetProperties(version, metadata.maxMetadataUsages);
            Console.WriteLine($"Il2Cpp Version: {il2Cpp.Version}");

            Console.WriteLine("Searching...");
            try
            {
                var flag = il2Cpp.PlusSearch(metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length);
                if (!flag)
                {
                    flag = il2Cpp.Search();
                }
                if (!flag)
                {
                    flag = il2Cpp.SymbolSearch();
                }
                if (!flag)
                {
                    Console.WriteLine("ERROR: Can't use auto mode to process file, try manual mode.");
                    Console.Write("Input CodeRegistration: ");
                    var codeRegistration = Convert.ToUInt64(Console.ReadLine(), 16);
                    Console.Write("Input MetadataRegistration: ");
                    var metadataRegistration = Convert.ToUInt64(Console.ReadLine(), 16);
                    il2Cpp.Init(codeRegistration, metadataRegistration);
                    return(true);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine("ERROR: An error occurred while processing.");
                return(false);
            }
            return(true);
        }