Skip to content

Commit 57b9eb9

Browse files
authored
Fix loading ELF files without valid .dynamic section (#2502)
* Fix loading ELF files without valid .dynamic section This allows to load separate debuginfo files and access their symbols. * Update CHANGELOG
1 parent b2d56fa commit 57b9eb9

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ The table below shows which release corresponds to each branch, and what date th
8686
- [#2484][2484] Allow to disable caching
8787
- [#2291][2291] Fix attaching to a gdbserver with tuple `gdb.attach(('0.0.0.0',12345))`
8888
- [#2410][2410] Add `tube.upload_manually` to upload files in chunks
89+
- [#2502][2502] Fix loading ELF files without valid .dynamic section
8990

9091
[2471]: https://github.com/Gallopsled/pwntools/pull/2471
9192
[2358]: https://github.com/Gallopsled/pwntools/pull/2358
@@ -100,6 +101,7 @@ The table below shows which release corresponds to each branch, and what date th
100101
[2484]: https://github.com/Gallopsled/pwntools/pull/2484
101102
[2291]: https://github.com/Gallopsled/pwntools/pull/2291
102103
[2410]: https://github.com/Gallopsled/pwntools/pull/2410
104+
[2502]: https://github.com/Gallopsled/pwntools/pull/2502
103105

104106
## 4.14.0 (`beta`)
105107

pwnlib/elf/elf.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from elftools.elf.constants import P_FLAGS
5353
from elftools.elf.constants import SHN_INDICES
5454
from elftools.elf.descriptions import describe_e_type
55+
from elftools.elf.dynamic import DynamicSection
5556
from elftools.elf.elffile import ELFFile
5657
from elftools.elf.enums import ENUM_GNU_PROPERTY_X86_FEATURE_1_FLAGS
5758
from elftools.elf.gnuversions import GNUVerDefSection
@@ -1607,7 +1608,7 @@ def dynamic_by_tag(self, tag):
16071608
dt = None
16081609
dynamic = self.get_section_by_name('.dynamic')
16091610

1610-
if not dynamic:
1611+
if not dynamic or not isinstance(dynamic, DynamicSection):
16111612
return None
16121613

16131614
try:

pwnlib/libcdb.py

+9
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ def search_by_hash(search_target, search_type='build_id', unstrip=True, offline_
294294
return cache
295295

296296
def _search_debuginfo_by_hash(base_url, hex_encoded_id):
297+
"""
298+
Given a hex-encoded build_id, attempt to download a matching debuginfo from the debuginfod server.
299+
300+
>>> debuginfo_file = _search_debuginfo_by_hash(DEBUGINFOD_SERVERS[0], 'd1704d25fbbb72fa95d517b883131828c0883fe9')
301+
>>> debuginfo_file is not None
302+
True
303+
>>> 'main_arena' in ELF(debuginfo_file).symbols
304+
True
305+
"""
297306
# Deferred import because it's slow
298307
import requests
299308
from six.moves import urllib

0 commit comments

Comments
 (0)