1 #-------------------------------------------------------------------------------
2 # elftools example: elfclass_address_size.py
4 # This example explores the ELF class (32 or 64-bit) and address size in each
5 # of the CUs in the DWARF information.
7 # Eli Bendersky (eliben@gmail.com)
8 # This code is in the public domain
9 #-------------------------------------------------------------------------------
10 from __future__
import print_function
12 from elftools
.elf
.elffile
import ELFFile
15 def process_file(filename
):
16 with
open(filename
) as f
:
18 # elfclass is a public attribute of ELFFile, read from its header
19 print('%s: elfclass is %s' % (filename
, elffile
.elfclass
))
21 if elffile
.has_dwarf_info():
22 dwarfinfo
= elffile
.get_dwarf_info()
23 for CU
in dwarfinfo
.iter_CUs():
24 # cu_offset is a public attribute of CU
25 # address_size is part of the CU header
26 print(' CU at offset 0x%x. address_size is %s' % (
27 CU
.cu_offset
, CU
['address_size']))
30 if __name__
== '__main__':
31 for filename
in sys
.argv
[1:]:
32 process_file(filename
)