Skip to content

Commit

Permalink
Fixed a bug where malformed PEs caused parsing to stop too early.
Browse files Browse the repository at this point in the history
  • Loading branch information
JusticeRage committed Feb 26, 2020
1 parent 7af37a0 commit 9fa4e88
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions manape/pe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,16 +630,17 @@ bool PE::_parse_directories()
return false;
}

return _parse_imports() &&
_parse_delayed_imports() &&
_parse_exports() &&
_parse_resources() &&
_parse_debug() &&
_parse_relocations() &&
_parse_tls() &&
_parse_config() &&
_parse_certificates() &&
_parse_rich_header();
_parse_imports();
_parse_delayed_imports();
_parse_exports();
_parse_resources();
_parse_debug();
_parse_relocations();
_parse_tls();
_parse_config();
_parse_certificates();
_parse_rich_header();
return true;
}

// ----------------------------------------------------------------------------
Expand All @@ -649,16 +650,16 @@ bool PE::_parse_exports()
if (!_ioh || _file_handle == nullptr) {
return false;
}
if (!_reach_directory(IMAGE_DIRECTORY_ENTRY_EXPORT)) {
return true; // No exports
}

image_export_directory ied;

// Don't overwrite the std::string at the end of the structure.
unsigned int ied_size = 9*sizeof(boost::uint32_t) + 2*sizeof(boost::uint16_t);
memset(&ied, 0, ied_size);

if (!_reach_directory(IMAGE_DIRECTORY_ENTRY_EXPORT)) {
return true; // No exports
}

if (ied_size != fread(&ied, 1, ied_size, _file_handle.get()))
{
PRINT_ERROR << "Could not read the IMAGE_EXPORT_DIRECTORY." << std::endl;
Expand Down Expand Up @@ -855,15 +856,15 @@ bool PE::_parse_tls()
if (feof(_file_handle.get()) || ferror(_file_handle.get()))
{
PRINT_ERROR << "Could not read the IMAGE_TLS_DIRECTORY." << DEBUG_INFO_INSIDEPE << std::endl;
return false;
return true; // Non-fatal
}

// Go to the offset table
unsigned int offset = _va_to_offset(tls.AddressOfCallbacks);
if (!offset || fseek(_file_handle.get(), offset, SEEK_SET))
{
PRINT_ERROR << "Could not reach the TLS callback table." << DEBUG_INFO_INSIDEPE << std::endl;
return false;
return true; // Non-fatal
}

boost::uint64_t callback_address = 0;
Expand Down Expand Up @@ -920,7 +921,7 @@ bool PE::_parse_config()
return false;
}

if (!_reach_directory(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG)) { // No TLS callbacks
if (!_reach_directory(IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG)) { // No load configuration
return true;
}

Expand Down

0 comments on commit 9fa4e88

Please sign in to comment.