| 1 | //! Support for reading Windows COFF files. |
| 2 | //! |
| 3 | //! Traits are used to abstract over the difference between COFF object files |
| 4 | //! and COFF bigobj files. The primary trait for this is [`CoffHeader`]. |
| 5 | //! |
| 6 | //! ## High level API |
| 7 | //! |
| 8 | //! [`CoffFile`] implements the [`Object`](crate::read::Object) trait for |
| 9 | //! COFF files. [`CoffFile`] is parameterised by [`CoffHeader`]. |
| 10 | //! The default parameter allows reading regular COFF object files, |
| 11 | //! while the type alias [`CoffBigFile`] allows reading COFF bigobj files. |
| 12 | //! |
| 13 | //! [`ImportFile`] allows reading COFF short imports that are used in import |
| 14 | //! libraries. Currently these are not integrated with the unified read API. |
| 15 | //! |
| 16 | //! ## Low level API |
| 17 | //! |
| 18 | //! The [`CoffHeader`] trait can be directly used to parse both COFF |
| 19 | //! object files (which start with [`pe::ImageFileHeader`]) and COFF bigobj |
| 20 | //! files (which start with [`pe::AnonObjectHeaderBigobj`]). |
| 21 | //! |
| 22 | //! ### Example for low level API |
| 23 | //! ```no_run |
| 24 | //! use object::pe; |
| 25 | //! use object::read::coff::{CoffHeader, ImageSymbol as _}; |
| 26 | //! use std::error::Error; |
| 27 | //! use std::fs; |
| 28 | //! |
| 29 | //! /// Reads a file and displays the name of each section and symbol. |
| 30 | //! fn main() -> Result<(), Box<dyn Error>> { |
| 31 | //! # #[cfg (feature = "std" )] { |
| 32 | //! let data = fs::read("path/to/binary" )?; |
| 33 | //! let mut offset = 0; |
| 34 | //! let header = pe::ImageFileHeader::parse(&*data, &mut offset)?; |
| 35 | //! let sections = header.sections(&*data, offset)?; |
| 36 | //! let symbols = header.symbols(&*data)?; |
| 37 | //! for section in sections.iter() { |
| 38 | //! println!("{}" , String::from_utf8_lossy(section.name(symbols.strings())?)); |
| 39 | //! } |
| 40 | //! for (_index, symbol) in symbols.iter() { |
| 41 | //! println!("{}" , String::from_utf8_lossy(symbol.name(symbols.strings())?)); |
| 42 | //! } |
| 43 | //! # } |
| 44 | //! Ok(()) |
| 45 | //! } |
| 46 | //! ``` |
| 47 | #[cfg (doc)] |
| 48 | use crate::pe; |
| 49 | |
| 50 | mod file; |
| 51 | pub use file::*; |
| 52 | |
| 53 | mod section; |
| 54 | pub use section::*; |
| 55 | |
| 56 | mod symbol; |
| 57 | pub use symbol::*; |
| 58 | |
| 59 | mod relocation; |
| 60 | pub use relocation::*; |
| 61 | |
| 62 | mod comdat; |
| 63 | pub use comdat::*; |
| 64 | |
| 65 | mod import; |
| 66 | pub use import::*; |
| 67 | |