boolean - specifies the target machine's endianness
elftype:
- string or int, either known value of E_TYPE enum defining ELF type
- (e.g. executable, dynamic library or core dump) or integral unparsed value
+ string or int, either known value of E_TYPE enum defining ELF
+ type (e.g. executable, dynamic library or core dump) or integral
+ unparsed value
header:
the complete ELF file header
# Sections that aren't found will be passed as None to DWARFInfo.
#
- section_names = ('.debug_info', '.debug_aranges', '.debug_abbrev', '.debug_str',
- '.debug_line', '.debug_frame',
+ section_names = ('.debug_info', '.debug_aranges', '.debug_abbrev',
+ '.debug_str', '.debug_line', '.debug_frame',
'.debug_loc', '.debug_ranges')
compressed = bool(self.get_section_by_name('.zdebug_info'))
if compressed:
section_names = tuple(map(lambda x: '.z' + x[1:], section_names))
- debug_info_sec_name, debug_aranges_sec_name, debug_abbrev_sec_name, debug_str_sec_name, \
- debug_line_sec_name, debug_frame_sec_name, debug_loc_sec_name, \
- debug_ranges_sec_name = section_names
+ (debug_info_sec_name, debug_aranges_sec_name, debug_abbrev_sec_name,
+ debug_str_sec_name, debug_line_sec_name, debug_frame_sec_name,
+ debug_loc_sec_name, debug_ranges_sec_name) = section_names
debug_sections = {}
for secname in section_names:
self.elfclass = elfclass
def create_basic_structs(self):
- """ Create word-size related structs and ehdr struct needed for
+ """ Create word-size related structs and ehdr struct needed for
initial determining of ELF type.
"""
if self.little_endian:
def create_advanced_structs(self, elftype=None):
""" Create all ELF structs except the ehdr. They may possibly depend
- on provided #elftype previously parsed from ehdr. """
+ on provided #elftype previously parsed from ehdr.
+ """
self._create_phdr()
self._create_shdr()
self._create_sym()
self.Elf_Nhdr = Struct('Elf_Nhdr',
self.Elf_word('n_namesz'),
self.Elf_word('n_descsz'),
- Enum(self.Elf_word('n_type'), **(ENUM_NOTE_N_TYPE if elftype != "ET_CORE" else ENUM_CORE_NOTE_N_TYPE)),
+ Enum(self.Elf_word('n_type'),
+ **(ENUM_NOTE_N_TYPE if elftype != "ET_CORE"
+ else ENUM_CORE_NOTE_N_TYPE)),
)
# A process psinfo structure according to
# http://elixir.free-electrons.com/linux/v2.6.35/source/include/linux/elfcore.h#L84
- if self.elfclass == 32:
+ if self.elfclass == 32:
self.Elf_Prpsinfo = Struct('Elf_Prpsinfo',
self.Elf_byte('pr_state'),
String('pr_sname', 1),
String('pr_psargs', 80),
)
-
def _create_stabs(self):
# Structure of one stabs entry, see binutils/bfd/stabs.c
# Names taken from https://sourceware.org/gdb/current/onlinedocs/stabs.html#Overview
'--debug-dump=aranges']:
if verbose: testlog.info("..option='%s'" % option)
- # TODO(zlobober): this is a dirty hack to make tests work for ELF core dump notes.
- # Making it work properly requires a pretty deep investigation of how original readelf
- # formats the output.
+ # TODO(zlobober): this is a dirty hack to make tests work for ELF core
+ # dump notes. Making it work properly requires a pretty deep
+ # investigation of how original readelf formats the output.
if "core" in filename and option == "-n":
if verbose:
testlog.warning("....will fail because corresponding part of readelf.py is not implemented yet")
# If file names are given as command-line arguments, only these files
# are taken as inputs. Otherwise, autodiscovery is performed.
- #
if len(args) > 0:
filenames = args
else:
class TestCoreNotes(unittest.TestCase):
""" This test makes sure than core dump specific
- sections are properly analyzed.
+ sections are properly analyzed.
"""
def test_core_prpsinfo(self):
- """ Test ...
- """
- with open(os.path.join('test', 'testfiles_for_unittests', 'core_linux64.elf'),
+ with open(os.path.join('test',
+ 'testfiles_for_unittests', 'core_linux64.elf'),
'rb') as f:
elf = ELFFile(f)
for segment in elf.iter_segments():
self.assertEquals(desc['pr_ppid'], 23187)
self.assertEquals(desc['pr_pgrp'], 23395)
self.assertEquals(desc['pr_sid'], 23187)
- self.assertEquals(desc['pr_fname'], b'coredump_self\x00\x00\x00')
- self.assertEquals(desc['pr_psargs'], b'./coredump_self foo bar 42 ' + b'\x00' * (80 - 27))
+ self.assertEquals(
+ desc['pr_fname'],
+ b'coredump_self\x00\x00\x00')
+ self.assertEquals(
+ desc['pr_psargs'],
+ b'./coredump_self foo bar 42 ' + b'\x00' * (80 - 27))