Skip to content

PE: Add resource parser #431

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

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7e2d000
PE: Add resource parser
kkent030315 Oct 29, 2024
cef82f6
Simplify expression
kkent030315 Oct 31, 2024
3b8d596
Add doc comment
kkent030315 Oct 31, 2024
b1f8ca3
alloc compatible
kkent030315 Oct 31, 2024
2d74eda
Fix doc comment
kkent030315 Oct 31, 2024
7cda493
Simplify expressions
kkent030315 Oct 31, 2024
912526b
add test
kkent030315 Nov 1, 2024
1af1c97
more stricter tests
kkent030315 Nov 2, 2024
fb17c99
Fix docs, check malformed to prevent panics
kkent030315 Nov 2, 2024
e0f95c1
Fix doc
kkent030315 Nov 2, 2024
4c6712c
Check malformed for iterator data
kkent030315 Nov 2, 2024
fbe0900
Remove `pub` from `num_resources`
kkent030315 Dec 11, 2024
860e7ef
Remove `pub` from `data`
kkent030315 Dec 11, 2024
c0742ec
Remove `pub` from `data`
kkent030315 Dec 11, 2024
f6d5264
Remove unnecessary lifetime from impl `VsFixedFileInfo`
kkent030315 Dec 11, 2024
2d7749a
Remove `pub` from `VersionInfo::data`
kkent030315 Dec 11, 2024
9af1f1d
Simplify entry id identification
kkent030315 Dec 11, 2024
e107d84
try impl `ResourceEntryIterator::find_by_id`
kkent030315 Dec 11, 2024
34038d0
adjustment for with or without alignments
kkent030315 Jan 4, 2025
4b8ced4
Merge remote-tracking branch 'upstream/master' into rsrcversioninfo
kkent030315 Jun 16, 2025
65bfbb7
move `align_up` to `utils`
kkent030315 Jun 16, 2025
0052eb6
add `Utf16String<'a>` for parsing utf16 strings
kkent030315 Jun 16, 2025
4a8d2cc
fix comment
kkent030315 Jun 16, 2025
c12c119
make `StringFileInfo` fields private
kkent030315 Jun 16, 2025
fef7955
make `next_iter` safe
kkent030315 Jun 16, 2025
24a09ea
use `pread_with::<&[u8]>` for simplifying code
kkent030315 Jun 16, 2025
916d581
remove noop offset alignment
kkent030315 Jun 16, 2025
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