hasherezade / bearparser

Portable Executable parsing library (from PE-bear)

Home Page:https://hasherezade.github.io/bearparser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in mapping Raw Size to Virtual Size (when Virtual Size is smaller)

hasherezade opened this issue · comments

Test cases:

1:
sample1

2:
sample2

Both samples have Virtual Size smaller than the Raw Size. It means not the whole Raw Size is going to be mapped.
However, Bearparser mistakenly uses the Raw Size as defined in the headers, over the Virtual Size. This leads to further errors in interpretation of the addresses.

What is really mapped in memory?

Example: cfccf5e157c00dc7104a750b2f9a8fc00fd323507277e8d616536c9084dc7586

This sample has Virtual Size defined as: 24B5 and Raw Size defined as 9400.
What is really mapped in memory is not exactly the Virtual Size, but the Virtual Size rounded up to File Alignment:

real_mapped

So, 24B5 rounded up to the File Alignment is 3000. We can make an experiment by appending a test string at the end of the section in the raw format:

sec_end1

And this is the end of the section in memory:

sec_end_virtual1

As we can see, indeed whole 3000 bytes from the file has been mapped in this section.

Fixed:

new_mapped1

new_mapped2

The real mapped sizes are displayed.
It fixes the problem with the interpretation of addresses, and the Entry Point is validly resolved.