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 section names contain null bytes, cannot be retrieved by name without \x00 #551

Closed
isaac-ped opened this issue Feb 23, 2021 · 2 comments

Comments

@isaac-ped
Copy link

isaac-ped commented Feb 23, 2021

Parsing a 64-bit binary with lief 0.11.1 causes extra null bytes appended to the end of section names:

>>> import lief
>>> b = lief.parse('test.exe')
>>> [section.name for section in b.sections]
['.text\x00\x00\x00', '.data\x00\x00\x00', '.rdata\x00\x00', '.pdata\x00\x00', '.xdata\x00\x00', '.bss\x00\x00\x00\x00', '.idata\x00\x00', '.CRT\x00\x00\x00\x00', '.tls\x00\x00\x00\x00', '/4\x00\x00\x00\x00\x00\x00', '/19\x00\x00\x00\x00\x00', '/31\x00\x00\x00\x00\x00', '/45\x00\x00\x00\x00\x00', '/57\x00\x00\x00\x00\x00', '/70\x00\x00\x00\x00\x00', '/81\x00\x00\x00\x00\x00', '/92\x00\x00\x00\x00\x00']
>>> b.get_section(".text")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
lief.not_found: No such section with this name
>>> b.get_section(".text\x00\x00\x00")
<lief.PE.Section object at 0x7f880d37a4b0>

The issue occurs for both 64-bit and 32-bit binaries compiled with x86_64-w64-mingw32-gcc and i686-w64-mingw32-gcc. Binaries compiled in other ways have been tested as well and show similar results.

Lief version is 0.11.1-a6d9ea9. Happy to provide more information on request

EDIT: have verified that this issue does not occur on 0.11.0-f58605f, and seems to be a direct consequence of this change:
8d874a0

@isaac-ped isaac-ped changed the title PE section names contain null bytes, cannot be retrieved by name PE section names contain null bytes, cannot be retrieved by name without \x00 Feb 23, 2021
@romainthomas
Copy link
Member

I made a patch release for this issue

@isaac-ped
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants