From 4dc37fa71e91876ea7fe603592b0c5e4c4b31fd3 Mon Sep 17 00:00:00 2001 From: Perfare Date: Fri, 19 Jun 2020 01:22:21 +0800 Subject: [PATCH] =?UTF-8?q?Macho=E5=8A=A0=E5=AF=86=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Il2CppDumper/ExecutableFormats/Macho.cs | 64 +++++++++++++---------- Il2CppDumper/ExecutableFormats/Macho64.cs | 62 +++++++++++++--------- 2 files changed, 73 insertions(+), 53 deletions(-) diff --git a/Il2CppDumper/ExecutableFormats/Macho.cs b/Il2CppDumper/ExecutableFormats/Macho.cs index a55e0ab..41188a3 100644 --- a/Il2CppDumper/ExecutableFormats/Macho.cs +++ b/Il2CppDumper/ExecutableFormats/Macho.cs @@ -25,34 +25,44 @@ namespace Il2CppDumper var pos = Position; var cmd = ReadUInt32(); var cmdsize = ReadUInt32(); - if (cmd == 1) //LC_SEGMENT + switch (cmd) { - var segname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd('\0'); - if (segname == "__TEXT") //__PAGEZERO - { - vmaddr = ReadUInt32(); - } - else - { - Position += 4; - } - Position += 20; //skip vmsize, fileoff, filesize, maxprot, initprot - var nsects = ReadUInt32(); - Position += 4; //skip flags - for (var j = 0; j < nsects; j++) - { - var section = new MachoSection(); - sections.Add(section); - section.sectname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd('\0'); - Position += 16; //skip segname - section.addr = ReadUInt32(); - section.size = ReadUInt32(); - section.offset = ReadUInt32(); - Position += 12; //skip align, reloff, nreloc - section.flags = ReadUInt32(); - section.end = section.addr + section.size; - Position += 8; //skip reserved1, reserved2 - } + case 1: //LC_SEGMENT + var segname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd('\0'); + if (segname == "__TEXT") //__PAGEZERO + { + vmaddr = ReadUInt32(); + } + else + { + Position += 4; + } + Position += 20; //skip vmsize, fileoff, filesize, maxprot, initprot + var nsects = ReadUInt32(); + Position += 4; //skip flags + for (var j = 0; j < nsects; j++) + { + var section = new MachoSection(); + sections.Add(section); + section.sectname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd('\0'); + Position += 16; //skip segname + section.addr = ReadUInt32(); + section.size = ReadUInt32(); + section.offset = ReadUInt32(); + Position += 12; //skip align, reloff, nreloc + section.flags = ReadUInt32(); + section.end = section.addr + section.size; + Position += 8; //skip reserved1, reserved2 + } + break; + case 0x21: //LC_ENCRYPTION_INFO + Position += 8; + var cryptID = ReadUInt32(); + if (cryptID != 0) + { + Console.WriteLine("ERROR: This Mach-O executable is encrypted and cannot be processed."); + } + break; } Position = pos + cmdsize;//next } diff --git a/Il2CppDumper/ExecutableFormats/Macho64.cs b/Il2CppDumper/ExecutableFormats/Macho64.cs index e906d53..f96f232 100644 --- a/Il2CppDumper/ExecutableFormats/Macho64.cs +++ b/Il2CppDumper/ExecutableFormats/Macho64.cs @@ -24,34 +24,44 @@ namespace Il2CppDumper var pos = Position; var cmd = ReadUInt32(); var cmdsize = ReadUInt32(); - if (cmd == 0x19) //LC_SEGMENT_64 + switch (cmd) { - var segname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd('\0'); - if (segname == "__TEXT") //__PAGEZERO - { - vmaddr = ReadUInt64(); - } - else - { + case 0x19: //LC_SEGMENT_64 + var segname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd('\0'); + if (segname == "__TEXT") //__PAGEZERO + { + vmaddr = ReadUInt64(); + } + else + { + Position += 8; + } + Position += 32; //skip vmsize, fileoff, filesize, maxprot, initprot + var nsects = ReadUInt32(); + Position += 4; //skip flags + for (var j = 0; j < nsects; j++) + { + var section = new MachoSection64Bit(); + sections.Add(section); + section.sectname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd('\0'); + Position += 16; //skip segname + section.addr = ReadUInt64(); + section.size = ReadUInt64(); + section.offset = ReadUInt32(); + Position += 12; //skip align, reloff, nreloc + section.flags = ReadUInt32(); + section.end = section.addr + section.size; + Position += 12; //skip reserved1, reserved2, reserved3 + } + break; + case 0x2C: //LC_ENCRYPTION_INFO_64 Position += 8; - } - Position += 32; //skip vmsize, fileoff, filesize, maxprot, initprot - var nsects = ReadUInt32(); - Position += 4; //skip flags - for (var j = 0; j < nsects; j++) - { - var section = new MachoSection64Bit(); - sections.Add(section); - section.sectname = Encoding.UTF8.GetString(ReadBytes(16)).TrimEnd('\0'); - Position += 16; //skip segname - section.addr = ReadUInt64(); - section.size = ReadUInt64(); - section.offset = ReadUInt32(); - Position += 12; //skip align, reloff, nreloc - section.flags = ReadUInt32(); - section.end = section.addr + section.size; - Position += 12; //skip reserved1, reserved2, reserved3 - } + var cryptID = ReadUInt32(); + if (cryptID != 0) + { + Console.WriteLine("ERROR: This Mach-O executable is encrypted and cannot be processed."); + } + break; } Position = pos + cmdsize;//skip }