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

@@ -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<elf_header>();

View File

@@ -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<MachOHeader>();
@@ -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++) {

View File

@@ -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)