Ejemplo n.º 1
0
        public static Il2CppProcessor LoadFromFile(string codeFile, string metadataFile)
        {
            // Load the metadata file
            Metadata metadata;

            try {
                metadata = new Metadata(new MemoryStream(File.ReadAllBytes(metadataFile)));
            }
            catch (Exception ex) {
                Console.Error.WriteLine(ex.Message);
                return(null);
            }

            // Load the il2cpp code file (try ELF and PE)
            var memoryStream         = new MemoryStream(File.ReadAllBytes(codeFile));
            IFileFormatReader stream =
                ((IFileFormatReader)ElfReader.Load(memoryStream) ??
                 PEReader.Load(memoryStream)) ??
                MachOReader.Load(memoryStream);

            if (stream == null)
            {
                Console.Error.WriteLine("Unsupported executable file format");
                return(null);
            }

            Il2CppReader il2cpp;

            // We are currently supporting x86 and ARM architectures
            switch (stream.Arch)
            {
            case "x86":
                il2cpp = new Il2CppReaderX86(stream);
                break;

            case "ARM":
                il2cpp = new Il2CppReaderARM(stream);
                break;

            default:
                Console.Error.WriteLine("Unsupported architecture");
                return(null);
            }

            // Find code and metadata regions
            if (!il2cpp.Load(metadata.Version))
            {
                Console.Error.WriteLine("Could not process IL2CPP image");
                return(null);
            }

            return(new Il2CppProcessor(il2cpp, metadata));
        }
Ejemplo n.º 2
0
        public static Il2CppProcessor LoadFromFile(string codeFile, string metadataFile)
        {
            logger.Info("Loading metadata file...");
            var metadata = new Metadata(new MemoryStream(File.ReadAllBytes(metadataFile)));

            logger.Info("Loading binary file...");
            var memoryStream = new MemoryStream(File.ReadAllBytes(codeFile));

            IFileFormatReader stream = null;

            if (codeFile.ToLower().EndsWith(".so"))
            {
                logger.Debug("Using ELF reader.");
                stream = ElfReader.Load(memoryStream);
            }
            else if (codeFile.ToLower().EndsWith(".dll"))
            {
                logger.Debug("Using PE reader.");
                stream = PEReader.Load(memoryStream);
            }
            else
            {
                logger.Debug("Using MachO reader.");
                stream = MachOReader.Load(memoryStream);
            }

            if (stream == null)
            {
                logger.Error("Unsupported executable file format.");
                return(null);
            }

            Il2CppReader il2cpp;

            // We are currently supporting x86 and ARM architectures
            switch (stream.Arch)
            {
            case "x86":
                il2cpp = new Il2CppReaderX86(stream);
                break;

            case "ARM":
                if (stream.Is64bits)
                {
                    il2cpp = new Il2CppReaderARM64(stream);
                }
                else
                {
                    il2cpp = new Il2CppReaderARM(stream);
                }
                break;

            default:
                logger.Error("Unsupported architecture: {0}", stream.Arch);
                return(null);
            }

            // Find code and metadata regions
            if (!il2cpp.Load())
            {
                logger.Error("Could not process IL2CPP image");
                return(null);
            }

            return(new Il2CppProcessor(il2cpp, metadata));
        }