some fixes in relocation printing. INFO STILL PRINTED ENDIAN-REVERSED -- WTF???
authorEli Bendersky <eliben@gmail.com>
Thu, 22 Sep 2011 03:37:07 +0000 (06:37 +0300)
committerEli Bendersky <eliben@gmail.com>
Thu, 22 Sep 2011 03:37:07 +0000 (06:37 +0300)
elftools/elf/structs.py
scripts/readelf.py

index 8105206a93d115d1af6ed2d4f6f05f7f0e1a36b4..a8d34976d02d0dd629865b0663354c492b57cbb6 100644 (file)
@@ -11,7 +11,7 @@ from ..construct import (
     UBInt8, UBInt16, UBInt32, UBInt64,
     ULInt8, ULInt16, ULInt32, ULInt64,
     SBInt32, SLInt32, SBInt64, SLInt64,
-    Struct, Array, Enum, Padding, BitStruct, BitField,
+    Struct, Array, Enum, Padding, BitStruct, BitField, Value,
     )
 
 from .enums import *
@@ -148,13 +148,22 @@ class ELFStructs(object):
                 Padding(24),
                 BitField('type', 8))
 
+        # Since the raw value of r_info is also needed, it's being re-computed
+        # in 'r_info_raw'
+        r_info_raw = Value('r_info_raw',
+                lambda ctx: 
+                    (ctx['r_info']['sym'] << 8 if self.elfclass == 32 else 32) +
+                    ctx['r_info']['type'])
+
         self.Elf_Rel = Struct('Elf_Rel',
             self.Elf_addr('r_offset'),
             r_info_struct,
+            r_info_raw,
         )
         self.Elf_Rela = Struct('Elf_Rela',
             self.Elf_addr('r_offset'),
             r_info_struct,
+            r_info_raw,
             self.Elf_sxword('r_addend'),
         )
 
index eb2c55037590a1eb694139b78b6fe0fba4822a8c..46caa1173b2916a5fd42d1c413a66a623fffefe5 100755 (executable)
@@ -276,9 +276,14 @@ class ReadElf(object):
 
             has_relocation_sections = True
             self._emitline("\nRelocation section '%s' at offset %s contains %s entries:" % (
-                1, 2, 3))
+                section.name,
+                self._format_hex(section['sh_offset']),
+                section.num_relocations()))
             for rel in section.iter_relocations():
-                print rel, rel.entry
+                self._emitline('%s %s' % (
+                    self._format_hex(rel['r_offset'], fullhex=True, lead0x=False),
+                    self._format_hex(rel['r_info_raw'], fullhex=True, lead0x=False)))
+                #print rel, rel.entry
 
         if not has_relocation_sections:
             self._emitline('\nThere are no relocations in this file.')