Fix formatting of some dynamic tag fields to match readelf
[pyelftools.git] / scripts / readelf.py
index 29efb7fa42944e7faecaf141fc5bfdede25b9084..c1ed3fc8d2146bd1610b7366b64d76436f7b3464 100755 (executable)
@@ -288,18 +288,15 @@ class ReadElf(object):
     def display_dynamic_tags(self):
         """ Display the dynamic tags contained in the file
         """
-        has_dynamic_section = False
         for section in self.elffile.iter_sections():
             if not isinstance(section, DynamicSection):
                 continue
 
-            has_relocation_sections = True
             self._emitline("\nDynamic section at offset %s contains %s entries:" % (
                 self._format_hex(section['sh_offset']),
                 section.num_tags()))
             self._emitline("  Tag        Type                         Name/Value")
 
-            hexwidth = 8 if self.elffile.elfclass == 32 else 16
             padding = 20 + (8 if self.elffile.elfclass == 32 else 0)
             for tag in section.iter_tags():
                 if tag.entry.d_tag == 'DT_NEEDED':
@@ -308,10 +305,13 @@ class ReadElf(object):
                     parsed = 'Library rpath: [%s]' % tag.rpath
                 elif tag.entry.d_tag == 'DT_RUNPATH':
                     parsed = 'Library runpath: [%s]' % tag.runpath
+                elif tag.entry.d_tag == 'DT_SONAME':
+                    parsed = 'Library soname: [%s]' % tag.soname
                 elif (tag.entry.d_tag.endswith('SZ') or
                       tag.entry.d_tag.endswith('ENT')):
                     parsed = '%i (bytes)' % tag['d_val']
-                elif tag.entry.d_tag.endswith('NUM'):
+                elif (tag.entry.d_tag.endswith('NUM') or
+                      tag.entry.d_tag.endswith('COUNT')):
                     parsed = '%i' % tag['d_val']
                 elif tag.entry.d_tag == 'DT_PLTREL':
                     s = describe_dyn_tag(tag.entry.d_val)
@@ -323,7 +323,7 @@ class ReadElf(object):
 
                 self._emitline(" %s %-*s %s" % (
                     self._format_hex(ENUM_D_TAG.get(tag.entry.d_tag, tag.entry.d_tag),
-                        fieldsize=hexwidth, lead0x=True),
+                        fullhex=True, lead0x=True),
                     padding,
                     '(%s)' % (tag.entry.d_tag[3:],),
                     parsed))