This commit is contained in:
Perfare 2020-12-13 03:19:10 +08:00
parent 95173b37a6
commit 7f2817ef12

View file

@ -25,20 +25,22 @@ namespace Il2CppDumper
} }
var fileHeader = ReadClass<FileHeader>(); var fileHeader = ReadClass<FileHeader>();
var pos = Position; var pos = Position;
if (fileHeader.Machine == 0x14c) //Intel 386 var magic = ReadUInt16();
Position -= 2;
if (magic == 0x10b)
{ {
Is32Bit = true; Is32Bit = true;
var optionalHeader = ReadClass<OptionalHeader>(); var optionalHeader = ReadClass<OptionalHeader>();
imageBase = optionalHeader.ImageBase; imageBase = optionalHeader.ImageBase;
} }
else if (fileHeader.Machine == 0x8664) //AMD64 else if (magic == 0x20b)
{ {
var optionalHeader = ReadClass<OptionalHeader64>(); var optionalHeader = ReadClass<OptionalHeader64>();
imageBase = optionalHeader.ImageBase; imageBase = optionalHeader.ImageBase;
} }
else else
{ {
throw new NotSupportedException("ERROR: Unsupported machine."); throw new NotSupportedException($"Invalid Optional header magic {magic}");
} }
Position = pos + fileHeader.SizeOfOptionalHeader; Position = pos + fileHeader.SizeOfOptionalHeader;
sections = ReadClassArray<SectionHeader>(fileHeader.NumberOfSections); sections = ReadClassArray<SectionHeader>(fileHeader.NumberOfSections);