Fix section extraction

This commit is contained in:
Julian Stecklina 2022-11-23 17:57:23 +01:00
parent 24803a04a2
commit fa331d8b98
1 changed files with 3 additions and 1 deletions

View File

@ -10,7 +10,9 @@ pub fn pe_section<'a>(file_data: &'a [u8], section_name: &str) -> Option<&'a [u8
.find(|s| s.name().unwrap() == section_name) .find(|s| s.name().unwrap() == section_name)
.and_then(|s| { .and_then(|s| {
let section_start: usize = s.pointer_to_raw_data.try_into().ok()?; let section_start: usize = s.pointer_to_raw_data.try_into().ok()?;
let section_end: usize = section_start + usize::try_from(s.size_of_raw_data).ok()?;
assert!(s.virtual_size <= s.size_of_raw_data);
let section_end: usize = section_start + usize::try_from(s.virtual_size).ok()?;
Some(&file_data[section_start..section_end]) Some(&file_data[section_start..section_end])
}) })