Example #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));
        }
        public static List <Il2CppInspector> 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, PE, Mach-O and Universal Binary)
            var memoryStream         = new MemoryStream(File.ReadAllBytes(codeFile));
            IFileFormatReader stream =
                (((IFileFormatReader)ElfReader.Load(memoryStream) ??
                  PEReader.Load(memoryStream)) ??
                 MachOReader.Load(memoryStream)) ??
                UBReader.Load(memoryStream);

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

            // Multi-image binaries may contain more than one Il2Cpp image
            var processors = new List <Il2CppInspector>();

            foreach (var image in stream.Images)
            {
                Il2CppBinary binary;

                // We are currently supporting x86 and ARM architectures
                switch (image.Arch)
                {
                case "x86":
                    binary = new Il2CppBinaryX86(image);
                    break;

                case "ARM":
                    binary = new Il2CppBinaryARM(image);
                    break;

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

                // Find code and metadata regions
                if (!binary.Initialize(metadata.Version))
                {
                    Console.Error.WriteLine("Could not process IL2CPP image");
                }
                else
                {
                    processors.Add(new Il2CppInspector(binary, metadata));
                }
            }
            return(processors);
        }
Example #3
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));
        }