lief-project / LIEF

LIEF - Library to Instrument Executable Formats

Home Page:https://lief-project.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failing to parse section type for binary

fzakaria opened this issue · comments

Describe the bug
I've hit an issue where LIEF is failing to parse a section whereas readelf succeeds.

To Reproduce

❯ python
Python 3.11.7 (main, Dec  8 2023, 14:22:46) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lief
>>> b = lief.parse("/tmp/tmp.23QwTfoAMF/usr/lib/x86_64-linux-gnu/libBrokenLocale.so.1")
>>> b.sections
<lief._lief.ELF.Binary.it_sections object at 0x7ffa5a0134e0>
>>> print(section.type) for section in b.sections
  File "<stdin>", line 1
    print(section.type) for section in b.sections
                        ^^^
SyntaxError: invalid syntax
>>> [print(section.type) for section in b.sections]
lief._lief.ELF.SECTION_TYPES.NULL
lief._lief.ELF.SECTION_TYPES.NOTE
lief._lief.ELF.SECTION_TYPES.NOTE
lief._lief.ELF.SECTION_TYPES.NOTE
lief._lief.ELF.SECTION_TYPES.HASH
lief._lief.ELF.SECTION_TYPES.GNU_HASH
lief._lief.ELF.SECTION_TYPES.DYNSYM
lief._lief.ELF.SECTION_TYPES.STRTAB
lief._lief.ELF.SECTION_TYPES.HIOS
lief._lief.ELF.SECTION_TYPES.GNU_VERDEF
lief._lief.ELF.SECTION_TYPES.GNU_VERNEED
lief._lief.ELF.SECTION_TYPES.RELA
lief._lief.ELF.SECTION_TYPES.RELA
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
RuntimeError: nb_enum: could not find entry!

Expected behavior
I expect the type to exist.

It's failing on .relr.dyn but readelf has the type as RELR

❯ readelf -S /tmp/tmp.23QwTfoAMF/usr/lib/x86_64-linux-gnu/libBrokenLocale.so.1 | grep .relr.dyn -A2 -B2
  [12] .rela.plt         RELA             0000000000000638  00000638
       0000000000000030  0000000000000018  AI       6    26     8
  [13] .relr.dyn         RELR             0000000000000668  00000668
       0000000000000018  0000000000000008   A       0     0     8
  [14] .init             PROGBITS         0000000000001000  00001000

Environment (please complete the following information):

  • System and Version: Debian
  • Target format: ELF
  • LIEF commit version: python -c "import lief;print(lief.__version__)" or the one from LIEF/config.h
❯ python -c "import lief;print(lief.__version__)"
0.14.1-bae887e0

If you want to get the file I ran it on:

# this should be debian:stable-20240211
$ docker create debian@sha256:d4f0a2e37df4ed912e2fe07786ac8d2f9979d8546c8375149406aa260e45d938
287348850f0e20eaf4ac656bb6087228db4eba930f27fbc31ea8d4caacbbea13

$ docker export 287348850f0e20eaf4ac656bb6087228db4eba930f27fbc31ea8d4caacbbea13 | tar -C "$TEMP_DIR" -xf -

You should find the file $TEMP_DIR/usr/lib/x86_64-linux-gnu/libBrokenLocale.so.1

I'm actually hitting this on a lot of files in this distribution -- even libc.so.6

Processing /tmp/tmp.cz1br9MQKD/usr/lib/x86_64-linux-gnu/libc.so.6 with sqlelf
2024-02-29 19:30:40,937 WARNING  [elf.py:264] Failed to parse section: .relr.dyn (/tmp/tmp.cz1br9MQKD/usr/lib/x86_64-linux-gnu/libc.so.6)

Hi @fzakaria as mentioned in the changelog, it implemented in the master branch (but not in 0.14.1)

Ah okay thanks ; I haven't figured out using pip how to upgrade from master branch.

pip install --index-url https://lief.s3-website.fr-par.scw.cloud/latest lief==0.15.0.dev0 :)

Ah great!
Now I remember my other issue -- pyproject.toml doesn't let me specify custom index-url..
I have to research more but that's on me.
Thanks.