Master the fundamental concepts of binary formats through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksThe Portable Executable (PE) format is used for .exe, .dll, and driver files on Windows. If you analyze cross-platform malware or compare Linux ELF with Windows binaries, you need to understand this layout.
A PE file layers several headers:
e_magic = 'MZ' (0x5A4D)'PE\0\0' at offset given by e_lfanewFor example, a 64-bit Windows executable has COFF Machine = 0x8664 and optional header Magic = 0x20B (PE32+).
You will parse DOS and PE headers, verify both magic values, and print machine type, entry point, and section information. Comparing PE with ELF helps you see that both formats solve the same problem (describing loadable code and data) with different field layouts.
Windows maps PE sections using VirtualAddress and SizeOfRawData, while ELF uses program headers for loading and section headers for linking. The PE optional header Subsystem field tells you whether the binary expects a console (3) or GUI (2). Cross-platform malware analysts encounter both formats, so recognizing MZ versus ELF magic immediately routes you to the correct parser.
Parse the headers of a Windows PE executable:
4D 5A ("MZ") at offset 0, and e_lfanew, a 32-bit little-endian offset of the PE header, at 0x3C.50 45 00 00 ("PE\0\0"), then the 20-byte COFF header: Machine (2 bytes), NumberOfSections (2), TimeDateStamp (4), 8 bytes you skip, SizeOfOptionalHeader (2), Characteristics (2).0x20B is PE32+ (64-bit) and 0x10B is PE32. AddressOfEntryPoint is at offset 16 and Subsystem at offset 68 in both. ImageBase is 8 bytes at offset 24 in PE32+ but 4 bytes at offset 28 in PE32.The entry point's virtual address is ImageBase + AddressOfEntryPoint. Machines: 0x8664 x86-64, 0x14C i386, 0xAA64 ARM64, others unknown. Subsystems: 2 GUI, 3 console, others other.
N (1 to 1024), then N bytes in hex.
=== PE Header Parser ===, then for a valid file:
cLoading…
The PE\0\0 line is printed literally with backslashes. Each check stops the program at the first failure, with one error line (after the lines already printed):
Error: input too short for DOS header (N bytes)Error: bad DOS magic (expected 4D 5A 'MZ', got XX XX)Error: PE signature at 0x... beyond input (N bytes)Error: bad PE signature at offset 0x40Error: unknown optional header magic 0x0107Error: optional header truncated