Skip to content

Commit

Permalink
PE: Add resource parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kkent030315 committed Oct 31, 2024
1 parent d096260 commit 7e2d000
Show file tree
Hide file tree
Showing 4 changed files with 1,451 additions and 0 deletions.
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

0 comments on commit 7e2d000

Please sign in to comment.