All readers report format, endianness, word size and instruction set

This commit is contained in:
Katy Coe
2019-10-21 14:00:13 +02:00
parent de7218602e
commit e46cca08e0
5 changed files with 27 additions and 5 deletions

View File

@@ -20,7 +20,9 @@ namespace Il2CppInspector
IEnumerable<IFileFormatReader> Images { get; } IEnumerable<IFileFormatReader> Images { get; }
IFileFormatReader this[uint index] { get; } IFileFormatReader this[uint index] { get; }
long Position { get; set; } long Position { get; set; }
string Format { get; }
string Arch { get; } string Arch { get; }
int Bits { get; }
uint GlobalOffset { get; } uint GlobalOffset { get; }
Dictionary<string, uint> GetSymbolTable(); Dictionary<string, uint> GetSymbolTable();
uint[] GetFunctionTable(); uint[] GetFunctionTable();
@@ -63,8 +65,12 @@ namespace Il2CppInspector
public uint GlobalOffset { get; protected set; } public uint GlobalOffset { get; protected set; }
public virtual string Format => throw new NotImplementedException();
public virtual string Arch => throw new NotImplementedException(); public virtual string Arch => throw new NotImplementedException();
public virtual int Bits => throw new NotImplementedException();
public IEnumerable<IFileFormatReader> Images { public IEnumerable<IFileFormatReader> Images {
get { get {
for (uint i = 0; i < NumImages; i++) for (uint i = 0; i < NumImages; i++)

View File

@@ -21,6 +21,8 @@ namespace Il2CppInspector
public ElfReader(Stream stream) : base(stream) { } public ElfReader(Stream stream) : base(stream) { }
public override string Format => "ELF";
public override string Arch { public override string Arch {
get { get {
switch (elf_header.e_machine) { 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() { protected override bool Init() {
elf_header = ReadObject<elf_header>(); elf_header = ReadObject<elf_header>();

View File

@@ -23,6 +23,8 @@ namespace Il2CppInspector
public MachOReader(Stream stream) : base(stream) { } public MachOReader(Stream stream) : base(stream) { }
public override string Format => "Mach-O";
public override string Arch { public override string Arch {
get { get {
switch ((MachO)header.CPUType) { switch ((MachO)header.CPUType) {
@@ -38,6 +40,8 @@ namespace Il2CppInspector
} }
} }
public override int Bits => is64 ? 64 : 32;
protected override bool Init() { protected override bool Init() {
// Detect endianness - default is little-endianness // Detect endianness - default is little-endianness
MachO magic = (MachO)ReadUInt32(); MachO magic = (MachO)ReadUInt32();
@@ -48,8 +52,6 @@ namespace Il2CppInspector
return false; return false;
} }
Console.WriteLine("Endianness: {0}", Endianness);
Position -= sizeof(uint); Position -= sizeof(uint);
header = ReadObject<MachOHeader>(); header = ReadObject<MachOHeader>();
@@ -59,14 +61,11 @@ namespace Il2CppInspector
is64 = true; is64 = true;
ReadUInt32(); ReadUInt32();
} }
Console.WriteLine("Architecture: {0}-bit", is64 ? 64 : 32);
// Must be executable file // Must be executable file
if ((MachO) header.FileType != MachO.MH_EXECUTE) if ((MachO) header.FileType != MachO.MH_EXECUTE)
return false; return false;
Console.WriteLine("CPU Type: " + (MachO)header.CPUType);
MachOLinkEditDataCommand functionStarts = null; MachOLinkEditDataCommand functionStarts = null;
for (var c = 0; c < header.NumCommands; c++) { for (var c = 0; c < header.NumCommands; c++) {

View File

@@ -19,6 +19,8 @@ namespace Il2CppInspector
public PEReader(Stream stream) : base(stream) {} public PEReader(Stream stream) : base(stream) {}
public override string Format => "PE";
public override string Arch { public override string Arch {
get { get {
switch (coff.Machine) { 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() { protected override bool Init() {
// Check for MZ signature "MZ" // Check for MZ signature "MZ"
if (ReadUInt16() != 0x5A4D) if (ReadUInt16() != 0x5A4D)

View File

@@ -4,6 +4,7 @@
All rights reserved. All rights reserved.
*/ */
using NoisyCowStudios.Bin2Object;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -167,6 +168,11 @@ namespace Il2CppInspector
// Multi-image binaries may contain more than one Il2Cpp image // Multi-image binaries may contain more than one Il2Cpp image
var processors = new List<Il2CppInspector>(); var processors = new List<Il2CppInspector>();
foreach (var image in stream.Images) { 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 // Architecture-agnostic load attempt
if (Il2CppBinary.Load(image, metadata.Version) is Il2CppBinary binary) { if (Il2CppBinary.Load(image, metadata.Version) is Il2CppBinary binary) {
processors.Add(new Il2CppInspector(binary, metadata)); processors.Add(new Il2CppInspector(binary, metadata));