| 1 |
# `object` |
| 2 |
|
| 3 |
The `object` crate provides a unified interface to working with object files |
| 4 |
across platforms. It supports reading relocatable object files and executable files, |
| 5 |
and writing COFF/ELF/Mach-O/XCOFF relocatable object files and ELF/PE executable files. |
| 6 |
|
| 7 |
For reading files, it provides multiple levels of support: |
| 8 |
|
| 9 |
* raw struct definitions suitable for zero copy access |
| 10 |
* low level APIs for accessing the raw structs ([example](crates/examples/src/readobj/)) |
| 11 |
* a higher level unified API for accessing common features of object files, such |
| 12 |
as sections and symbols ([example](crates/examples/src/objdump.rs)) |
| 13 |
|
| 14 |
Supported file formats for reading: ELF, Mach-O, Windows PE/COFF, Wasm, XCOFF, and Unix archive. |
| 15 |
|
| 16 |
For writing files, it provides: |
| 17 |
|
| 18 |
* low level writers for ELF, PE, and COFF |
| 19 |
* higher level builder for ELF ([example](crates/rewrite/src)) |
| 20 |
* a unified API for writing relocatable object files (ELF, Mach-O, COFF, XCOFF) |
| 21 |
([example](crates/examples/src/bin/simple_write.rs)) |
| 22 |
|
| 23 |
## Example for unified read API |
| 24 |
```rust |
| 25 |
use object::{Object, ObjectSection}; |
| 26 |
use std::error::Error; |
| 27 |
use std::fs; |
| 28 |
|
| 29 |
/// Reads a file and displays the name of each section. |
| 30 |
fn main() -> Result<(), Box<dyn Error>> { |
| 31 |
let binary_data = fs::read("path/to/binary")?; |
| 32 |
let file = object::File::parse(&*binary_data)?; |
| 33 |
for section in file.sections() { |
| 34 |
println!("{}", section.name()?); |
| 35 |
} |
| 36 |
Ok(()) |
| 37 |
} |
| 38 |
``` |
| 39 |
|
| 40 |
See [`crates/examples`](crates/examples) for more examples. |
| 41 |
|
| 42 |
## Minimum Supported Rust Version (MSRV) |
| 43 |
|
| 44 |
Changes to MSRV are considered breaking changes. We are conservative about changing the MSRV, |
| 45 |
but sometimes are required to due to dependencies. The MSRV is 1.65.0. |
| 46 |
|
| 47 |
## License |
| 48 |
|
| 49 |
Licensed under either of |
| 50 |
|
| 51 |
* Apache License, Version 2.0 ([`LICENSE-APACHE`](./LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0) |
| 52 |
* MIT license ([`LICENSE-MIT`](./LICENSE-MIT) or https://opensource.org/licenses/MIT) |
| 53 |
|
| 54 |
at your option. |
| 55 |
|
| 56 |
## Contribution |
| 57 |
|
| 58 |
Unless you explicitly state otherwise, any contribution intentionally submitted |
| 59 |
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be |
| 60 |
dual licensed as above, without any additional terms or conditions. |