diff --git a/Il2CppInspector/FileFormatReader.cs b/Il2CppInspector/FileFormatReader.cs index 54f133a..50494bd 100644 --- a/Il2CppInspector/FileFormatReader.cs +++ b/Il2CppInspector/FileFormatReader.cs @@ -20,7 +20,9 @@ namespace Il2CppInspector IEnumerable Images { get; } IFileFormatReader this[uint index] { get; } long Position { get; set; } + string Format { get; } string Arch { get; } + int Bits { get; } uint GlobalOffset { get; } Dictionary GetSymbolTable(); uint[] GetFunctionTable(); @@ -63,8 +65,12 @@ namespace Il2CppInspector public uint GlobalOffset { get; protected set; } + public virtual string Format => throw new NotImplementedException(); + public virtual string Arch => throw new NotImplementedException(); + public virtual int Bits => throw new NotImplementedException(); + public IEnumerable Images { get { for (uint i = 0; i < NumImages; i++) diff --git a/Il2CppInspector/FileFormatReaders/ElfReader.cs b/Il2CppInspector/FileFormatReaders/ElfReader.cs index bfe8bb9..aa555f2 100644 --- a/Il2CppInspector/FileFormatReaders/ElfReader.cs +++ b/Il2CppInspector/FileFormatReaders/ElfReader.cs @@ -21,6 +21,8 @@ namespace Il2CppInspector public ElfReader(Stream stream) : base(stream) { } + public override string Format => "ELF"; + public override string Arch { get { switch (elf_header.e_machine) { @@ -34,6 +36,8 @@ namespace Il2CppInspector } } + public override int Bits => (elf_header.m_arch == 2) ? 64 : 32; + protected override bool Init() { elf_header = ReadObject(); diff --git a/Il2CppInspector/FileFormatReaders/MachOReader.cs b/Il2CppInspector/FileFormatReaders/MachOReader.cs index d1ba9bc..3af456d 100644 --- a/Il2CppInspector/FileFormatReaders/MachOReader.cs +++ b/Il2CppInspector/FileFormatReaders/MachOReader.cs @@ -23,6 +23,8 @@ namespace Il2CppInspector public MachOReader(Stream stream) : base(stream) { } + public override string Format => "Mach-O"; + public override string Arch { get { switch ((MachO)header.CPUType) { @@ -38,6 +40,8 @@ namespace Il2CppInspector } } + public override int Bits => is64 ? 64 : 32; + protected override bool Init() { // Detect endianness - default is little-endianness MachO magic = (MachO)ReadUInt32(); @@ -48,8 +52,6 @@ namespace Il2CppInspector return false; } - Console.WriteLine("Endianness: {0}", Endianness); - Position -= sizeof(uint); header = ReadObject(); @@ -59,14 +61,11 @@ namespace Il2CppInspector is64 = true; ReadUInt32(); } - Console.WriteLine("Architecture: {0}-bit", is64 ? 64 : 32); // Must be executable file if ((MachO) header.FileType != MachO.MH_EXECUTE) return false; - Console.WriteLine("CPU Type: " + (MachO)header.CPUType); - MachOLinkEditDataCommand functionStarts = null; for (var c = 0; c < header.NumCommands; c++) { diff --git a/Il2CppInspector/FileFormatReaders/PEReader.cs b/Il2CppInspector/FileFormatReaders/PEReader.cs index 38405ef..47f883d 100644 --- a/Il2CppInspector/FileFormatReaders/PEReader.cs +++ b/Il2CppInspector/FileFormatReaders/PEReader.cs @@ -19,6 +19,8 @@ namespace Il2CppInspector public PEReader(Stream stream) : base(stream) {} + public override string Format => "PE"; + public override string Arch { get { switch (coff.Machine) { @@ -33,6 +35,11 @@ namespace Il2CppInspector } } + // IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20B + // IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10B + // Could also use coff.Characteristics (IMAGE_FILE_32BIT_MACHINE) or coff.Machine + public override int Bits => pe.signature == 0x20B ? 64 : 32; + protected override bool Init() { // Check for MZ signature "MZ" if (ReadUInt16() != 0x5A4D) diff --git a/Il2CppInspector/Il2CppInspector.cs b/Il2CppInspector/Il2CppInspector.cs index 148e5dd..abcb45b 100644 --- a/Il2CppInspector/Il2CppInspector.cs +++ b/Il2CppInspector/Il2CppInspector.cs @@ -4,6 +4,7 @@ All rights reserved. */ +using NoisyCowStudios.Bin2Object; using System; using System.Collections.Generic; using System.IO; @@ -167,6 +168,11 @@ namespace Il2CppInspector // Multi-image binaries may contain more than one Il2Cpp image var processors = new List(); foreach (var image in stream.Images) { + Console.WriteLine("Container format: " + image.Format); + Console.WriteLine("Container endianness: " + ((BinaryObjectReader) image).Endianness); + Console.WriteLine("Architecture word size: {0}-bit", image.Bits); + Console.WriteLine("Instruction set: " + image.Arch); + // Architecture-agnostic load attempt if (Il2CppBinary.Load(image, metadata.Version) is Il2CppBinary binary) { processors.Add(new Il2CppInspector(binary, metadata));