Perfare/Il2CppDumper · error · InvalidDataException

ERROR: Invalid PE file

Error message

ERROR: Invalid PE file

What it means

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.

Solutions

  1. Verify the file is a Windows PE: check that it starts with the bytes 4D 5A ('MZ').
  2. Pass the correct binary (GameAssembly.dll / libil2cpp.so path order matters: binary first, metadata second on the CLI).
  3. If the target is ELF (Android), confirm the dumper branch supports it and that you are not feeding it to the PE parser.
  4. Re-download or re-extract the binary; truncated files can lose the header.

Example fix

// before
var pe = new PE(File.OpenRead("global-metadata.dat")); // wrong file
// after
var pe = new PE(File.OpenRead("GameAssembly.dll")); // must start with 'MZ'
Defensive patterns

Strategy: validation

Validate before calling

using var fs = File.OpenRead(path);
int b0 = fs.ReadByte(), b1 = fs.ReadByte();
bool isPe = b0 == 0x4D && b1 == 0x5A; // 'MZ'
fs.Position = 0;
if (!isPe) throw new InvalidOperationException($"{path} is not a PE file");

Type guard

static bool IsPeFile(byte[] bytes) => bytes.Length >= 2 && bytes[0] == 0x4D && bytes[1] == 0x5A;

Try / catch

try { var pe = new PE(stream); }
catch (InvalidDataException ex) when (ex.Message == "ERROR: Invalid PE file") { /* report wrong binary path */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of Perfare/Il2CppDumper@4741d46ba9 (2026-09-11). Data as JSON: /api/errors/43d8e9da856cd919. Report an issue: GitHub.

Appendix: source

Thrown at Il2CppDumper/ExecutableFormats/PE.cs:17

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Il2CppDumper
{
    public sealed class PE : Il2Cpp
    {
        private readonly SectionHeader[] sections;

        public PE(Stream stream) : base(stream)
        {
            var dosHeader = ReadClass<DosHeader>();
            if (dosHeader.Magic != 0x5A4D)
            {
                throw new InvalidDataException("ERROR: Invalid PE file");
            }
            Position = dosHeader.Lfanew;
            if (ReadUInt32() != 0x4550u) //Signature
            {
                throw new InvalidDataException("ERROR: Invalid PE file");
            }
            var fileHeader = ReadClass<FileHeader>();
            var pos = Position;
            var magic = ReadUInt16();
            Position -= 2;
            if (magic == 0x10b)
            {
                Is32Bit = true;
                var optionalHeader = ReadClass<OptionalHeader>();
                ImageBase = optionalHeader.ImageBase;
            }
            else if (magic == 0x20b)
            {

View on GitHub (pinned to 4741d46ba9)