Remove unused import
[pyelftools.git] / examples / elfclass_address_size.py
1 #-------------------------------------------------------------------------------
2 # elftools example: elfclass_address_size.py
3 #
4 # This example explores the ELF class (32 or 64-bit) and address size in each
5 # of the CUs in the DWARF information.
6 #
7 # Eli Bendersky (eliben@gmail.com)
8 # This code is in the public domain
9 #-------------------------------------------------------------------------------
10 from __future__ import print_function
11 import sys
12
13 # If pyelftools is not installed, the example can also run from the root or
14 # examples/ dir of the source distribution.
15 sys.path[0:0] = ['.', '..']
16
17 from elftools.elf.elffile import ELFFile
18
19
20 def process_file(filename):
21 with open(filename, 'rb') as f:
22 elffile = ELFFile(f)
23 # elfclass is a public attribute of ELFFile, read from its header
24 print('%s: elfclass is %s' % (filename, elffile.elfclass))
25
26 if elffile.has_dwarf_info():
27 dwarfinfo = elffile.get_dwarf_info()
28 for CU in dwarfinfo.iter_CUs():
29 # cu_offset is a public attribute of CU
30 # address_size is part of the CU header
31 print(' CU at offset 0x%x. address_size is %s' % (
32 CU.cu_offset, CU['address_size']))
33
34
35 if __name__ == '__main__':
36 for filename in sys.argv[1:]:
37 process_file(filename)
38