Exemplo n.º 1
0
        private bool ExtractCurrentData(string il2cppPath, string metadataPath, out Il2Cpp il2Cpp, out Il2CppExecutor executor, out Metadata metadata)
        {
            il2Cpp   = null;
            executor = null;
            metadata = null;
            var metadataBytes = File.ReadAllBytes(metadataPath);

            metadata = new Metadata(new MemoryStream(metadataBytes));

            var il2cppBytes  = File.ReadAllBytes(il2cppPath);
            var il2cppMagic  = BitConverter.ToUInt32(il2cppBytes, 0);
            var il2CppMemory = new MemoryStream(il2cppBytes);

            if (il2cppMagic != IL2CPPMAGIC_PE)
            {
                throw new Exception("Unexpected il2cpp magic number.");
            }

            il2Cpp = new PE(il2CppMemory);

            il2Cpp.SetProperties(metadata.Version, metadata.maxMetadataUsages);

            if (il2Cpp.Version >= 27 && il2Cpp is ElfBase elf && elf.IsDumped)
            {
                metadata.Address = Convert.ToUInt64(Console.ReadLine(), 16);
            }

            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)
                    {
                        il2Cpp = PELoader.Load(il2cppPath);
                        il2Cpp.SetProperties(metadata.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)
                {
                    var codeRegistration     = Convert.ToUInt64(Console.ReadLine(), 16);
                    var metadataRegistration = Convert.ToUInt64(Console.ReadLine(), 16);
                    il2Cpp.Init(codeRegistration, metadataRegistration);
                }
            }
            catch
            {
                throw new Exception("ERROR: An error occurred while processing.");
            }

            executor = new Il2CppExecutor(metadata, il2Cpp);

            return(true);
        }