Skip to content

Commit

Permalink
read/pe: stop iterating import directory entries at a completely null…
Browse files Browse the repository at this point in the history
… item (#385)
  • Loading branch information
daladim authored Sep 28, 2021
1 parent 37d68d0 commit 4db37ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,18 @@ pub struct ImageImportDescriptor {
pub first_thunk: U32Bytes<LE>,
}

impl ImageImportDescriptor {
/// Tell whether this import descriptor is the null descriptor
/// (used to mark the end of the iterator array in a PE)
pub fn is_null(&self) -> bool {
self.original_first_thunk.get(LE) == 0
&& self.time_date_stamp.get(LE) == 0
&& self.forwarder_chain.get(LE) == 0
&& self.name.get(LE) == 0
&& self.first_thunk.get(LE) == 0
}
}

//
// New format import descriptors pointed to by DataDirectory[ IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT ]
//
Expand Down
2 changes: 1 addition & 1 deletion src/read/pe/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<'data> ImportDescriptorIterator<'data> {
.data
.read::<pe::ImageImportDescriptor>()
.read_error("Missing PE null import descriptor")?;
if import_desc.original_first_thunk.get(LE) == 0 {
if import_desc.is_null() {
Ok(None)
} else {
Ok(Some(import_desc))
Expand Down

0 comments on commit 4db37ab

Please sign in to comment.