Skip to content

davea42/readelfobj-code

Repository files navigation

README.md

Last update: May 9, 2026 Version now set to 2.3.1

The distribution consists entirely of C source files (along with GNU configure scripts to configure and build executables). Builds and works on Linux, MacOS, and Windows msys2 and on across all of those the programs can read all the object formats supported.

Requires a bash or sh shell, a C compiler, python3, m4, libtool, autoconf, and automake. On Debian and Ubuntu systems, these can quickly be installed with

apt-get install autoconf automake libtool m4 gcc python3

If unsure what object format a file might be, the object_detector will tell you. (On linux and MacOs the 'file' command will do that too.)

As of version 2.3.0 reading Elf objects with compressed section contents is supported, and one must have zlib and zstd installed to read object files with compressed sections. See REQUIREMENTS below. As of 2.3.1 we have tests of the decompression code on 64 and 32 bit objects.

Contents

object_detector

A program that reads a minimal amount of object header content (for any of the supported object types) and prints basic information (file type, offset size, and endianness) about each file.

readelfobj

A program that reads elf object files and prints the header information. It also checks for certain errors including wasted space in the object files. It also dumps Elf relocation sections, Elf symtab sections, and the Elf dynamic section.

readobjpe

A program that reads PE object executables or dlls and prints header information (mainly focused on sections that may be DWARF data).

readobjmacho

A program that reads MacOS dSYM files and prints header information. (mainly focused on sections that may be DWARF data).

The only library used is standard C libc.

The code does not depend on any Elf, Mach-o, or Windows libraries or headers, it depends on a basic POSIX/unix/Linux set of headers plus libc (or equivalent) and if you have some compressed object sections, decompression libraries.

The test directory contains numerous examples of using the programs.

To dump DWARF section contents one should use dwarfdump (a part of the libdwarf-code github project) or GNU readelf (in GNU binutils).

For Msys2 (Windows): The configure option --enable-nonstandardprintf may be required to avoid errors in certain printf.

REQUIREMENTS for decompression

If the objects you work with do not have section content compressed with zlib(libz) or libzstd neither those libraries nor their header files are required for building/using readelfobj. Defaults to --enable-decompression=yes

Ubuntu:
sudo apt install pkgconf zlib1g zlib1g-dev libzstd1
sudo apt install libzstd-dev

RUNNING MAKE CHECK from a release

Download the release from

https://github.com/davea42/readelfobj-code

and unpack

#For example:
tar xf readelfobj-1.0.0.xz
cd  readelfobj-1.0.0 
./configure --enable-wall
make
make check
#Building in a directory separate from
#the download also works

RUNNING MAKE CHECK from git clone:

Using a git clone is not recommended as the autogen.sh step requires one have the GNU autotools installed. We build outside the source tree to keep the tree clean.

#git clone https://github.com/davea42/readelfobj-code
#Linux/Unix/MacOS/MinGW(Windows)
src=/path/to/readelfobj-code
cd $src
sh autogen.sh

bld=/tmp/robld 
rm -rf $bld 
mkdir $bld
cd $bld
# may not be necessary.
sh $src/configure --enable-wall
make check 

To update configure, update configure.ac and/or one or more Makefile.am and do, in the top level directory: autoreconf -vif You will need several GNU autotools installed for this autoreconf to work.

About

This provides programs that read and print basic object information on three different object formats. Elf,MachO, and PE. They work regardless of endian differences. No object-format specific libraries are used, only the standard C library is required.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors