erocarrera / pefile

pefile is a Python module to read and work with PE (Portable Executable) files
MIT License
1.86k stars 519 forks source link

Fails to detect files without OPTIONAL_HEADER as invalid #137

Open mountainstorm opened 8 years ago

mountainstorm commented 8 years ago

I'm fast loading PE's:

pe = PE(path, fast_load=True)

then manually loading various directories e.g.:

pe.parse_data_directories(pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_DEBUG'])

After trying over a lot of data I've found some issues where a file appears to be a PE i.e. PE() doesn't throw an exception; but when loading the directory I get an error as self doesn't have an OPTIONAL HEADER (line 2369):

dir_entry = self.OPTIONAL_HEADER.DATA_DIRECTORY[directory_index]

nyx0 commented 8 years ago

can you provide a snippet of code with a sample please?