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.imports: ignore malformed imports in ParseMode::Permissive #442

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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
}
}
Loading