annotate python/readelf.py @ 178:c694ec551f34

Added lex yacc test scripts
author Windel Bouwman
date Sat, 04 May 2013 12:07:17 +0200
parents bbf4c9b138d4
children
rev   line source
118
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
1 #!/usr/bin/python
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
2
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
3 import elffile, argparse
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
4
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
5 parser = argparse.ArgumentParser()
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
6 parser.add_argument('file', type=argparse.FileType('rb'))
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
7 parser.add_argument('-l', action='store_const', const=True, default=False, dest='list_program_headers')
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
8
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
9 args = parser.parse_args()
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
10 print(args)
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
11 ef = elffile.ElfFile(args.file)
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
12 print(ef)
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
13
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
14 if args.list_program_headers:
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
15 print('program headers')
126
bbf4c9b138d4 Changes to elf reading
Windel Bouwman
parents: 118
diff changeset
16 phs = ef.parsePrograms()
bbf4c9b138d4 Changes to elf reading
Windel Bouwman
parents: 118
diff changeset
17 print(phs)
bbf4c9b138d4 Changes to elf reading
Windel Bouwman
parents: 118
diff changeset
18 for ph in phs:
bbf4c9b138d4 Changes to elf reading
Windel Bouwman
parents: 118
diff changeset
19 print('type=0x{0:X} vaddr=0x{1:X} filesz=0x{2:X}'.format(ph.p_type, ph.p_vaddr, ph.p_filesz))
118
db8aafe00d27 Added elf file read scripts
Windel Bouwman
parents:
diff changeset
20