The object package provides a unified interface for working with object files
across platforms. It supports reading relocatable object files and executable files,
and writing COFF/ELF/Mach-O/XCOFF relocatable object files and ELF/PE/Mach-O
executable files.
For reading files the library provides various abstraction levels:
- raw type/record definitions close to the original C definitions
- low level APIs for accessing specific formats
- a higher level unified API for accessing common features of object files, such as sections and symbols
Supported file formats for reading: ELF, Mach-O, and PE/COFF.
For writing files the library provides:
- low level writers for ELF, and Mach-O.
- higher level builder for ELF
- a unified API for writing relocatable object files (ELF, Mach-O)
To install object as a dependency, run:
$ opam install objectAnd add object to your project's dune-project or *.opam files.
The tests for object are split between:
- Unit tests in
test/unitthat build in-memory representations of binaries and test they can be parsed correctly. They can be run usingdune build @runtest. - Integration tests in
test/integrationthat use the system toolchain to build binaries and check they can be parsed correctly. These tests rely more on specific versions of the toolchain that match GitHub CI runners. They can be run usingdune build @integration.
Both suites can be run together with dune build @run-all-tests.
- Documentation on ocaml.org
- Example programs in
exampledirectory- A simple file implementation that checks for MAGIC numbers
- A simple objdump implementation for displaying the section headers.
- Implementation of nm to display name list (aka symbol table).
- Implementation of otool the object file displaying tool for MachO binaries
- Implementation of lipo for creating or operating on universal files (aka FAT binaries).
- Reading file formats: Unix Archive.
- Writing PE/COFF files
This motivation for this library grew out of the author's need to manipulate object files and DWARF information while working on the OCaml compiler. The library name simultaneously derives from the author's fascination with objects in OCaml and the Rust library of the same name.
The PE/COFF support was informed by these existing OCaml parsers: