Libelf by Example
About the Book
This tutorial introduces libelf, a library implementing the ELF(3)/GELF(3) API for reading and writing object code in the Extensible Linking Format (ELF) file format.
The tutorial covers:
- Getting started with libelf: obtaining a handle to an ELF object, establishing a working ELF version, and handling errors reported by libelf.
- How ELF data structures are laid out in-memory and on disk, the notions of "file representation" and "memory representation", how to write applications that can handle non-native binaries.
- ELF Segments and the ELF Program Header Table, retrieving the program header table from an ELF executable and the meaning of the fields of a program header table entry.
- How data is stored inside ELF sections, the ELF Section Header Table, and how to traverse the sections in an ELF object.
- How to create new ELF objects: the rules for ordering individual API calls, the default object layout implemented by libelf, and how to specify custom layouts.
- ar archives: their structure, and how to read the contents of these archives using the APIs provided by libelf.
The code in this tutorial is written in the C programming language.
While written for the libelf implementation that is part of the Elftoolchain open-source project, this tutorial is expected to be compatible with other libelf implementations, such as that offered by the GNU project.
This 'source' for this tutorial is itself published under a liberal license; please see the Elftoolchain project's site.
- 1. Introduction
- 1.1 Tutorial Overview
- 1.2 Tutorial Structure
- 2. Getting Started
- 2.1 Example: Getting started with libelf
- 3. Peering Inside an ELF Object
- 3.1 The Layout of an ELF file
- 3.2 Example: Reading an ELF executable header
- 4. Examining the Program Header Table
- 4.1 The ELF Program Header Table
- 4.2 Example: Reading a Program Header Table
- 5. Looking at Sections
- 5.1 ELF section handling with libelf
- 5.2 Example: Listing section names
- 6. Creating new ELF objects
- 6.1 Example: Creating an ELF object
- 6.2 The finer points in creating ELF objects
- 7. Processing ar(1) archives
- 7.1 Archive structure
- 7.2 Example: Stepping through an ar(1) archive
- 8. Conclusion
- 8.1 Further Reading
- 8.2 Getting Further Help
Electronic Frontier Foundation
Defending your civil liberties in a digital world.https://www.eff.org/
Based in San Francisco, EFF is a donor-supported membership organization working to protect fundamental rights regardless of technology.
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.