Skip to content

Commit

Permalink
pe.header: added ability to parse part of pe header without dos
Browse files Browse the repository at this point in the history
  • Loading branch information
ideeockus committed Mar 13, 2024
1 parent 06cf965 commit 1a6abe6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/pe/header.rs
Expand Up @@ -569,6 +569,29 @@ impl Header {
optional_header,
})
}

pub fn parse_without_dos(bytes: &[u8]) -> error::Result<Self> {
let dos_header = DosHeader::default();
let mut offset = dos_header.pe_pointer as usize;
let signature = bytes.gread_with(&mut offset, scroll::LE).map_err(|_| {
error::Error::Malformed(format!("cannot parse PE signature (offset {:#x})", offset))
})?;
let coff_header = CoffHeader::parse(bytes, &mut offset)?;
let optional_header = if coff_header.size_of_optional_header > 0 {
let opt_hdr = bytes.pread::<optional_header::OptionalHeader>(offset)?;
Some(opt_hdr)
} else {
None
};

Ok(Header {
dos_header,
dos_stub: DosStub::default(),
signature,
coff_header,
optional_header,
})
}
}

impl ctx::TryIntoCtx<scroll::Endian> for Header {
Expand Down

0 comments on commit 1a6abe6

Please sign in to comment.