Expand description
Support for reading PE files.
Traits are used to abstract over the difference between PE32 and PE32+.
The primary trait for this is ImageNtHeaders
.
High level API
PeFile
implements the Object
trait for
PE files. PeFile
is parameterised by ImageNtHeaders
to allow
reading both PE32 and PE32+. There are type aliases for these parameters
(PeFile32
and PeFile64
).
Low level API
The ImageNtHeaders
trait can be directly used to parse both
pe::ImageNtHeaders32
and pe::ImageNtHeaders64
.
Example for low level API
use object::pe;
use object::read::pe::ImageNtHeaders;
use std::error::Error;
use std::fs;
/// Reads a file and displays the name of each section.
fn main() -> Result<(), Box<dyn Error>> {
let data = fs::read("path/to/binary")?;
let dos_header = pe::ImageDosHeader::parse(&*data)?;
let mut offset = dos_header.nt_headers_offset().into();
let (nt_headers, data_directories) = pe::ImageNtHeaders64::parse(&*data, &mut offset)?;
let sections = nt_headers.sections(&*data, offset)?;
let symbols = nt_headers.symbols(&*data)?;
for section in sections.iter() {
println!("{}", String::from_utf8_lossy(section.name(symbols.strings())?));
}
Ok(())
}
Re-exports
pub use super::coff::SectionTable;
pub use super::coff::SymbolTable;
Structs
- The table of data directories in a PE file.
- A fallible iterator for the descriptors in the delay-load data directory.
- Information for parsing a PE delay-load import table.
- An export from a PE file.
- A partially parsed PE export table.
- A fallible iterator for the descriptors in the import data directory.
- Information for parsing a PE import table.
- A list of import thunks.
- A COMDAT section group in a
PeFile
. - An iterator for the COMDAT section groups in a
PeFile
. - An iterator for the sections in a COMDAT section group in a
PeFile
. - A PE image file.
- An iterator for the relocations in an
PeSection
. - A section in a
PeFile
. - An iterator for the sections in a
PeFile
. - A loadable section in a
PeFile
. - An iterator for the loadable sections in a
PeFile
. - A relocation in the
.reloc
section of a PE file. - An iterator over the relocation blocks in the
.reloc
section of a PE file. - An iterator of the relocations in a block in the
.reloc
section of a PE file. - The
.rsrc
section of a PE file. - A table of resource entries.
- A resource name.
- A PE rich header entry after it has been unmasked.
- Parsed information about a Rich Header.
Enums
- Where an export is pointing to.
- A parsed import thunk.
- Data associated with a resource directory entry.
- A resource name or ID.
Traits
- A trait for generic access to
pe::ImageNtHeaders32
andpe::ImageNtHeaders64
. - A trait for generic access to
pe::ImageOptionalHeader32
andpe::ImageOptionalHeader64
. - A trait for generic access to
pe::ImageThunkData32
andpe::ImageThunkData64
.
Functions
- Find the optional header and read its
magic
field.
Type Aliases
- A COMDAT section group in a
PeFile32
. - A COMDAT section group in a
PeFile64
. - An iterator for the COMDAT section groups in a
PeFile32
. - An iterator for the COMDAT section groups in a
PeFile64
. - An iterator for the sections in a COMDAT section group in a
PeFile32
. - An iterator for the sections in a COMDAT section group in a
PeFile64
. - A PE32 (32-bit) image file.
- A PE32+ (64-bit) image file.
- A section in a
PeFile32
. - A section in a
PeFile64
. - An iterator for the sections in a
PeFile32
. - An iterator for the sections in a
PeFile64
. - A loadable section in a
PeFile32
. - A loadable section in a
PeFile64
. - An iterator for the loadable sections in a
PeFile32
. - An iterator for the loadable sections in a
PeFile64
.