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

Add ParseOptions field to toggle parsing Attribute Certificates for PEs loaded into memory #377

Merged
merged 6 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
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
27 changes: 16 additions & 11 deletions src/pe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,23 @@ impl<'a> PE<'a> {
}
}

let certtable = if let Some(certificate_table) =
*optional_header.data_directories.get_certificate_table()
{
certificates = certificate_table::enumerate_certificates(
bytes,
certificate_table.virtual_address,
certificate_table.size,
)?;
// Parse attribute certificates unless opted out of
let certtable = if opts.parse_attribute_certificates {
if let Some(certificate_table) =
*optional_header.data_directories.get_certificate_table()
{
certificates = certificate_table::enumerate_certificates(
bytes,
certificate_table.virtual_address,
certificate_table.size,
)?;

let start = certificate_table.virtual_address as usize;
let end = start + certificate_table.size as usize;
Some(start..end)
let start = certificate_table.virtual_address as usize;
let end = start + certificate_table.size as usize;
Some(start..end)
} else {
None
}
} else {
None
};
Expand Down
10 changes: 9 additions & 1 deletion src/pe/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
pub struct ParseOptions {
/// Wether the parser should resolve rvas or not. Default: true
pub resolve_rva: bool,
/// Whether or not to parse attribute certificates.
/// Set to false for in-memory representation, as the [loader does not map this info into
/// memory](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#other-contents-of-the-file).
/// For on-disk representations, leave as true. Default: true
pub parse_attribute_certificates: bool,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it would perhaps be slightly better to have the fields in ascending alphanumeric order (that is, parse_attribute_certificates before resolve_rva).

}

impl ParseOptions {
/// Returns a parse options structure with default values
pub fn default() -> Self {
ParseOptions { resolve_rva: true }
ParseOptions {
resolve_rva: true,
parse_attribute_certificates: true,
}
}
}
Loading