elf-parser
May 1, 2026 · View on GitHub
Identify and extract sections of an ELF file. For learning how Linux binaries are laid out.
What is an ELF file?
ELF (Executable and Linkable Format) is the format used by Linux executables, shared libraries, and object files.
Examples: /bin/ls, libc.so.6, a.out.
Layout:
+------------------------+
| ELF header | identifies the file
+------------------------+
| Program headers | how the kernel loads it
+------------------------+
| Sections (.text, ...) | code, data, symbols, strings
+------------------------+
| Section headers | describes each section
+------------------------+
Quickstart
Requires: gcc, make, Linux.
make
./elfparser /bin/ls
Prints ELF header, section headers, and symbols.
Writes .text to text.S.
Try it on
/bin/ls— executable/usr/lib/x86_64-linux-gnu/libc.so.6— shared librarygcc hello.c -o hello && ./elfparser hello*.a— refused (it's anararchive, not ELF)
Files
elf-parser-main.c— entry point (<100 lines)elf-parser.h— declarationself-parser.c— parsing logicdisasm.c— disassembler stub
Notes
-
Use
readelforobjdumpfor real work. -
Gap between ELF header and program header:
- header ends at
e_ehsize - program header starts at
e_phoff
- header ends at
-
*.sois ELF.*.ais anararchive, not ELF. -
Disassembler is a stub. Reads
.textinto memory but does not decode.
License
Creative Commons. See LICENSE.md.