3. The PE Format: Reading a Windows Executable Like an Analyst
DOS stub to overlay: the headers, sections, imports, exports, resources, signatures and TLS callbacks of a Windows program, and what each one gives away about a suspicious file
Think about a flat-pack wardrobe. In the shop it's a heavy, compact box: every panel stacked tight against the next, no wasted space. Taped to the top is a sheet of paper that the whole job depends on. It lists every panel, where each one sits in the box, and where it goes in the finished wardrobe. It says how much floor space to clear. It lists the screws and hinges not included, which you'll have to fetch from the hardware store. And it says which step to start with.
A Windows executable is that box, and the Portable Executable (PE) headers are the sheet of paper. On disk, the program's code and data are packed tightly. When you run it, the Windows loader reads the headers, clears a larger space in memory, lays every piece out at its proper position with gaps between them, fetches the functions the program needs from system DLLs, and starts at the step the headers name. The loader does exactly what the sheet says, which is why analysts read the sheet first.
In static triage we glanced at a few of these structures: the MZ and
PE\0\0 magic, section names and sizes, and a handful of suspicious imports. This article is
the deep dive. We'll walk the format from the first byte to the last, read a complete header
by hand, convert between the three kinds of address the format uses, and at every stop ask
the analyst's question: what does this tell me about the file, and could it be lying? Linux
programs use a different format, ELF, which gets its own article next.
Everything here is synthetic
Every header byte on this page was generated for this article: a do-nothing console
program that was never compiled from any source. The interactive tools build their
samples in your browser in the same way, and a file you load into them is parsed locally
and never uploaded. As always in this series, open real samples only inside your
lab, renamed to something unclickable like
sample.bin.
Why the Headers Matter
Here's the idea that makes PE analysis worth learning: the headers fall into two kinds of field.
- Fields the loader depends on. Where the code starts, where each section goes in memory, which DLL functions to fetch. If these are wrong, the program doesn't run. So in a sample that runs, these fields are telling the truth, even if the author would rather they didn't.
- Fields only humans and tools read. The compile timestamp, the build-tool fingerprint, the version information that says "Microsoft Corporation", the section names. The loader ignores them, so an author can write anything there. They're claims, and sometimes the most interesting thing about a claim is that it's false.
Keep asking which kind of field you're looking at, and the PE format stops being a wall of hex and becomes a set of questions with answers.
PE isn't just .exe files. DLLs (.dll), drivers (.sys), control-panel applets (.cpl),
screensavers (.scr), ActiveX controls (.ocx) and UEFI applications (.efi) are all PE
files, and all of them turn up as malware. The format is documented by Microsoft in the
PE Format specification,
and the structure names below (IMAGE_DOS_HEADER, IMAGE_FILE_HEADER and so on) come
from it and from the Windows SDK header winnt.h.
The Map: From MZ to the Last Section
A PE file is a chain of headers followed by the sections that hold the actual code and data. Each header either has a fixed size or says how big the next thing is, so a parser can walk from the first byte to the end without guessing. Here's the layout of the synthetic program we'll take apart, with its real offsets:
The order is always the same: a DOS header at offset 0, a pointer from it to the PE
signature, a small fixed COFF file header, a bigger optional header (which, despite
the name, every executable has), a section table describing each section, and then the
sections' raw bytes. Everything up to the end of the section table is the headers; the
optional header records their padded size as SizeOfHeaders (here 0x400).
The DOS Header and Stub
The PE format dates from Windows NT 3.1 in 1993, and it was designed so that an NT program
copied to an MS-DOS machine would fail politely instead of crashing. So every PE file begins
with a complete, tiny DOS program: a 64-byte IMAGE_DOS_HEADER starting with MZ, followed
by a DOS stub
that prints "This program cannot be run in DOS mode." and exits.
Windows only cares about two fields of the DOS header:
e_magicat offset0x00: must be4D 5A(MZ).e_lfanewat offset0x3C: a 4-byte little-endian file offset of the PE signature.
Everything else in the DOS header, and the whole stub, is ignored by the Windows loader.
That makes the region between 0x40 and e_lfanew the first place where an author has
free rein. Normally it holds the standard stub, which the Microsoft linker writes
identically into every program. Things worth noticing:
- A non-standard stub or message. Other toolchains sometimes write their own stub, which is a toolchain hint. A stub that's been replaced with something that isn't DOS code at all is odder.
- Unusual
e_lfanewvalues. In MSVC-built files the PE header follows the Rich header within the first few hundred bytes. A PE header far into the file, or one that overlaps the DOS header (possible in hand-crafted "tiny PE" files), is a sign the file was built or edited by hand. - Data hidden in the gap. Since nothing reads it, the stub area is a small hiding spot for a marker or a few bytes of configuration.
The Rich Header: A Fingerprint of the Build
Between the DOS stub and the PE signature, programs linked with Microsoft's linker carry an
extra block that Microsoft has never documented. It's called the Rich header, after the
ASCII word Rich that marks its end, and it's a record of the tools that built the program:
for every compiler, assembler, linker and library object that went into the link, a product
ID, a build number, and a count of how many objects it contributed.
It's lightly disguised. The block starts with the word DanS and ends with Rich followed
by a 4-byte key; everything between, including DanS itself, is XORed with that key. The
key isn't random: it's a checksum computed over the DOS header and stub and the tool entries.
In our synthetic file the key is 0xEA24900B, and the first four bytes at 0x80 are
4F F1 4A B9. XOR them with the key (as the little-endian value 0xB94AF14F):
0xB94AF14F (stored)
^ 0xEA24900B (key, stored right after "Rich")
= 0x536E6144 = bytes 44 61 6E 53 = "DanS"
Decoded, our synthetic file's entries look like this (the product IDs and build number are made up for this page, so a real lookup table won't recognise them):
Product ID Build Count
0x0105 31433 12 (e.g. C++ compiler objects)
0x0104 31433 3 (e.g. C compiler objects)
0x0102 31433 1 (e.g. the linker itself)
Tools like PE-bear, PEStudio and Detect It Easy decode the Rich header and translate the product IDs into names like "Visual Studio 2022 linker" using community-maintained tables.
Why analysts care
The Rich header is a fingerprint of the build environment, not of the code. Two samples compiled on the same developer's machine, with the same Visual Studio version and the same project, tend to have identical or near-identical Rich headers even when everything else differs. Researchers hash the decoded entries and use the result to cluster samples, a bit like the imphash from triage.
Why you can't trust it
The loader never reads the Rich header, so an author can delete it, zero it, or copy one from somebody else's binary. The best-known case is Olympic Destroyer, the wiper that disrupted the opening of the 2018 Winter Olympics. Its Rich header matched samples from the Lazarus group, and early analysis leaned that way. Kaspersky's researchers (in a write-up titled The devil's in the Rich header) showed that the header listed tools that couldn't have produced the actual code in the file: it had been copied over as a false flag. The lesson generalises: when a field the loader ignores contradicts the parts the loader uses, believe the parts the loader uses.
A few practical checks: no Rich header at all on a file that Detect It Easy says was built with Visual C++ (it was stripped); a Rich header on a file built by a non-Microsoft toolchain like Go, Delphi or MinGW (it was added); or a key that doesn't match the recomputed checksum (the header or the bytes before it were edited afterwards).
The PE Signature and COFF File Header
At e_lfanew comes the 4-byte signature 50 45 00 00 (PE\0\0), immediately followed by
the 20-byte COFF file header (IMAGE_FILE_HEADER). It's short, and every field is worth
reading:
| Offset | Field | Size | Our sample | Meaning |
|---|---|---|---|---|
| +0 | Machine |
2 | 0x8664 |
Target CPU |
| +2 | NumberOfSections |
2 | 4 |
Entries in the section table |
| +4 | TimeDateStamp |
4 | 0x66F2B3C0 |
Link time (seconds since 1970) |
| +8 | PointerToSymbolTable |
4 | 0 |
COFF symbols; 0 in images |
| +12 | NumberOfSymbols |
4 | 0 |
Likewise |
| +16 | SizeOfOptionalHeader |
2 | 0xF0 |
240 bytes: a PE32+ header |
| +18 | Characteristics |
2 | 0x0022 |
File flags |
Machine names the CPU: 0x014C for 32-bit x86, 0x8664 for x86-64, 0xAA64 for
ARM64. A 32-bit sample can run on 64-bit Windows (under the WOW64 layer), so lots of malware
is still 32-bit; that matters later, because a 32-bit sample needs a 32-bit debugger.
Characteristics is a set of bit flags. The ones you'll actually meet:
| Flag | Value | Meaning |
|---|---|---|
RELOCS_STRIPPED |
0x0001 |
No relocation info: must load at its preferred address |
EXECUTABLE_IMAGE |
0x0002 |
A runnable image (set on both EXEs and DLLs) |
LARGE_ADDRESS_AWARE |
0x0020 |
Can handle addresses above 2 GB |
32BIT_MACHINE |
0x0100 |
32-bit word machine |
DLL |
0x2000 |
This is a DLL, not an EXE |
Our 0x0022 is EXECUTABLE_IMAGE | LARGE_ADDRESS_AWARE, a normal 64-bit EXE. The DLL bit
is the one that matters most: it decides whether the file is a program or a library,
whatever its extension says. A file named invoice.pdf with 0x2000 set is a DLL meant to
be loaded by something else, often by rundll32.exe or by a legitimate program that's been
tricked into loading it.
The timestamp, and why it lies
TimeDateStamp is supposed to record when the linker produced the file, as a count of
seconds since 1 January 1970 UTC. Our 0x66F2B3C0 decodes to 2024-09-24 12:42:40 UTC.
When it's genuine, it's gold: it dates a campaign, and a cluster of samples whose
timestamps all fall in the working hours of one time zone says something about who built
them. That's exactly why it can't be taken at face value:
- Faked. It's four bytes the loader barely looks at. Authors zero it, set it to a date years in the past, or to a date in the future.
- Fixed by the toolchain. Delphi versions from roughly Delphi 4 through Delphi 2006
write the same value into every program:
0x2A425E19, which is 1992-06-19 22:22:17. Seeing that date means "old Delphi", not "1992". - Replaced by a hash. For
reproducible builds,
Microsoft's linker option
/Brepro(and LLVM'slld-link) write a hash of the output into the field instead of the time. Since Windows 10, Microsoft's own system files are built this way, so their "timestamps" decode to random-looking dates, some of them in the future.
So: a future date, zero, or the Delphi constant isn't proof of anything by itself. The useful check is consistency. The PE has other timestamps: the debug directory has its own, the export directory has one, and Delphi programs often record a real time in the resource directory. An author who fakes one and forgets the others has left you a clue.
The Optional Header
The optional header is where the loader gets most of its instructions. It comes in two
flavours, identified by its first two bytes, the Magic field:
| PE32 | PE32+ | |
|---|---|---|
Magic |
0x10B |
0x20B |
| Used for | 32-bit programs | 64-bit programs |
ImageBase |
4 bytes | 8 bytes |
BaseOfData field |
present | absent |
| Stack and heap size fields | 4 bytes each | 8 bytes each |
| Usual size with 16 data directories | 224 bytes (0xE0) |
240 bytes (0xF0) |
The fields that matter to an analyst, using our sample's values:
Optional header fields worth knowing
AddressOfEntryPoint=0x14A0. Where execution starts, as an RVA. For a C or C++ program this is the compiler's startup code, which then callsmainorWinMain. For a DLL it'sDllMain's startup wrapper, and it may be zero if the DLL has none.ImageBase=0x140000000. The preferred address to load the image at. The linker defaults are0x400000for 32-bit EXEs,0x10000000for 32-bit DLLs,0x140000000for 64-bit EXEs and0x180000000for 64-bit DLLs. With ASLR on, Windows usually loads somewhere else and patches the code using the relocation table.SectionAlignment=0x1000andFileAlignment=0x200. Sections start on multiples of these in memory and in the file, respectively.0x1000is the 4 KB page size;0x200(512) is the traditional disk sector size and the linker's default.SizeOfImage=0x6000. How much memory to reserve for the whole loaded image, a multiple ofSectionAlignment. Our file is0x2600bytes on disk but needs0x6000in memory.SizeOfHeaders=0x400. The headers' size, rounded up toFileAlignment.CheckSum=0. Only checked for drivers and a few critical system DLLs; zero is normal for ordinary programs.Subsystem=3. Which environment the program needs:2is a Windows GUI program (no console window),3a console program,1"native" (drivers and a few boot-time programs),10a UEFI application.DllCharacteristics=0x8160. Security feature flags, below.NumberOfRvaAndSizes=16. How many data directories follow. It's always 16 in practice; anything else is worth a second look.
Subsystem 2 deserves a moment. A GUI program that never creates a window runs with no visible sign at all, which is why so much malware is marked GUI. So are thousands of perfectly ordinary programs, so it's context, not a verdict.
DllCharacteristics: the security flags
These bits tell Windows which exploit mitigations the program supports. They're mostly about how robust the program is against attack, but a missing flag is also a hint about how, and how recently, the file was built: modern Visual Studio turns the first three below on by default.
| Flag | Value | What it enables |
|---|---|---|
HIGH_ENTROPY_VA |
0x0020 |
64-bit ASLR with a much wider range of base addresses |
DYNAMIC_BASE |
0x0040 |
ASLR: the image can be loaded at a random base address |
NX_COMPAT |
0x0100 |
DEP: data pages aren't executable |
NO_SEH |
0x0400 |
The image uses no structured exception handlers |
APPCONTAINER |
0x1000 |
Must run inside an AppContainer sandbox |
GUARD_CF |
0x4000 |
Control Flow Guard: indirect calls are checked |
TERMINAL_SERVER_AWARE |
0x8000 |
Behaves correctly on Remote Desktop servers |
Our 0x8160 is TERMINAL_SERVER_AWARE | NX_COMPAT | DYNAMIC_BASE | HIGH_ENTROPY_VA, which
is what Visual Studio produces for a 64-bit program out of the box. Control Flow Guard isn't
set because it's opt-in (/guard:cf). An image without DYNAMIC_BASE and NX_COMPAT was
built with old tools, a non-Microsoft toolchain, or a deliberately unusual configuration, and
many packers clear DYNAMIC_BASE so their stub can rely on a fixed address. (64-bit
processes always get DEP, whatever the flag says; the flag matters for 32-bit ones.)
The data directories
The optional header ends with 16 data directories, each an 8-byte pair of RVA and size, pointing at the structures the loader needs. Index matters: entry 1 is always the import table, entry 9 always TLS, and so on. A zero pair means "not present".
| # | Directory | Points at |
|---|---|---|
| 0 | Export | Functions this file offers to others |
| 1 | Import | DLLs and functions this file needs |
| 2 | Resource | Icons, version info, manifests, embedded files |
| 3 | Exception | Unwind data for 64-bit exception handling (.pdata) |
| 4 | Certificate (Security) | Authenticode signature. A file offset, not an RVA |
| 5 | Base relocation | Fix-ups for loading at a different address (.reloc) |
| 6 | Debug | Debug info, including the PDB path from triage |
| 9 | TLS | Thread-local storage, including TLS callbacks |
| 10 | Load config | Security cookie, Control Flow Guard tables and more |
| 12 | IAT | The import address table |
| 13 | Delay import | Imports loaded on first use |
| 14 | CLR runtime header | Present only in .NET assemblies |
(Entries 7, 8, 11 and 15 are reserved or obsolete; 11 is the rarely used "bound import" table.) Simply scanning which directories are non-zero is a quick structural summary: our sample has Import, Resource and IAT. A file with no Import directory at all, or a TLS directory in a tiny program, or a CLR header, each changes what you do next.
Walkthrough: Reading a Header by Hand
Tools will parse all of this for you, but reading one header by hand, once, is what makes
the tools' output make sense. Here's the first 0x270 bytes of our synthetic program, in
the classic hex-dump layout: offset, sixteen bytes, and the same bytes as ASCII. Multi-byte
values are little-endian, so C0 00 00 00 is the number 0x000000C0.
00000000 4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00 MZ..............
00000010 B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ........@.......
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000030 00 00 00 00 00 00 00 00 00 00 00 00 C0 00 00 00 ................
00000040 0E 1F BA 0E 00 B4 09 CD 21 B8 01 4C CD 21 54 68 ........!..L.!Th
00000050 69 73 20 70 72 6F 67 72 61 6D 20 63 61 6E 6E 6F is program canno
00000060 74 20 62 65 20 72 75 6E 20 69 6E 20 44 4F 53 20 t be run in DOS
00000070 6D 6F 64 65 2E 0D 0D 0A 24 00 00 00 00 00 00 00 mode....$.......
00000080 4F F1 4A B9 0B 90 24 EA 0B 90 24 EA 0B 90 24 EA O.J...$...$...$.
00000090 C2 EA 21 EB 07 90 24 EA C2 EA 20 EB 08 90 24 EA ..!...$... ...$.
000000A0 C2 EA 26 EB 0A 90 24 EA 52 69 63 68 0B 90 24 EA ..&...$.Rich..$.
000000B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000000C0 50 45 00 00 64 86 04 00 C0 B3 F2 66 00 00 00 00 PE..d......f....
000000D0 00 00 00 00 F0 00 22 00 0B 02 0E 24 00 12 00 00 ......"....$....
000000E0 00 10 00 00 00 00 00 00 A0 14 00 00 00 10 00 00 ................
000000F0 00 00 00 40 01 00 00 00 00 10 00 00 00 02 00 00 ...@............
00000100 06 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 ................
00000110 00 60 00 00 00 04 00 00 00 00 00 00 03 00 60 81 .`............`.
00000120 00 00 10 00 00 00 00 00 00 10 00 00 00 00 00 00 ................
00000130 00 00 10 00 00 00 00 00 00 10 00 00 00 00 00 00 ................
00000140 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 ................
00000150 60 32 00 00 28 00 00 00 00 50 00 00 E0 01 00 00 `2..(....P......
00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
... 0x170 to 0x19F: directories 5 to 10, all zero ...
000001A0 00 00 00 00 00 00 00 00 00 30 00 00 48 00 00 00 .........0..H...
000001B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000001C0 00 00 00 00 00 00 00 00 2E 74 65 78 74 00 00 00 .........text...
000001D0 C8 11 00 00 00 10 00 00 00 12 00 00 00 04 00 00 ................
000001E0 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 60 ............ ..`
000001F0 2E 72 64 61 74 61 00 00 3A 0B 00 00 00 30 00 00 .rdata..:....0..
00000200 00 0C 00 00 00 16 00 00 00 00 00 00 00 00 00 00 ................
00000210 00 00 00 00 40 00 00 40 2E 64 61 74 61 00 00 00 ....@[email protected]...
00000220 48 06 00 00 00 40 00 00 00 02 00 00 00 22 00 00 H....@......."..
00000230 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 C0 ............@...
00000240 2E 72 73 72 63 00 00 00 E0 01 00 00 00 50 00 00 .rsrc........P..
00000250 00 02 00 00 00 24 00 00 00 00 00 00 00 00 00 00 .....$..........
00000260 00 00 00 00 40 00 00 40 00 00 00 00 00 00 00 00 ....@..@........
Walk it in order, exactly as the loader does:
-
0x00: the magic
4D 5AisMZ. The rest of the first line is the DOS header's legacy fields, filled with the standard values every MSVC binary has. -
0x3C: follow the pointer
C0 00 00 00ise_lfanew = 0xC0. Jump there. On the way, note the DOS stub at0x40(machine code, then the message ending in$, which is how DOS marks the end of a string to print) and the Rich header at0x80: three repeated groups0B 90 24 EA(the key, XORed with zeros) andRichat0xA8followed by the key again. -
0xC0: signature and COFF header
50 45 00 00isPE\0\0. Then64 86: Machine0x8664, x86-64.04 00: four sections.C0 B3 F2 66: the timestamp,0x66F2B3C0. Two zero dwords for the symbol table.F0 00: a 240-byte optional header.22 00: Characteristics0x0022. -
0xD8: optional header
0B 02: Magic0x20B, so PE32+ and 8-byte fields ahead. Linker version 14.36 (0E 24). At+16(file offset0xE8),A0 14 00 00: the entry point RVA0x14A0. At+24(0xF0), eight bytes00 00 00 40 01 00 00 00: ImageBase0x140000000. Then the alignments0x1000and0x200, OS and subsystem versions 6.0, SizeOfImage0x6000at0x110, SizeOfHeaders0x400, a zero checksum, and at0x11CSubsystem03 00and DllCharacteristics60 81(0x8160). -
0x148: data directories
NumberOfRvaAndSizesis 16 (at0x144), and the 16 pairs start at0x148. Export (0x148) is zero. Import (0x150): RVA0x3260, size0x28, room for one 20-byte descriptor plus the all-zero terminator, so this program imports from exactly one DLL. Resource (0x158): RVA0x5000, size0x1E0. IAT, entry 12 (0x1A8): RVA0x3000, size0x48, nine 8-byte slots: eight imported functions and a terminating zero. -
0x1C8: the section table
Four 40-byte entries, each starting with an 8-byte name. Read
.text: VirtualSize0x11C8, VirtualAddress0x1000, SizeOfRawData0x1200, PointerToRawData0x400, and at the end of the entry Characteristics0x60000020: code, readable, executable. The other three follow the same pattern. The headers end at0x268, and zeros pad them out to0x400, where.text's bytes begin.
That's the whole skeleton. Notice what we now know without having seen a single instruction: a 64-bit console EXE, four ordinary sections, one imported DLL with eight functions, a version-info-sized resource section, modern security flags, no signature, no TLS, no exports, and a build fingerprint. Every later section of this article fills in one of those facts in more detail.
Three Kinds of Address: File Offset, RVA and VA
This is the part of the PE format that trips everyone up at first, so it's worth going slowly. The same byte of a program has three different addresses, depending on where you're standing:
- A file offset is a position in the file on disk. A hex editor shows file offsets.
- An RVA (relative virtual address) is a position in the loaded image, counted from wherever the image starts in memory. Almost every pointer inside the PE headers is an RVA, because the headers are written before anyone knows where the image will be loaded.
- A VA (virtual address) is the actual address in the running process: ImageBase plus RVA. Disassemblers and debuggers show VAs.
If the file were copied into memory byte for byte, file offsets and RVAs would be the same.
They aren't, because of the two alignments. On disk, sections are packed at multiples of
FileAlignment (0x200) to save space. In memory, each section starts on its own 4 KB page
(SectionAlignment, 0x1000), because memory permissions (read, write, execute) are set per
page and each section needs its own. So the loader spreads the sections out, like
unpacking flat-pack panels across a room:
Every RVA belongs to one section, and within a section, file and memory keep the same order. So converting is a matter of finding the section and swapping one starting point for the other:
Write for the section's VirtualAddress (its start in memory, as an RVA) and for
its PointerToRawData (its start in the file). Then:
Name VirtualAddress VirtualSize PointerToRawData SizeOfRawData
.text 0x1000 0x11C8 0x0400 0x1200
.rdata 0x3000 0x0B3A 0x1600 0x0C00
.data 0x4000 0x0648 0x2200 0x0200
.rsrc 0x5000 0x01E0 0x2400 0x0200
Worked example: where are the import descriptors?
The Import data directory says RVA 0x3260. You want to look at those bytes
in a hex editor, so you need the file offset.
- Find the section.
.rdatacovers RVAs0x3000up to0x3000 + 0xB3A = 0x3B3A.0x3260is inside it. - Offset within the section:
0x3260 − 0x3000 = 0x260. - Check that it's backed by file bytes:
0x260is less than SizeOfRawData0xC00, so yes. - Add the section's file start:
0x1600 + 0x260 = 0x1860. That's the file offset. - VA, for the debugger:
0x140000000 + 0x3260 = 0x140003260(if the image loaded at its preferred base; with ASLR, use the actual base instead).
The entry point works the same way: RVA 0x14A0 is in .text, so its file offset is
0x14A0 − 0x1000 + 0x400 = 0x8A0 and its preferred VA is 0x1400014A0. Going backwards is
symmetrical: file offset 0x1728 lies in .rdata's file range (0x1600 to 0x2200), so
its RVA is 0x1728 − 0x1600 + 0x3000 = 0x3128.
Two edge cases come up constantly:
- RVAs with no file bytes. Take RVA
0x4400. It's in.data(0x4000to0x4648), at offset0x400into the section, but.dataonly has0x200bytes in the file. So0x4400has no file offset: the loader fills it with zeros. This is where a C program's uninitialised global variables live. It's also exactly how the UPX section from triage works, at a much larger scale: a raw size of zero, a big virtual size, and the unpacking stub fills it in at run time. - RVAs in the headers. RVAs below
SizeOfHeaders(0x400) point into the headers, which are mapped at the start of the image unchanged, so the file offset equals the RVA.
RVA Calculator
Pick a preset section table (or use the one from a file loaded into the PE Header Explorer below), type an address in any of the three forms, and step through the conversion. The diagram shows where the address falls in the file and in memory.
Leave ImageBase empty to use the section table's own; type another base to see where an ASLR-relocated image puts the same RVA. Or start from an example:
Click either bar to convert the address under the pointer.
Section table in use
The Section Table
Each 40-byte section table entry (IMAGE_SECTION_HEADER) describes one section:
| Field | Size | Meaning |
|---|---|---|
Name |
8 | ASCII name, zero-padded, not necessarily zero-terminated |
VirtualSize |
4 | Size in memory |
VirtualAddress |
4 | RVA where it starts in memory |
SizeOfRawData |
4 | Size in the file (a multiple of FileAlignment) |
PointerToRawData |
4 | File offset where it starts |
| (relocation and line-number fields) | 12 | Zero in executables |
Characteristics |
4 | Content type and memory permissions |
The characteristics combine a content type with permission bits. The ones that matter:
| Flag | Value | Meaning |
|---|---|---|
CNT_CODE |
0x00000020 |
Contains code |
CNT_INITIALIZED_DATA |
0x00000040 |
Contains initialised data |
CNT_UNINITIALIZED_DATA |
0x00000080 |
Contains only zeros (no file bytes) |
MEM_EXECUTE |
0x20000000 |
Executable |
MEM_READ |
0x40000000 |
Readable |
MEM_WRITE |
0x80000000 |
Writable |
So .text's 0x60000020 is code, readable, executable; .rdata's 0x40000040 is
initialised data, read-only; .data's 0xC0000040 is initialised data, readable and
writable. Section names are pure convention: the loader never looks at them. MSVC
produces .text, .rdata, .data, .pdata (64-bit exception data), .rsrc and .reloc;
other toolchains add their own (.bss, .idata, .tls, .CRT, Delphi's CODE and
DATA, Go's .symtab).
What's suspicious in a section table
Because names are a claim and the permission bits and sizes are fact (the loader uses them), section tables are one of the richest places to look for trouble:
Normal build
Name VSize RawSize Flags Perms
.text 0x11C8 0x1200 0x60000020 R-X
.rdata 0x0B3A 0x0C00 0x40000040 R--
.data 0x0648 0x0200 0xC0000040 RW-
.rsrc 0x01E0 0x0200 0x40000040 R--
Entry point 0x14A0: in .text
UPX-like packed build
Name VSize RawSize Flags Perms
UPX0 0x30000 0x0000 0xE0000080 RWX
UPX1 0x12000 0x11E00 0xE0000040 RWX
.rsrc 0x01000 0x00C00 0xC0000040 RW-
Entry point 0x41E20: in UPX1,
the last code-bearing section
-
Writable and executable (RWX)
A section that's both writable and executable can be filled with code at run time and then run. Normal compilers never produce one. Packers do, because their stub decompresses code into memory and jumps into it. Self-modifying code, shellcode loaders and some protectors produce them too.
-
Entry point outside the first code section
A compiled program starts in its code section, usually
.text. An entry point in the last section, in a data section, or in a section without the execute flag, suggests something was bolted on after compilation: a packer's stub, or code injected by a file infector. An entry point that falls in no section at all (inside the headers) is a hand-crafted file. -
VirtualSize much larger than SizeOfRawData
Some difference is normal (
.dataabove). A section with a raw size of zero and a virtual size of hundreds of kilobytes, flagged executable, is an empty room being reserved for code that doesn't exist yet. That's the unpacking target. -
Odd names
Packer names (
UPX0,.aspack,.MPRESS1,.themida), empty names, random strings, or a familiar name in the wrong place (two.textsections, or a.rsrcthat's executable). -
Sizes that don't add up
Sections that overlap in the file or in memory, raw data that runs past the end of the file, a
SizeOfImagethat doesn't match the last section's end. Some of these crash analysis tools while Windows loads the file happily, which is sometimes the point.
Pair each section with its entropy (from triage) and the picture sharpens: an RWX section with a raw size near its virtual size and entropy near 8 is almost certainly a compressed or encrypted payload.
Imports: What the Program Asks Windows For
In triage we skimmed the import list for suspicious names. Here's how it's actually built, because the structure explains several tricks malware plays with it.
The Import data directory points at an array of import descriptors
(IMAGE_IMPORT_DESCRIPTOR, 20 bytes each), one per DLL, ending with an all-zero entry. Each
descriptor names a DLL and points at two parallel arrays:
- The INT (import name table, the descriptor's
OriginalFirstThunk): one entry per imported function, each pointing at a hint (a guess at the function's position in the DLL's export list, to speed up the search) and the function's name. - The IAT (import address table,
FirstThunk): on disk, a copy of the INT. When the program loads, the loader looks up each function and overwrites the IAT entry with the function's real address. The program's code calls through the IAT.
The diagram shows three of our sample's eight imported functions:
Ordinals
An INT entry doesn't have to name a function. If its top bit is set (0x80000000 in a
PE32, 0x8000000000000000 in a PE32+), the low 16 bits are an ordinal: the function's
number in the DLL's export table, with no name at all. Some Windows DLLs are commonly
imported this way (the Winsock DLL ws2_32.dll and oleaut32.dll, for instance), and tools
like PEStudio translate well-known ordinals back to names. But importing by ordinal also
hides intent from a quick string scan, so a sample that imports unusual functions by
ordinal deserves a second look.
Imports that never appear in the table
The import table only lists functions the program links against statically. Windows also lets a program load a DLL and look up a function at run time:
HMODULE h = LoadLibraryA("advapi32.dll");
FARPROC f = GetProcAddress(h, "RegSetValueExA");
Neither advapi32.dll nor RegSetValueExA appears in the import table, only
LoadLibraryA and GetProcAddress. Plenty of legitimate programs do this (plug-ins,
optional features), and delay-loaded imports (data directory 13) are the linker doing it
for you, with the names still visible in their own table. But an import table that is
almost empty apart from those two functions, as in a packed sample, means the real list is
being built at run time, out of your sight. The names may still be in the strings, or may be
encrypted.
The next step down is API hashing: the sample doesn't even call GetProcAddress. It
finds kernel32.dll already loaded in its own memory, walks that DLL's export table itself,
hashes every function name, and compares each hash against a list of constants. No function
names exist anywhere in the file, only numbers like 0x0726774C. (The ROR-13 hash
popularised by Metasploit-style shellcode is the classic example.) Recognising and reversing
these is a job for the obfuscation article later in the series; for now, a sample with no
imports and no readable API names is telling you it's hiding them.
imphash, revisited
Triage introduced imphash: the MD5 of the lowercase
dll.function list in import order. Now you can see why it works and where it breaks. It
captures the linker's output, so rebuilds of the same project usually keep it. It's
destroyed by packing (every UPX-packed file has a near-identical tiny import table), by
dynamic resolution, and by anything that reorders imports. Ordinal imports are included as
dll.ord123 by most implementations, and pefile maps a few well-known ordinals back to
names first, so different tools can disagree on the same file.
Imports as capability hints
The import table won't tell you what a program does, but grouped by family it tells you what it can do. No single function is suspicious; look for a family that's complete, and for families that don't fit the program's claimed purpose.
| Capability | Functions to look for | Also used legitimately by |
|---|---|---|
| Process injection | OpenProcess, VirtualAllocEx, WriteProcessMemory, CreateRemoteThread, NtCreateThreadEx, QueueUserAPC, SetThreadContext + ResumeThread, NtUnmapViewOfSection |
Debuggers, security software, game overlays |
| Persistence | RegCreateKeyExW + RegSetValueExW (with a Run key string), CreateServiceW, StartServiceW, CoCreateInstance (Task Scheduler is driven through COM) |
Installers, updaters |
| Networking | WSAStartup, socket, connect, send, recv; InternetOpenW, HttpSendRequestW; WinHttpOpen, WinHttpSendRequest; URLDownloadToFileW; DnsQuery_W |
Almost every modern program |
| Crypto | CryptAcquireContextW, CryptEncrypt, CryptGenRandom; BCryptEncrypt, BCryptGenRandom; CryptStringToBinaryA (Base64 decoding) |
Browsers, backup tools, anything using TLS |
| Anti-debugging | IsDebuggerPresent, CheckRemoteDebuggerPresent, NtQueryInformationProcess, OutputDebugStringA, GetTickCount / QueryPerformanceCounter in tight pairs |
Copy-protection, games, the C runtime itself |
| Surveillance | SetWindowsHookExW, GetAsyncKeyState, GetForegroundWindow, BitBlt + GetDC (screenshots), OpenClipboard |
Accessibility tools, remote support, screenshot apps |
| Discovery | CreateToolhelp32Snapshot, Process32FirstW/NextW, GetComputerNameW, GetUserNameW, NetShareEnum |
System utilities, inventory agents |
| Privilege | OpenProcessToken, LookupPrivilegeValueW, AdjustTokenPrivileges |
Installers, admin tools |
| Run-time loading | LoadLibraryA/W, GetProcAddress, LdrLoadDll, LdrGetProcedureAddress |
Plug-in hosts, the C runtime |
Read the families against the program's story. A "PDF viewer" with a complete injection set
and a keyboard hook is lying about something. A backup tool with CryptEncrypt and
FindFirstFileW is doing its job; a 40 KB unsigned file with the same pair and a ransom-note
string is not.
Exports: What a DLL Offers
A DLL's export table (data directory 0) lists the functions it offers to other modules.
EXEs rarely export anything; DLLs nearly always do. The IMAGE_EXPORT_DIRECTORY holds the
DLL's internal name, an ordinal Base, and three parallel arrays:
Three features of exports matter to an analyst:
- Forwarders. If a function's RVA points inside the export directory itself, it isn't
code but a string like
NTDLL.RtlGetVersion, and the loader transparently resolves the import from that other DLL instead. Windows uses this heavily:kernel32.dll'sHeapAlloc, for instance, forwards toNTDLL.RtlAllocateHeap. Malware uses it for DLL proxying: a maliciousversion.dlldropped next to a legitimate program forwards every real export to the genuine DLL inSystem32(sometimes by full path), so the program keeps working, while the malicious DLL's own startup code runs alongside it. A DLL whose exports are all forwarders to a same-named system DLL is a strong hint of exactly that. - Ordinal-only exports. An export with no name can only be called by number. Malware
DLLs sometimes export a single unnamed function and are launched with
rundll32.exe sample.dll,#1(the#means "ordinal"). In the lab, that's also how you call such an export to detonate the DLL. - Telling names. The export names describe what the DLL expects to be loaded by. A DLL
exporting
ServiceMainis built to run as a service insidesvchost.exe(registered through aServiceDllregistry value). One exportingDllRegisterServerandDllGetClassObjectis a COM server, which can be registered for persistence. One whose export names imitate a well-known DLL's, while its own code does something else, is probably meant to be side-loaded in place of it.
A DLL's own entry point, DllMain, isn't an export: it's AddressOfEntryPoint, and the
loader calls it automatically when the DLL loads, with the reason DLL_PROCESS_ATTACH.
That means just loading a DLL runs code, before any export is called. Remember it when a
"harmless" plug-in turns up in a strange directory.
The export directory also records the DLL's internal name. A file renamed to
msupdate.dll whose export directory still says loader_x64.dll has told you its
original name.
Resources: Icons, Version Info and Hidden Cargo
The resource section (.rsrc, data directory 2) holds data the program carries with it,
organised as a three-level tree: type, then name or ID, then language. Each leaf
points at a blob of bytes. Here's a resource tree of the kind you might see in a suspicious
file:
.rsrc
├── RT_ICON (3)
│ └── 1 ── 0x0409 (English, US) ── 9,640 bytes
├── RT_GROUP_ICON (14)
│ └── 1 ── 0x0409 ── 20 bytes
├── RT_VERSION (16)
│ └── 1 ── 0x0409 ── VS_VERSIONINFO, 812 bytes
├── RT_MANIFEST (24)
│ └── 1 ── 0x0409 ── XML, 381 bytes
└── RT_RCDATA (10)
└── "CFG" ── 0x0000 ── 48,152 bytes, entropy 7.98 <-- look here
What each part can tell you:
- Icons are pure decoration, which is exactly why they're abused: a PE carrying a PDF, Word or folder icon is trying to be double-clicked by someone who trusts icons. Analysts compare icon hashes to spot families that reuse the same fake icon.
- Version information (
RT_VERSION) holds the "Details" tab of a file's properties:CompanyName,FileDescription,ProductName,OriginalFilename, version numbers. It's free text, and malware routinely claims to be "Microsoft Corporation". Inconsistencies are the tell: a "Microsoft" file that's unsigned, anOriginalFilenamethat doesn't match the internal export name or the PDB path, or a copyright year after the timestamp's year. - Embedded payloads usually live in
RT_RCDATA(raw binary data), or in custom resource types. A large, high-entropy RCDATA blob in a small program is one of the most common shapes of a dropper: the program's job is to decrypt that blob and write or load it. Look for anMZat the start of any resource, and for imports likeFindResourceW,LoadResource,LockResourceandSizeofResource, which is how a program reads its own resources. - Language IDs record the locale the resources were compiled with.
0x0409is English (US); other values occasionally hint at a developer's locale. Like everything the loader ignores, they're trivial to fake, so treat them as weak evidence. - The manifest (
RT_MANIFEST) is an XML document that, among other things, can ask for administrator rights:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
asInvoker (run with the user's normal rights) is the usual value; requireAdministrator
triggers a UAC prompt at launch, and highestAvailable asks for admin only if the user is
an admin. A small "invoice viewer" that demands administrator rights deserves the same
suspicion you'd give a person who asks for your house keys to deliver a letter.
The Overlay: Data After the Last Section
The loader maps the headers and the sections, and nothing else. Any bytes in the file past the end of the last section's raw data are the overlay:
end of mapped data = max over all sections of (PointerToRawData + SizeOfRawData)
overlay = file bytes from there to the end of the file
In our sample, .rsrc ends at 0x2400 + 0x200 = 0x2600, which is the file size, so there's
no overlay. Append 100 KB to the file and Windows will run it exactly the same; the program
just has to open its own file and read the extra bytes itself.
That's a perfectly legitimate design, and it's how most installers work: NSIS and Inno
Setup installers, and self-extracting archives, are a small PE stub with the compressed
payload appended as an overlay. So "overlay present" is not suspicious on its own. What you
want to know is what's in it: an archive (look for PK or 7z magic), a second MZ, an
encrypted blob with entropy near 8, or a configuration block. Detect It Easy and PEStudio
both report overlays with their size, and Detect It Easy can show their entropy and
often recognise what format they're in.
One overlay is special. The Authenticode signature of a signed file is also stored past the last section, and is never mapped into memory. Unlike other overlay data, it's described in the headers: data directory 4 (the Certificate Table) gives its location as a plain file offset, the one directory entry that isn't an RVA. Good tools report "overlay" and "signature" separately; naive overlay calculations lump them together.
Authenticode: What a Signature Proves (and Doesn't)
A signed PE carries a
PKCS #7
signature over a hash of the file, plus the publisher's certificate chain. The hash covers
almost the whole file, deliberately skipping three things that must change when the
signature is added: the CheckSum field, the Certificate Table directory entry, and the
signature data itself. Windows verifies the signature with the WinVerifyTrust API, and the
"Digital Signatures" tab in a file's properties shows the result. The
digital signatures article in the Encryption series explains the
mathematics; here's what it means in practice.
A valid signature proves
- The file hasn't changed since it was signed (outside the excluded fields).
- Whoever signed it held the private key for a certificate that a trusted certificate authority issued to the named publisher.
- If it carries a trusted timestamp countersignature, that it was signed while the certificate was valid, even if the certificate has since expired.
It does not prove
- That the file is safe. Signing is about identity, not intent.
- That the named publisher wrote it. Signing keys get stolen: Stuxnet's drivers (2010) were signed with certificates stolen from two hardware companies, Realtek and JMicron.
- That the publisher is who you think. Certificates have been issued to shell companies set up for the purpose.
- That the signature is still trusted. Certificates are revoked after abuse; check the status, not just the presence.
Three practical traps:
- Present is not valid. A signature blob can be copied from a legitimate file and glued
onto a malicious one. The file then has a signature, and naive tools say "signed", but
verification fails because the hash doesn't match. Always check the verification result
(PEStudio,
sigcheckfrom Sysinternals, orGet-AuthenticodeSignaturein PowerShell). - Unsigned is not suspicious by itself. Many Windows system files carry no signature
inside the file at all: they're catalog-signed, with their hashes listed in a signed
.catfile elsewhere on the system. A file that claims to be a Windows component but is neither embedded- nor catalog-signed is the suspicious combination. - Data hidden inside the signature. By default, Windows doesn't strictly check the
padding inside the signature structure, so extra data can be tucked in there without
breaking verification. Microsoft documented this as CVE-2013-3900 and offers a stricter
check (the
EnableCertPaddingCheckregistry setting) that is opt-in. A signature directory noticeably larger than its certificates need is worth a look.
TLS Callbacks: Code Before the Entry Point
Thread-local storage (TLS) lets each thread have its own copy of a variable. To set
those copies up, the format lets a program register TLS callbacks: functions the loader
calls whenever a thread starts or ends, including the main thread, before the entry point
runs. The TLS data directory (entry 9) points at an IMAGE_TLS_DIRECTORY, whose
AddressOfCallBacks field holds a pointer (a VA, not an RVA) to a zero-terminated list of
callback addresses.
To see why that matters, here's roughly the order in which the loader prepares an EXE:
-
Map the image
Reserve
SizeOfImagebytes, copy the headers and each section into place, and set each section's memory permissions from its characteristics. -
Relocate, if needed
If the image didn't get its preferred
ImageBase(always the case with ASLR), patch every absolute address listed in the relocation table. -
Resolve imports
Load each DLL in the import table (running their own
DllMains) and fill the IAT. -
Run TLS callbacks
Call each function in the TLS callback list with
DLL_PROCESS_ATTACH. -
Jump to the entry point
ImageBase + AddressOfEntryPoint. Most debuggers place their first breakpoint here by default.
Step 4 runs before step 5. A debugger set to stop at the entry point stops after the TLS
callbacks have already run, so malware uses them to check for a debugger, decrypt code, or
start its real work before the analyst thinks anything has happened. The defences are
simple once you know: check whether the TLS directory is present and has callbacks (every
PE tool shows it), and configure your debugger to break on TLS callbacks (x64dbg has an
option for this in its event settings). Compilers do emit TLS directories for legitimate
reasons (C++ thread_local variables, Delphi programs, the Rust and MinGW runtimes), so
it's a flag to investigate, not a conviction.
.NET Assemblies: A PE Wrapped Around Something Else
A program written in C# or another .NET language is still a PE file, but its code isn't x86 machine code. It's CIL (Common Intermediate Language) bytecode, compiled to native code at run time by the .NET runtime. You can recognise one structurally:
- Data directory 14, the CLR runtime header (
IMAGE_COR20_HEADER), is non-zero. It points at the .NET metadata: tables describing every type, method and field, plus heaps of strings named#Strings,#US(user strings) and#Blob. - The import table is tiny: for .NET Framework assemblies, typically a single import,
mscoree.dll!_CorExeMain(or_CorDllMainfor a DLL). Don't mistake that for a packed sample's minimal imports.
The good news for analysts is that CIL keeps most of the program's structure, so .NET
assemblies decompile back to readable C# far better than native code disassembles.
dnSpy (the original project was archived in 2020; the community fork dnSpyEx
continues it) decompiles and can debug .NET assemblies, and ILSpy is a widely used,
actively maintained decompiler. For .NET, the interesting detail moves out of the PE headers and
into the metadata and the decompiled code. Expect
obfuscators (renamed symbols, encrypted strings) that later articles deal with. Note also
that modern .NET (since .NET Core 3.0) builds a small native launcher .exe with the real
assembly in a separate .dll by default, so check both files.
Putting It Together: A Structural Checklist
Here's everything above as a single pass you can make over any PE. None of these is a verdict; each one is a question with an innocent answer and a guilty one.
| Observation | Why it's interesting | Innocent explanations |
|---|---|---|
| A section that is writable and executable | Code written at run time, then run | Some protectors, JIT-heavy old programs |
| Entry point not in the first code section, or in the last section | A stub or injected code runs first | Unusual toolchains |
| VirtualSize far larger than SizeOfRawData, especially with raw size 0 | Space reserved for unpacked code | .bss-style data sections |
| Non-standard or packer section names | Packer or hand-built file | Less common compilers |
| Timestamp zero, in the future, or the Delphi constant | Faked, or reproducible build | /Brepro, Delphi |
| Rich header contradicting the toolchain, or present on non-MSVC code | Copied or forged | None very convincing |
No DYNAMIC_BASE / NX_COMPAT |
Old or unusual toolchain, packer | Legacy software |
Few imports, mostly LoadLibrary + GetProcAddress |
Imports resolved at run time | Plug-in loaders, .NET (mscoree.dll) |
| No imports and no readable API names | API hashing | Hand-written tiny programs |
| Overlay present | Appended payload or configuration | Installers, self-extracting archives, signatures |
| TLS callbacks | Code before the entry point | thread_local, Delphi, some runtimes |
Large high-entropy RT_RCDATA, or MZ inside a resource |
Embedded payload (dropper) | Compressed assets |
| Manifest requests administrator | Wants elevation at launch | Installers, admin tools |
| Version info claims a big publisher, but no valid signature | Impersonation | Very old or internal builds |
| DLL with all exports forwarded to a same-named system DLL | DLL proxying for side-loading | Compatibility shims |
The PE Header Explorer below puts the whole article into one tool. Start with the built-in synthetic samples: the "normal" one is the exact program dissected above, and the others each trip a different set of these flags.
PE Header Explorer
Choose a file from your computer or one of the built-in synthetic samples. Files are parsed entirely in your browser and are never uploaded anywhere. Nothing is executed. The built-in samples are header-only byte buffers generated on this page; none of them is real software or real malware. Click any field to highlight its bytes in the hex view.
Or drop a file anywhere on this panel.
Anomaly flags
Structure
The PE Toolkit
All of these are free, and FLARE-VM installs most of them. Each has a different strength:
- PEStudio (Marc Ochsenmeier, Winitor): the triage view. Everything in this article on one screen, with indicators ranked by severity, imports flagged against a list of suspicious functions, and the overlay, resources, signature and version info laid out.
- PE-bear (hasherezade): a fast, free, open-source viewer and editor that's very good at malformed files, shows the file and memory layouts side by side, decodes the Rich header, and makes comparing two samples easy.
- CFF Explorer (Daniel Pistelli, NTCore): an older but still popular structure editor, with a good .NET metadata viewer and a built-in hex editor.
- Detect It Easy (horsicq): compiler, linker, packer, protector and installer detection, overlay detection, and per-section entropy.
- pefile (Ero Carrera): the Python library underneath a great many analysis scripts and tools.
- LIEF (Quarkslab): a library for C++, Python and Rust that parses PE, ELF and Mach-O, and can also modify and rebuild them, which is handy for repairing a damaged sample's headers in the lab.
The site you're reading doesn't use Python, but you will, in REMnux or FLARE-VM. A few
lines of pefile cover most of this article (run them on samples only inside your lab):
import pefile
pe = pefile.PE("sample.bin")
fh, oh = pe.FILE_HEADER, pe.OPTIONAL_HEADER
print(hex(fh.Machine), fh.TimeDateStamp, hex(fh.Characteristics), pe.is_dll())
print(hex(oh.Magic), hex(oh.AddressOfEntryPoint), hex(oh.ImageBase), hex(oh.DllCharacteristics))
for s in pe.sections:
print(s.Name.rstrip(b"\0"), hex(s.VirtualAddress), hex(s.Misc_VirtualSize),
hex(s.SizeOfRawData), hex(s.Characteristics), round(s.get_entropy(), 2))
Imports, exports, overlay and address conversion:
for dll in getattr(pe, "DIRECTORY_ENTRY_IMPORT", []):
for imp in dll.imports:
print(dll.dll.decode(), imp.name.decode() if imp.name else f"ord {imp.ordinal}")
if hasattr(pe, "DIRECTORY_ENTRY_EXPORT"):
for exp in pe.DIRECTORY_ENTRY_EXPORT.symbols:
print(exp.ordinal, exp.name, exp.forwarder) # forwarder is None for real code
print(pe.get_overlay_data_start_offset()) # None if there's no overlay
print(hex(pe.get_offset_from_rva(0x3260))) # RVA -> file offset
print(hasattr(pe, "DIRECTORY_ENTRY_TLS")) # TLS directory present?
print(pe.get_imphash())
pe.dump_info() prints everything at once, which is a good way to see the whole structure
of an unfamiliar file. And for Linux-native tools, rabin2 -I, -S, -i and -E (from
radare2, met in triage) give the headers, sections, imports and exports of a PE as well.
What's Next
You can now read a Windows executable the way the loader does: follow e_lfanew to the PE
header, decode the COFF and optional headers, walk the data directories and section table,
convert between file offsets, RVAs and VAs, and take apart the import, export, resource and
TLS structures. More to the point, you know which of those fields the loader needs, and so
can trust, and which ones are only claims: timestamps, Rich headers, section names, version
information, icons. Most of the interesting findings in PE analysis come from catching those
two kinds of field disagreeing.
Linux malware is built from a different format, ELF, with its own headers, segments, sections, dynamic linking and tricks. The next article gives it the same treatment, and after that the series moves from reading the file's structure to reading its code.