/// Read the NT headers, including the data directories.
///
/// The DOS header is required to determine the NT headers offset.
///
/// The given data must be for the entire file.  Returns the data following the NT headers,
/// which will contain the section headers.
///
/// Also checks that the `signature` and `magic` fields in the headers are valid.
Read the NT headers, including the data directories.
The DOS header is required to determine the NT headers offset.

The given data must be for the entire file.  Returns the data following the NT headers,
which will contain the section headers.

Also checks that the `signature` and `magic` fields in the headers are valid.
Read the NT headers including the data directories . The DOS header is required to determine the NT headers offset . The given data must be for the entire file . Returns the data following the NT headers which will contain the section headers . Also checks that the ` signature ` and ` magic ` fields in the headers are valid .
fn parse<'data>(
        dos_header: &pe::ImageDosHeader,
        mut data: Bytes<'data>,
    ) -> read::Result<(&'data Self, &'data [pe::ImageDataDirectory], Bytes<'data>)> {
        data.skip(dos_header.e_lfanew.get(LE) as usize)
            .read_error("Invalid PE headers offset")?;
        // Note that this does not include the data directories in the optional header.
        let nt_headers = data
            .read::<Self>()
            .read_error("Invalid PE headers size or alignment")?;
        if nt_headers.signature() != pe::IMAGE_NT_SIGNATURE {
            return Err(Error("Invalid PE magic"));
        }
        if !nt_headers.is_valid_optional_magic() {
            return Err(Error("Invalid PE optional header magic"));
        }
        // Read the rest of the optional header, and then read the data directories from that.
        let optional_data_size = (nt_headers.file_header().size_of_optional_header.get(LE)
            as usize)
            .checked_sub(mem::size_of::<Self::ImageOptionalHeader>())
            .read_error("PE optional header size is too small")?;
        let mut optional_data = data
            .read_bytes(optional_data_size)
            .read_error("Invalid PE optional header size")?;
        let data_directories = optional_data
            .read_slice(nt_headers.optional_header().number_of_rva_and_sizes() as usize)
            .read_error("Invalid PE number of RVA and sizes")?;
        Ok((nt_headers, data_directories, data))
    }
fn parse < ' data > ( dos_header : & pe :: ImageDosHeader , mut data : Bytes < ' data > , ) -> read :: Result < ( & ' data Self , & ' data [ pe :: ImageDataDirectory ] , Bytes < ' data > ) > { data . skip ( dos_header . e_lfanew . get ( LE ) as usize ) . read_error ( " " ) ? ; // Note that this does not include the data directories in the optional header. let nt_headers = data . read :: < Self > ( ) . read_error ( " " ) ? ; if nt_headers . signature ( ) != pe :: IMAGE_NT_SIGNATURE { return Err ( Error ( " " ) ) ; } if ! nt_headers . is_valid_optional_magic ( ) { return Err ( Error ( " " ) ) ; } // Read the rest of the optional header, and then read the data directories from that. let optional_data_size = ( nt_headers . file_header ( ) . size_of_optional_header . get ( LE ) as usize ) . checked_sub ( mem :: size_of :: < Self :: ImageOptionalHeader > ( ) ) . read_error ( " " ) ? ; let mut optional_data = data . read_bytes ( optional_data_size ) . read_error ( " " ) ? ; let data_directories = optional_data . read_slice ( nt_headers . optional_header ( ) . number_of_rva_and_sizes ( ) as usize ) . read_error ( " " ) ? ; Ok ( ( nt_headers , data_directories , data ) ) }
Read the NT headers, including the data directories.
Read the NT headers including the data directories .
dos_header
&pe::ImageDosHeader
data
Bytes<'data>