A really lightweight, optimistic, and naive C++ (header-only) parser for the Executable and Linking Format, supporting common GNU/Linux extensions.
This library was written for a small dynamic linker & loader, hence it directly accesses the memory mapped file without requiring dynamic memory allocation. However, it is still designed with academic purposes in mind and not optimized for best performance.
Unless you are happy with those limitations, you should better take look at more mature projects like ELFIO.
The src
directory contains a few example programs, which can be built using
make
(a current C++ compiler and Python 3 with PyParsing are required for the build process)
Displays ELF file information, similar to GNU Binutils readelf -a -W
.
./elfo-dump test/h2g2
h2g2
is a prebuilt test binary (see h2g2,cpp), the output should be identical to dump.stdout.
Displays ELF header and all information accessible via DYNAMIC section.
./elfo-dynamic-dump test/h2g2
The output should be identical to dynamic-dump.stdout.
Dump the contents of the virtual dynamic shared object (residing in memory) into a local file:
./elfo-vdso-dump /tmp/vdso
will dump the contents into /tmp/vdso
-- this should create a valid ELF file, which can be inspected by elfo-dump
.
Find a symbol in the dynamic section of an ELF file (using hash, if possible).
./elfo-lookup test/h2g2
The output should be identical to lookup.stdout.
Change the interpreter string (to a path with less or equal length):
g++ -o foo test/h2g2
./elfo-setinterp foo /opt/luci/ld-luci.so
will change the default interpreter /lib64/ld-linux-x86-64.so.2
(on Debian) to /opt/luci/ld-luci.so
Elfo is part of the Luci-project, which is being developed by Bernhard Heinloth of the Department of Computer Science 4 at Friedrich-Alexander-Universität Erlangen-Nürnberg and is available under the GNU Affero General Public License, Version 3 (AGPL v3).