Skip to content

Commit

Permalink
pe.imports: ignore malformed imports in ParseMode::Permissive
Browse files Browse the repository at this point in the history
  • Loading branch information
ideeockus committed Jan 9, 2025
1 parent 9c59d67 commit 91b6b62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/pe/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::pe::options;
use crate::pe::section_table;
use crate::pe::utils;

use crate::pe::options::ParseMode;
use log::{debug, warn};

pub const IMPORT_BY_ORDINAL_32: u32 = 0x8000_0000;
Expand Down Expand Up @@ -361,15 +362,26 @@ impl<'a> ImportData<'a> {
if import_directory_entry.is_null() || !import_directory_entry.is_possibly_valid() {
break;
} else {
let entry = SyntheticImportDirectoryEntry::parse_with_opts::<T>(
let entry_result = SyntheticImportDirectoryEntry::parse_with_opts::<T>(
bytes,
import_directory_entry,
sections,
file_alignment,
opts,
)?;
debug!("entry {:#?} at {:#x}", entry, offset);
import_data.push(entry);
);
match entry_result {
Ok(entry) => {
debug!("entry {entry:#?}");
import_data.push(entry);
}
Err(err) if matches!(opts.parse_mode, ParseMode::Permissive) => {
warn!("Failed to parse import data: {err:?}");
continue;
}
Err(err) => {
return Err(err);
}
}
}
}
debug!("finished ImportData");
Expand Down
5 changes: 5 additions & 0 deletions src/pe/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ impl ParseOptions {
parse_mode: ParseMode::Strict,
}
}

pub fn with_parse_mode(mut self, parse_mode: ParseMode) -> Self {
self.parse_mode = parse_mode;
self
}
}

0 comments on commit 91b6b62

Please sign in to comment.