Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions elftools/elf/descriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def describe_ei_data(x):


def describe_ei_version(x):
s = '%d' % ENUM_E_VERSION[x]
s = str(ENUM_E_VERSION.get(x, f"{x} <unknown>"))
if x == 'EV_CURRENT':
s += ' (current)'
return s
Expand All @@ -41,9 +41,10 @@ def describe_e_type(x, elffile=None):
if elffile is not None and x == 'ET_DYN':
# Detect whether this is a normal SO or a PIE executable
dynamic = elffile.get_section_by_name('.dynamic')
for t in dynamic.iter_tags('DT_FLAGS_1'):
if t.entry.d_val & ENUM_DT_FLAGS_1['DF_1_PIE']:
return 'DYN (Position-Independent Executable file)'
if dynamic:
for t in dynamic.iter_tags('DT_FLAGS_1'):
if t.entry.d_val & ENUM_DT_FLAGS_1['DF_1_PIE']:
return 'DYN (Position-Independent Executable file)'
return _DESCR_E_TYPE.get(x, _unknown)


Expand All @@ -52,7 +53,7 @@ def describe_e_machine(x):


def describe_e_version_numeric(x):
return '0x%x' % ENUM_E_VERSION[x]
return f"{ENUM_E_VERSION.get(x, x):#x}"


def describe_p_type(x):
Expand Down
9 changes: 5 additions & 4 deletions elftools/elf/elffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def __init__(self, stream, stream_loader=None):
self.stream.seek(0)
self.e_ident_raw = self.stream.read(16)

self._section_header_stringtable = \
self._get_section_header_stringtable()
self._section_header_stringtable = None # Lazy load
self._section_name_map = None
self.stream_loader = stream_loader

Expand Down Expand Up @@ -693,8 +692,10 @@ def _get_section_name(self, section_header):
""" Given a section header, find this section's name in the file's
string table
"""
if self._section_header_stringtable is None:
raise ELFParseError("String Table not found")
if self._section_header_stringtable is None: # Try to lazy load
self._section_header_stringtable = self._get_section_header_stringtable()
if self._section_header_stringtable is None: # If absent (or badly malformed)
raise ELFParseError("String Table not found")

name_offset = section_header['sh_name']
return self._section_header_stringtable.get_string(name_offset)
Expand Down