Skip to content

Commit

Permalink
Merge pull request #596 from avast/version-info-exotic
Browse files Browse the repository at this point in the history
Fixed reading of version info which has non-matching length of struct and strings
  • Loading branch information
metthal authored Jun 23, 2019
2 parents 157fea0 + e975e6e commit aaba790
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/fileformat/file_format/pe/pe_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,12 +1453,17 @@ void PeFormat::loadResourceNodes(std::vector<const PeLib::ResourceChild*> &nodes
void PeFormat::loadResources()
{
size_t iconGroupIDcounter = 0;
unsigned long long rva = 0, size = 0;
unsigned long long rva = 0, size = 0, imageBase = 0;
if(!getDataDirectoryRelative(PELIB_IMAGE_DIRECTORY_ENTRY_RESOURCE, rva, size))
{
return;
}

if(!getImageBaseAddress(imageBase))
{
return;
}

std::vector<const ResourceChild*> nodes;
std::vector<std::size_t> levels;
if(!getResourceNodes(nodes, levels))
Expand Down Expand Up @@ -1553,7 +1558,9 @@ void PeFormat::loadResources()
resource->setNameId(nameChild->getOffsetToName());
}

resource->setOffset(lanLeaf->getOffsetToData() - rva + formatParser->getResourceDirectoryOffset());
unsigned long long dataOffset;
getOffsetFromAddress(dataOffset, imageBase + lanLeaf->getOffsetToData());
resource->setOffset(dataOffset);
resource->setSizeInFile(lanLeaf->getSize());
resource->setLanguage(lanChild->getName());
resource->invalidateLanguageId();
Expand Down
9 changes: 2 additions & 7 deletions src/fileformat/types/resource_table/resource_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,7 @@ bool ResourceTable::parseVarString(const std::vector<std::uint8_t> &bytes, std::
return false;
}

std::size_t targetOffset = origOffset + str.length;

std::size_t targetOffset = retdec::utils::alignUp(origOffset + str.length, sizeof(std::uint32_t));
if (offset > targetOffset)
{
return false;
Expand All @@ -705,7 +704,6 @@ bool ResourceTable::parseVarString(const std::vector<std::uint8_t> &bytes, std::
std::string name = retdec::utils::unicodeToAscii(&bytes.data()[offset], nToRead, nRead);
offset += nRead;
offset = retdec::utils::alignUp(offset, sizeof(std::uint32_t));

if (offset > targetOffset)
{
return false;
Expand All @@ -714,12 +712,9 @@ bool ResourceTable::parseVarString(const std::vector<std::uint8_t> &bytes, std::
nToRead = targetOffset - offset;
std::string value;
if (nToRead > 0)
{
value = retdec::utils::unicodeToAscii(&bytes.data()[offset], nToRead, nRead);
offset += nRead;
offset = retdec::utils::alignUp(offset, sizeof(std::uint32_t));
}

offset = targetOffset;
strings.emplace_back(std::make_pair(name, value));
return true;
}
Expand Down

0 comments on commit aaba790

Please sign in to comment.