From 43278d581c05507dd99802a2a533e5a5f3ec6827 Mon Sep 17 00:00:00 2001 From: ideeockus Date: Wed, 13 Mar 2024 22:18:10 +0300 Subject: [PATCH] pe.header: added ability to parse part of pe header without dos --- src/pe/header.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pe/header.rs b/src/pe/header.rs index b7f52b3e..1c308361 100644 --- a/src/pe/header.rs +++ b/src/pe/header.rs @@ -543,14 +543,15 @@ pub struct Header { } impl Header { + /// Parses PE header from the given bytes, use default DosHeader if missed pub fn parse(bytes: &[u8]) -> error::Result { - let dos_header = DosHeader::parse(&bytes)?; + let dos_header = DosHeader::parse(&bytes).unwrap_or_default(); let dos_stub = bytes.pread(DOS_STUB_OFFSET as usize).map_err(|_| { error::Error::Malformed(format!( "cannot parse DOS stub (offset {:#x})", DOS_STUB_OFFSET )) - })?; + }).unwrap_or_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))