add __contains__ to construct's Container. this actually fixes Relocation.is_RELA...
authorEli Bendersky <eliben@gmail.com>
Fri, 18 Nov 2011 03:55:06 +0000 (05:55 +0200)
committerEli Bendersky <eliben@gmail.com>
Fri, 18 Nov 2011 03:55:06 +0000 (05:55 +0200)
elftools/construct/lib/container.py
elftools/elf/sections.py
z.py

index 4b2f727225216e25ecdf67794af720635793a0cb..326ee57475d31fccfc6fa123f0780668420f7257 100644 (file)
@@ -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):
index d545ec2a220e42361186333ae7201968dc836ffd..b30bd63efb2db7026c28859d117c7487351d7a17 100644 (file)
@@ -187,4 +187,11 @@ class Relocation(object):
         """
         return self.entry[name]
 
+    def __repr__(self):
+        return '<Relocation (%s): %s>' % (
+                'RELA' if self.is_RELA() else 'REL',
+                self.entry)
+
+    def __str__(self):
+        return self.__repr__()
 
diff --git a/z.py b/z.py
index 2cffb7445053b2da81c32f937943208ba2150292..94951852fbd906e35379320271abd28e42a2f3fc 100644 (file)
--- 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)