{"record":{"id":"43d8e9da856cd919","repo":"Perfare/Il2CppDumper","slug":"error-invalid-pe-file","errorCode":null,"errorMessage":"ERROR: Invalid PE file","messagePattern":"ERROR: Invalid PE file","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"Il2CppDumper/ExecutableFormats/PE.cs","lineNumber":17,"sourceCode":"﻿using System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Linq;\n\nnamespace Il2CppDumper\n{\n    public sealed class PE : Il2Cpp\n    {\n        private readonly SectionHeader[] sections;\n\n        public PE(Stream stream) : base(stream)\n        {\n            var dosHeader = ReadClass<DosHeader>();\n            if (dosHeader.Magic != 0x5A4D)\n            {\n                throw new InvalidDataException(\"ERROR: Invalid PE file\");\n            }\n            Position = dosHeader.Lfanew;\n            if (ReadUInt32() != 0x4550u) //Signature\n            {\n                throw new InvalidDataException(\"ERROR: Invalid PE file\");\n            }\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            {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/Perfare/Il2CppDumper/blob/4741d46ba9cd6159c5d853eb9d6fc48b4bfa2b1a/Il2CppDumper/ExecutableFormats/PE.cs#L1-L35","documentation":"Thrown by the PE constructor when the stream's DOS header does not begin with the 'MZ' magic (0x5A4D). Il2CppDumper only parses Windows PE executables, so this is the first sanity check on the input binary. It means the file supplied is not a PE executable at all.","triggerScenarios":"Calling new PE(stream) where the first two bytes of the stream are not 'MZ' (0x4D 0x5A), e.g. passing an ELF, Mach-O, NSO, WASM, or metadata file instead of a PE binary.","commonSituations":"Users pass the global-metadata.dat file as the binary, hand the dumper an ELF .so from an Android build, or a corrupted/truncated download whose first bytes are not MZ.","solutions":["Verify the file is a Windows PE: check that it starts with the bytes 4D 5A ('MZ').","Pass the correct binary (GameAssembly.dll / libil2cpp.so path order matters: binary first, metadata second on the CLI).","If the target is ELF (Android), confirm the dumper branch supports it and that you are not feeding it to the PE parser.","Re-download or re-extract the binary; truncated files can lose the header."],"exampleFix":"// before\nvar pe = new PE(File.OpenRead(\"global-metadata.dat\")); // wrong file\n// after\nvar pe = new PE(File.OpenRead(\"GameAssembly.dll\")); // must start with 'MZ'","handlingStrategy":"validation","validationCode":"using var fs = File.OpenRead(path);\nint b0 = fs.ReadByte(), b1 = fs.ReadByte();\nbool isPe = b0 == 0x4D && b1 == 0x5A; // 'MZ'\nfs.Position = 0;\nif (!isPe) throw new InvalidOperationException($\"{path} is not a PE file\");","typeGuard":"static bool IsPeFile(byte[] bytes) => bytes.Length >= 2 && bytes[0] == 0x4D && bytes[1] == 0x5A;","tryCatchPattern":"try { var pe = new PE(stream); }\ncatch (InvalidDataException ex) when (ex.Message == \"ERROR: Invalid PE file\") { /* report wrong binary path */ }","preventionTips":["Always verify the binary's first two bytes are 'MZ' before dumping.","Never pass global-metadata.dat as the binary argument.","Match the dumper branch to the platform (PE for Windows, ELF for Android)."],"tags":["pe","executable-format","invalid-header"],"backgroundTag":"invalid-argument-format","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"}