Skip to content

Commit

Permalink
Fix rich header parser for stability
Browse files Browse the repository at this point in the history
NOTE: all `cargo test` passed
  • Loading branch information
kkent030315 committed Oct 10, 2024
1 parent e29c121 commit 7274230
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pe/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ pub struct Header<'a> {
pub dos_header: DosHeader,
/// DOS program for legacy loaders
pub dos_stub: &'a [u8],
/// The Rich header added by MSVC linker, see [RichHeader] for more information.
pub rich_header: Option<RichHeader<'a>>,

// Q (JohnScience): should we care about the "rich header"?
Expand Down Expand Up @@ -964,7 +965,7 @@ impl<'a> RichHeader<'a> {
let metadatas = rich_header
.chunks(8)
.map(|chunk| {
let build_and_product = u32::from_le_bytes(chunk[0..4].try_into().unwrap()) ^ key;
let build_and_product = u32::from_le_bytes(chunk[..4].try_into().unwrap()) ^ key;
let build = (build_and_product & 0xFFFF) as u16;
let product = (build_and_product >> 16) as u16;
let use_count = u32::from_le_bytes(chunk[4..8].try_into().unwrap()) ^ key;
Expand All @@ -976,8 +977,7 @@ impl<'a> RichHeader<'a> {
})
.collect();

let start_offset = scan_start as u32 + rich_start_offset as u32 + padding_count as u32 - 4;
// Right before the Rich marker
let start_offset = scan_start as u32 + rich_start_offset as u32 - 4;
let end_offset = scan_start as u32 + rich_end_offset as u32;

Ok(Some(RichHeader {
Expand Down

0 comments on commit 7274230

Please sign in to comment.