Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PE: add overlay detection #344

Merged
merged 3 commits into from
Aug 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/read/coff/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ impl<'data> SectionTable<'data> {
.find(|(_, section)| section.name(strings) == Ok(name))
.map(|(index, section)| (index + 1, section))
}

/// Compute the maximum file offset used by sections.
daladim marked this conversation as resolved.
Show resolved Hide resolved
///
/// This will usually match the end of file, unless the PE file has a [data overlay]
/// (https://security.stackexchange.com/questions/77336/how-is-the-file-overlay-read-by-an-exe-virus)
pub fn max_section_file_offset(&self) -> u64 {
let mut max = 0;
for section in self.iter() {
match (section.pointer_to_raw_data.get(LE) as u64)
.checked_add(section.size_of_raw_data.get(LE) as u64)
{
None => {
// This cannot happen, we're suming two u32 into a u64
continue;
}
Some(end_of_section) => {
if end_of_section > max {
max = end_of_section;
}
}
}
}
max
}
}

/// An iterator over the loadable sections of a `CoffFile`.
Expand Down