From ddeedc446859987f13af050e686e00bbe4723615 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Fri, 18 Nov 2011 05:55:06 +0200 Subject: [PATCH] add __contains__ to construct's Container. this actually fixes Relocation.is_RELA which wouldn't work otherwise. also add __repr__ and __str__ to Relocation --- elftools/construct/lib/container.py | 2 ++ elftools/elf/sections.py | 7 +++++++ z.py | 18 +++++++----------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/elftools/construct/lib/container.py b/elftools/construct/lib/container.py index 4b2f727..326ee57 100644 --- a/elftools/construct/lib/container.py +++ b/elftools/construct/lib/container.py @@ -37,6 +37,8 @@ class Container(object): if name not in d: self.__attrs__.append(name) d[name] = value + def __contains__(self, name): + return name in self.__dict__ def __getitem__(self, name): return self.__dict__[name] def __delitem__(self, name): diff --git a/elftools/elf/sections.py b/elftools/elf/sections.py index d545ec2..b30bd63 100644 --- a/elftools/elf/sections.py +++ b/elftools/elf/sections.py @@ -187,4 +187,11 @@ class Relocation(object): """ return self.entry[name] + def __repr__(self): + return '' % ( + 'RELA' if self.is_RELA() else 'REL', + self.entry) + + def __str__(self): + return self.__repr__() diff --git a/z.py b/z.py index 2cffb74..9495185 100644 --- a/z.py +++ b/z.py @@ -7,6 +7,8 @@ from elftools.elf.structs import ELFStructs from elftools.elf.elffile import ELFFile from elftools.elf.sections import * +from elftools.dwarf.dwarfrelocationmanager import DWARFRelocationManager + # read a little-endian, 64-bit file es = ELFStructs(True, 64) @@ -27,16 +29,10 @@ print cu.structs.Dwarf_dw_form['DW_FORM_strp'].parse('\x01\x00\x00\x00\x01\x00\x print 'CU header', cu.header topdie = cu.get_top_DIE() -print topdie - -#~ print 'siblings.....' - -#~ for s in c.iter_siblings(): - #~ print s - -#~ from elftools.dwarf.location_expr import DW_OP_name2opcode, DW_OP_opcode2name - -#~ print hex(DW_OP_name2opcode['DW_OP_lit14']) -#~ print DW_OP_opcode2name[0x0e] +#print topdie +dinfo_sec = efile.get_section_by_name('.debug_info') +relman = DWARFRelocationManager(efile, dinfo_sec.name, dinfo_sec['sh_offset']) +print relman._reloc_section.name, relman._reloc_section['sh_offset'] +pprint.pprint(relman._relocs) -- 2.30.2