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 resource parser #431

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
18 changes: 18 additions & 0 deletions src/pe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use alloc::borrow::Cow;
use alloc::string::String;
use alloc::vec::Vec;
use log::warn;
use resource::ResourceData;

pub mod authenticode;
pub mod certificate_table;
Expand All @@ -23,6 +24,7 @@ pub mod import;
pub mod optional_header;
pub mod options;
pub mod relocation;
pub mod resource;
pub mod section_table;
pub mod subsystem;
pub mod symbol;
Expand Down Expand Up @@ -78,6 +80,8 @@ pub struct PE<'a> {
pub exception_data: Option<exception::ExceptionData<'a>>,
/// Certificates present, if any, described by the Certificate Table
pub certificates: certificate_table::CertificateDirectoryTable<'a>,
/// Resource information if any
pub resource_data: Option<ResourceData<'a>>,
}

impl<'a> PE<'a> {
Expand Down Expand Up @@ -112,6 +116,7 @@ impl<'a> PE<'a> {
let mut tls_data = None;
let mut exception_data = None;
let mut certificates = Default::default();
let mut resource_data = Default::default();
let mut is_64 = false;
if let Some(optional_header) = header.optional_header {
// Sections we are assembling through the parsing, eventually, it will be passed
Expand Down Expand Up @@ -278,6 +283,18 @@ impl<'a> PE<'a> {
0
};

if let Some(&resource_table) = optional_header.data_directories.get_resource_table() {
let data = resource::ResourceData::parse_with_opts(
bytes,
resource_table,
&sections,
file_alignment,
opts,
)?;
resource_data = Some(data);
debug!("resource_data data: {:#?}", data.version_info);
}

authenticode_excluded_sections = Some(authenticode::ExcludedSections::new(
checksum,
datadir_entry_certtable,
Expand Down Expand Up @@ -305,6 +322,7 @@ impl<'a> PE<'a> {
tls_data,
exception_data,
certificates,
resource_data,
})
}

Expand Down
Loading
Loading