Skip to content

Commit bc33409

Browse files
authored
PE: Add base relocation parser (#444)
* Add new base relocation parser * Add base reloc constants
1 parent f06b768 commit bc33409

File tree

2 files changed

+563
-1
lines changed

2 files changed

+563
-1
lines changed

src/pe/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ pub struct PE<'a> {
7777
pub tls_data: Option<tls::TlsData<'a>>,
7878
/// Exception handling and stack unwind information, if any, contained in the PE header
7979
pub exception_data: Option<exception::ExceptionData<'a>>,
80+
/// Base relocation data if any
81+
pub relocation_data: Option<relocation::RelocationData<'a>>,
8082
/// Certificates present, if any, described by the Certificate Table
8183
pub certificates: certificate_table::CertificateDirectoryTable<'a>,
8284
}
@@ -112,6 +114,7 @@ impl<'a> PE<'a> {
112114
let mut debug_data = None;
113115
let mut tls_data = None;
114116
let mut exception_data = None;
117+
let mut relocation_data = None;
115118
let mut certificates = Default::default();
116119
let mut is_64 = false;
117120
if let Some(optional_header) = header.optional_header {
@@ -250,6 +253,18 @@ impl<'a> PE<'a> {
250253
}
251254
}
252255

256+
if let Some(&baserelocs_dir) =
257+
optional_header.data_directories.get_base_relocation_table()
258+
{
259+
relocation_data = Some(relocation::RelocationData::parse_with_opts(
260+
bytes,
261+
baserelocs_dir,
262+
&sections,
263+
file_alignment,
264+
opts,
265+
)?);
266+
}
267+
253268
// Parse attribute certificates unless opted out of
254269
let certificate_table_size = if opts.parse_attribute_certificates {
255270
if let Some(&certificate_table) =
@@ -303,6 +318,7 @@ impl<'a> PE<'a> {
303318
debug_data,
304319
tls_data,
305320
exception_data,
321+
relocation_data,
306322
certificates,
307323
})
308324
}

0 commit comments

Comments
 (0)