Skip to content

Commit cfe9c26

Browse files
authored
PE: Add resource parser (#431)
* PE: Add resource parser * Add tests
1 parent 09bd764 commit cfe9c26

File tree

5 files changed

+1954
-0
lines changed

5 files changed

+1954
-0
lines changed

src/pe/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use alloc::borrow::Cow;
99
use alloc::string::String;
1010
use alloc::vec::Vec;
1111
use log::warn;
12+
use resource::ResourceData;
1213

1314
pub mod authenticode;
1415
pub mod certificate_table;
@@ -24,6 +25,7 @@ pub mod load_config;
2425
pub mod optional_header;
2526
pub mod options;
2627
pub mod relocation;
28+
pub mod resource;
2729
pub mod section_table;
2830
pub mod subsystem;
2931
pub mod symbol;
@@ -84,6 +86,8 @@ pub struct PE<'a> {
8486
pub load_config_data: Option<load_config::LoadConfigData>,
8587
/// Certificates present, if any, described by the Certificate Table
8688
pub certificates: certificate_table::CertificateDirectoryTable<'a>,
89+
/// Resource information if any
90+
pub resource_data: Option<ResourceData<'a>>,
8791
}
8892

8993
impl<'a> PE<'a> {
@@ -120,6 +124,7 @@ impl<'a> PE<'a> {
120124
let mut relocation_data = None;
121125
let mut load_config_data = None;
122126
let mut certificates = Default::default();
127+
let mut resource_data = Default::default();
123128
let mut is_64 = false;
124129
if let Some(optional_header) = header.optional_header {
125130
// Sections we are assembling through the parsing, eventually, it will be passed
@@ -310,6 +315,18 @@ impl<'a> PE<'a> {
310315
0
311316
};
312317

318+
if let Some(&resource_table) = optional_header.data_directories.get_resource_table() {
319+
let data = resource::ResourceData::parse_with_opts(
320+
bytes,
321+
resource_table,
322+
&sections,
323+
file_alignment,
324+
opts,
325+
)?;
326+
resource_data = Some(data);
327+
debug!("resource_data data: {:#?}", data.version_info);
328+
}
329+
313330
authenticode_excluded_sections = Some(authenticode::ExcludedSections::new(
314331
checksum,
315332
datadir_entry_certtable,
@@ -339,6 +356,7 @@ impl<'a> PE<'a> {
339356
relocation_data,
340357
load_config_data,
341358
certificates,
359+
resource_data,
342360
})
343361
}
344362

0 commit comments

Comments
 (0)