{"record":{"id":"fabd444ecb860f60","repo":"Perfare/Il2CppDumper","slug":"invalid-optional-header-magic-magic","errorCode":null,"errorMessage":"Invalid Optional header magic {magic}","messagePattern":"Invalid Optional header magic (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"Il2CppDumper/ExecutableFormats/PE.cs","lineNumber":41,"sourceCode":"            }\n            var fileHeader = ReadClass<FileHeader>();\n            var pos = Position;\n            var magic = ReadUInt16();\n            Position -= 2;\n            if (magic == 0x10b)\n            {\n                Is32Bit = true;\n                var optionalHeader = ReadClass<OptionalHeader>();\n                ImageBase = optionalHeader.ImageBase;\n            }\n            else if (magic == 0x20b)\n            {\n                var optionalHeader = ReadClass<OptionalHeader64>();\n                ImageBase = optionalHeader.ImageBase;\n            }\n            else\n            {\n                throw new NotSupportedException($\"Invalid Optional header magic {magic}\");\n            }\n            Position = pos + fileHeader.SizeOfOptionalHeader;\n            sections = ReadClassArray<SectionHeader>(fileHeader.NumberOfSections);\n        }\n\n        public void LoadFromMemory(ulong addr)\n        {\n            ImageBase = addr;\n            foreach (var section in sections)\n            {\n                section.PointerToRawData = section.VirtualAddress;\n                section.SizeOfRawData = section.VirtualSize;\n            }\n        }\n\n        public override ulong MapVATR(ulong absAddr)\n        {\n            var addr = absAddr - ImageBase;","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Perfare/Il2CppDumper/blob/4741d46ba9cd6159c5d853eb9d6fc48b4bfa2b1a/Il2CppDumper/ExecutableFormats/PE.cs#L23-L59","documentation":"Thrown during PE header parsing after the PE signature and COFF FileHeader have been read. The first UInt16 of the Optional Header (the magic) determines whether the image is PE32 (0x10b, 32-bit, parsed with OptionalHeader) or PE32+ (0x20b, 64-bit, parsed with OptionalHeader64). Any other value means the file is not a valid PE executable — it may be corrupted, truncated, or an entirely different format misidentified as PE — so the parser cannot determine the image bitness or locate the ImageBase and aborts by raising this NotSupportedException at Il2CppDumper/ExecutableFormats/PE.cs:41. The faulting input is the Optional Header magic field of the loaded file.","triggerScenarios":"Calling new PE(stream) on a PE whose optional header magic read at FileHeader end is not 0x10b or 0x20b — e.g. ROM images, unknown/corrupt optional headers, or files where SizeOfOptionalHeader/magic got mangled.","commonSituations":"Dumping non-standard PE derivatives (Xbox/UWP custom headers), files hand-edited or corrupted in transit, or obfuscated/packed binaries that scrambled the optional header.","solutions":["Confirm the binary is a standard PE32 (magic 0x10b) or PE32+ (magic 0x20b) using a tool like CFF Explorer or pestudio.","Re-obtain the original GameAssembly.dll without post-processing/packing that alters headers.","If the file is a console/custom PE variant, this dumper does not support it; use a platform-specific extraction tool first.","Verify the file hash against the original build output to rule out corruption."],"exampleFix":"// before\n// magic read as 0x020C (ROM image) -> NotSupportedException\n// after\n// supply a standard PE: check bytes at PE offset + 24 == 0x0B01 or 0x0B02 (LE)","handlingStrategy":"validation","validationCode":"byte[] b = File.ReadAllBytes(path);\nuint off = BitConverter.ToUInt32(b, 0x3C);\nushort magic = BitConverter.ToUInt16(b, (int)off + 24);\nbool ok = magic == 0x10b || magic == 0x20b; // PE32 or PE32+","typeGuard":"static bool IsStandardPeOptionalHeader(byte[] b) { uint o = BitConverter.ToUInt32(b, 0x3C); ushort m = BitConverter.ToUInt16(b, (int)o + 24); return m is 0x10b or 0x20b; }","tryCatchPattern":"try { var pe = new PE(stream); }\ncatch (NotSupportedException ex) when (ex.Message.StartsWith(\"Invalid Optional header magic\")) { /* unsupported PE variant */ }","preventionTips":["Confirm with a PE editor that the optional header magic is 0x10b or 0x20b.","Avoid packed/protected builds that mangle optional headers; unpack first.","Keep the original unmodified GameAssembly.dll from the build output."],"tags":["pe","optional-header","unsupported-format"],"backgroundTag":"unsupported-enum-value","analyzedSha":"4741d46ba9cd6159c5d853eb9d6fc48b4bfa2b1a","analyzedAt":"2026-09-11T16:52:42.117Z","contentChangedAt":"2026-09-11T16:52:42.117Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}