Skip to content
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

PE: Assume AddressOfIndex could not be in raw section, check callback is zero right after it reads from binary #425

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
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
17 changes: 5 additions & 12 deletions src/pe/tls.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -236,9 +232,6 @@ impl<'a> TlsData<'a> {
callback
)));
}
if callback == 0 {
break;
}
callbacks.push(callback);
i += 1;
}