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 worksAfter the ELF header comes the section header table, which describes all sections in the file. Sections are the building blocks for linking: .text holds code, .data holds initialized globals, .bss reserves space for zero-initialized data.
Each Elf64_Shdr entry contains:
sh_name: Offset into .shstrtab for the section namesh_type: Section type (PROGBITS, SYMTAB, STRTAB, NOBITS, etc.)sh_flags: Writable, allocatable, executablesh_offset: File offset to section datash_size: Size in bytesCommon flags you will encounter:
SHF_WRITE (0x1): Writable at runtimeSHF_ALLOC (0x2): Loaded into memorySHF_EXECINSTR (0x4): Contains executable instructionsFor example, .text typically has SHF_ALLOC | SHF_EXECINSTR, while .data has SHF_WRITE | SHF_ALLOC.
You will walk the section header table and list every section with its name, type, flags, offset, and size. This is exactly what readelf -S prints, and reverse engineers scan section flags first when triaging an unfamiliar binary.
The section count lives in e_shnum, and each entry is e_shentsize bytes wide. You iterate from e_shoff to e_shoff + e_shnum * e_shentsize, resolving each name through .shstrtab. Linkers merge sections with compatible flags during linking, and loaders map only sections with SHF_ALLOC set into the process address space at runtime.
List the sections of an ELF64 file the way readelf -S does. Take e_shnum and e_shstrndx from the file header. Then resolve each section's name: sh_name is an offset into the section-name string table (.shstrtab), and the name runs to the next NUL.
? when sh_name is past the end of the string table or e_shstrndx is not a valid index (>= e_shnum). Offset 0 is the empty name of the NULL section.NULL, 1 PROGBITS, 2 SYMTAB, 3 STRTAB, 8 NOBITS, anything else OTHER.W for 0x1, A for 0x2, X for 0x4, I for 0x40, or empty.A (SHF_ALLOC) flag.64, then the 64 header bytes in hex. The magic must be 7F 45 4C 46.sh_name sh_type sh_flags sh_addr sh_offset sh_size, every value in hex (with or without 0x).cLoading…
then one row per section with the C format "%3u %-17s %-9s %-6s 0x%08llX 0x%08llX %llu\n" (index, name, type, flags, address, offset, size in decimal), for example
cLoading…
and finally total section bytes: N and alloc bytes (SHF_ALLOC): N. The first two header values are decimal.