Skip to content
Buy me a coffee

PE files

tag: conceptstag: windowstag: beginners

A file extension is just part of the name. Anyone can rename invoice.pdf.exe to invoice.pdf. The real type is in the first few bytes, the magic bytes:

  • Every PE file starts with MZ (hex 4D 5A), the initials of Mark Zbikowski, who designed the original DOS format.
  • On a Mac or Linux, file FILE reads those bytes and tells you what the file really is. More on this in Magic numbers and Confirming a file type.
  1. DOS header: starts with MZ. At offset 0x3C it holds the location of the real PE header.
  2. DOS stub: a tiny program that prints “This program cannot be run in DOS mode.”
  3. PE signature: PE followed by two zero bytes.
  4. File header: the CPU it targets, the number of sections and a compile timestamp (which can be faked).
  5. Optional header: despite the name, always there. It holds the entry point (where execution starts) and whether it’s a console or a windowed program.
  6. Section table and sections: the actual contents.
Section What’s usually in it
.text The program’s code
.rdata Read-only data, often including the import table
.data Global variables
.rsrc Resources: icons, version info, and sometimes a hidden payload
.reloc Fix-ups used when Windows loads the file at a different address

Strange section names (such as UPX0 and UPX1), very high entropy and only a handful of imports usually mean the file is packed: compressed or encrypted so the real code appears only when it runs. See Vocabulary.

The import table lists the Windows functions the program asks for. They hint at what it can do:

Imports Suggests
VirtualAllocEx, WriteProcessMemory, CreateRemoteThread Injecting code into another process
URLDownloadToFileA, InternetOpenUrlA Downloading something
RegSetValueExA, CreateServiceA Staying on the machine after a reboot

These are hints, not proof. Plenty of legitimate software imports the same functions.

A .NET program is still a PE file, but its code is .NET bytecode rather than machine code. Open it in a .NET decompiler such as dnSpyEx or ILSpy instead of a disassembler.

You don’t need malware to learn this. Inside your lab VM, open a normal Windows file such as C:\Windows\System32\notepad.exe in one of these:

Then calculate its hash and compare.

That’s File Types 101. Back to the series overview.

One Reverse Look

"A little learning is a dangerous thing." ~ A. Pope

One Reverse Look · Made with ❤ · Your friendly knowledge seeker