All readers report format, endianness, word size and instruction set
This commit is contained in:
@@ -20,7 +20,9 @@ namespace Il2CppInspector
|
||||
IEnumerable<IFileFormatReader> Images { get; }
|
||||
IFileFormatReader this[uint index] { get; }
|
||||
long Position { get; set; }
|
||||
string Format { get; }
|
||||
string Arch { get; }
|
||||
int Bits { get; }
|
||||
uint GlobalOffset { get; }
|
||||
Dictionary<string, uint> 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<IFileFormatReader> Images {
|
||||
get {
|
||||
for (uint i = 0; i < NumImages; i++)
|
||||
|
||||
@@ -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>();
|
||||
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<Il2CppInspector>();
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user