Identify and extract sections of an ELF file. For learning how Linux binaries are laid out.
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
+------------------------+
Requires: gcc, make, Linux.
make
./elfparser /bin/lsPrints ELF header, section headers, and symbols.
Writes .text to text.S.
/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)
elf-parser-main.c— entry point (<100 lines)elf-parser.h— declarationself-parser.c— parsing logicdisasm.c— disassembler stub
-
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.
Creative Commons. See LICENSE.md.