]>
Commit | Line | Data |
---|---|---|
9c376795 FG |
1 | # `object` |
2 | ||
3 | The `object` crate provides a unified interface to working with object files | |
fe692bf9 FG |
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. | |
9c376795 FG |
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 | ||
fe692bf9 | 14 | Supported file formats: ELF, Mach-O, Windows PE/COFF, Wasm, XCOFF, and Unix archive. |
9c376795 FG |
15 | |
16 | ## Example for unified read API | |
17 | ```rust | |
18 | use object::{Object, ObjectSection}; | |
19 | use std::error::Error; | |
20 | use std::fs; | |
21 | ||
22 | /// Reads a file and displays the content of the ".boot" section. | |
23 | fn main() -> Result<(), Box<dyn Error>> { | |
24 | let bin_data = fs::read("./multiboot2-binary.elf")?; | |
25 | let obj_file = object::File::parse(&*bin_data)?; | |
26 | if let Some(section) = obj_file.section_by_name(".boot") { | |
27 | println!("{:#x?}", section.data()?); | |
28 | } else { | |
29 | eprintln!("section not available"); | |
30 | } | |
31 | Ok(()) | |
32 | } | |
33 | ``` | |
34 | ||
35 | See [`crates/examples`](crates/examples) for more examples. | |
36 | ||
37 | ## Minimum Supported Rust Version (MSRV) | |
38 | ||
39 | Changes to MSRV are considered breaking changes. We are conservative about changing the MSRV, | |
40 | but sometimes are required to due to dependencies. The MSRV is: | |
41 | ||
49aad941 FG |
42 | * 1.52.0 for the `read` feature and its dependencies. |
43 | * 1.61.0 for the `write` feature and its dependencies. | |
9c376795 FG |
44 | |
45 | ## License | |
46 | ||
47 | Licensed under either of | |
48 | ||
49 | * Apache License, Version 2.0 ([`LICENSE-APACHE`](./LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0) | |
50 | * MIT license ([`LICENSE-MIT`](./LICENSE-MIT) or https://opensource.org/licenses/MIT) | |
51 | ||
52 | at your option. | |
53 | ||
54 | ## Contribution | |
55 | ||
56 | Unless you explicitly state otherwise, any contribution intentionally submitted | |
57 | for inclusion in the work by you, as defined in the Apache-2.0 license, shall be | |
58 | dual licensed as above, without any additional terms or conditions. |