prints ELF header correctly
authorEli Bendersky <eliben@gmail.com>
Fri, 9 Sep 2011 07:05:57 +0000 (10:05 +0300)
committerEli Bendersky <eliben@gmail.com>
Fri, 9 Sep 2011 07:05:57 +0000 (10:05 +0300)
scripts/readelf.py

index 96fae3069c1fae86b0d79da9608b6606511ea798..44b77989be335c9efe37a77bcb10c40664a898be 100644 (file)
@@ -64,12 +64,40 @@ class ReadElf(object):
                 describe_e_machine(header['e_machine']))
         self._emitline('  Version:                           %s' %
                 describe_e_version_numeric(header['e_version']))
+        self._emitline('  Entry point address:               %s' % 
+                self._format_addr(header['e_entry']))
+        self._emit('  Start of program headers           %s' % 
+                header['e_phoff'])
+        self._emitline(' (bytes into file)')
+        self._emit('  Start of section headers           %s' % 
+                header['e_shoff'])
+        self._emitline(' (bytes into file)')
+        self._emitline('  Flags:                             %s' % 
+                self._format_addr(header['e_flags']))
+        self._emitline('  Size of this header:               %s (bytes)' %
+                header['e_ehsize'])
+        self._emitline('  Size of program headers:           %s (bytes)' %
+                header['e_phentsize'])
+        self._emitline('  Number of program headers:         %s' %
+                header['e_phnum'])
+        self._emitline('  Size of section headers:           %s (bytes)' %
+                header['e_shentsize'])
+        self._emitline('  Number of section headers:         %s' %
+                header['e_shnum'])
+        self._emitline('  Section header string table index: %s' %
+                header['e_shstrndx'])
 
+
+    def _format_addr(self, addr):
+        """ Format an address into a string
+        """
+        return '0x%x' % addr
+        
     def _emit(self, s):
         """ Emit an object to output
         """
         self.output.write(str(s))
-        
+
     def _emitline(self, s):
         """ Emit an object to output, followed by a newline
         """