| 1 |
//! Support for reading PE files. |
| 2 |
//! |
| 3 |
//! Traits are used to abstract over the difference between PE32 and PE32+. |
| 4 |
//! The primary trait for this is [`ImageNtHeaders`]. |
| 5 |
//! |
| 6 |
//! ## High level API |
| 7 |
//! |
| 8 |
//! [`PeFile`] implements the [`Object`](crate::read::Object) trait for |
| 9 |
//! PE files. [`PeFile`] is parameterised by [`ImageNtHeaders`] to allow |
| 10 |
//! reading both PE32 and PE32+. There are type aliases for these parameters |
| 11 |
//! ([`PeFile32`] and [`PeFile64`]). |
| 12 |
//! |
| 13 |
//! ## Low level API |
| 14 |
//! |
| 15 |
//! The [`ImageNtHeaders`] trait can be directly used to parse both |
| 16 |
//! [`pe::ImageNtHeaders32`] and [`pe::ImageNtHeaders64`]. |
| 17 |
//! |
| 18 |
//! ### Example for low level API |
| 19 |
//! ```no_run |
| 20 |
//! use object::pe; |
| 21 |
//! use object::read::pe::ImageNtHeaders; |
| 22 |
//! use std::error::Error; |
| 23 |
//! use std::fs; |
| 24 |
//! |
| 25 |
//! /// Reads a file and displays the name of each section. |
| 26 |
//! fn main() -> Result<(), Box<dyn Error>> { |
| 27 |
//! # #[cfg(feature = "std")] { |
| 28 |
//! let data = fs::read("path/to/binary")?; |
| 29 |
//! let dos_header = pe::ImageDosHeader::parse(&*data)?; |
| 30 |
//! let mut offset = dos_header.nt_headers_offset().into(); |
| 31 |
//! let (nt_headers, data_directories) = pe::ImageNtHeaders64::parse(&*data, &mut offset)?; |
| 32 |
//! let sections = nt_headers.sections(&*data, offset)?; |
| 33 |
//! let symbols = nt_headers.symbols(&*data)?; |
| 34 |
//! for section in sections.iter() { |
| 35 |
//! println!("{}", String::from_utf8_lossy(section.name(symbols.strings())?)); |
| 36 |
//! } |
| 37 |
//! # } |
| 38 |
//! Ok(()) |
| 39 |
//! } |
| 40 |
//! ``` |
| 41 |
#[cfg(doc)] |
| 42 |
use crate::pe; |
| 43 |
|
| 44 |
mod file; |
| 45 |
pub use file::*; |
| 46 |
|
| 47 |
mod section; |
| 48 |
pub use section::*; |
| 49 |
|
| 50 |
mod data_directory; |
| 51 |
pub use data_directory::*; |
| 52 |
|
| 53 |
mod export; |
| 54 |
pub use export::*; |
| 55 |
|
| 56 |
mod import; |
| 57 |
pub use import::*; |
| 58 |
|
| 59 |
mod relocation; |
| 60 |
pub use relocation::*; |
| 61 |
|
| 62 |
mod resource; |
| 63 |
pub use resource::*; |
| 64 |
|
| 65 |
mod rich; |
| 66 |
pub use rich::*; |
| 67 |
|
| 68 |
pub use super::coff::{SectionTable, SymbolTable}; |