Skip to content

Commit

Permalink
pe: Assume AddressOfIndex could not be in raw section, check callba…
Browse files Browse the repository at this point in the history
…ck is zero right after it reads from binary (#425)

* PE: Assume `AddressOfIndex` could not be in raw section, check callback is zero right after it reads from binary
* Simplify the expression with same semantics
  • Loading branch information
kkent030315 authored Oct 25, 2024
1 parent b2505ec commit 29dcaad
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/pe/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,8 @@ impl<'a> TlsData<'a> {

// VA to RVA
let rva = itd.address_of_index as usize - image_base;
let offset =
utils::find_offset(rva, sections, file_alignment, opts).ok_or_else(|| {
error::Error::Malformed(format!(
"cannot map tls address_of_index rva ({:#x}) into offset",
rva
))
})?;

slot = Some(bytes.pread_with::<u32>(offset, scroll::LE)?);
let offset = utils::find_offset(rva, sections, file_alignment, opts);
slot = offset.and_then(|x| bytes.pread_with::<u32>(x, scroll::LE).ok());
}

// Parse the callbacks if any
Expand Down Expand Up @@ -227,6 +220,9 @@ impl<'a> TlsData<'a> {
} else {
bytes.pread_with::<u32>(offset + i * 4, scroll::LE)? as u64
};
if callback == 0 {
break;
}
// Each callback is an VA so convert it to RVA
let callback_rva = callback as usize - image_base;
// Check if the callback is in the image
Expand All @@ -236,9 +232,6 @@ impl<'a> TlsData<'a> {
callback
)));
}
if callback == 0 {
break;
}
callbacks.push(callback);
i += 1;
}
Expand Down

0 comments on commit 29dcaad

Please sign in to comment.