Eli Bendersky | c4a4c07 | 2011-09-17 15:28:28 +0300 | [diff] [blame] | 1 | # Just a script for playing around with pyelftools during testing |
| 2 | # please ignore it! |
| 3 | # |
| 4 | |
eliben | c6db4c4 | 2011-09-20 16:03:59 +0300 | [diff] [blame] | 5 | import sys, pprint |
Eli Bendersky | e0735d5 | 2011-09-08 20:12:44 +0300 | [diff] [blame] | 6 | from elftools.elf.structs import ELFStructs |
| 7 | from elftools.elf.elffile import ELFFile |
| 8 | from elftools.elf.sections import * |
| 9 | |
| 10 | # read a little-endian, 64-bit file |
| 11 | es = ELFStructs(True, 64) |
| 12 | |
eliben | 4455651 | 2011-09-19 12:54:32 +0300 | [diff] [blame] | 13 | stream = open('tests/testfiles/z.elf', 'rb') |
Eli Bendersky | e0735d5 | 2011-09-08 20:12:44 +0300 | [diff] [blame] | 14 | #stream = open('binfiles/z32.elf', 'rb') |
| 15 | |
| 16 | efile = ELFFile(stream) |
eliben | 033b44f | 2011-09-19 15:48:39 +0300 | [diff] [blame] | 17 | print efile.elfclass, efile.little_endian |
Eli Bendersky | e0735d5 | 2011-09-08 20:12:44 +0300 | [diff] [blame] | 18 | print '===> %s sections!' % efile.num_sections() |
eliben | 54e39b2 | 2011-09-19 13:10:57 +0300 | [diff] [blame] | 19 | |
eliben | 033b44f | 2011-09-19 15:48:39 +0300 | [diff] [blame] | 20 | print efile.has_dwarf_info() |
| 21 | |
eliben | ce5ec71 | 2011-09-20 10:20:32 +0300 | [diff] [blame] | 22 | dwarfinfo = efile.get_dwarf_info() |
eliben | c6db4c4 | 2011-09-20 16:03:59 +0300 | [diff] [blame] | 23 | |
eliben | a98028e | 2011-09-21 12:09:53 +0300 | [diff] [blame] | 24 | cu = dwarfinfo.get_CU(1) |
| 25 | print cu.get_top_DIE() |
| 26 | |
eliben | c6db4c4 | 2011-09-20 16:03:59 +0300 | [diff] [blame] | 27 | #~ print dwarfinfo.structs.Dwarf_abbrev_entry.parse('\x13\x01\x01\x03\x50\x04\x00\x00') |
| 28 | |
eliben | a98028e | 2011-09-21 12:09:53 +0300 | [diff] [blame] | 29 | #~ abbrevtable = dwarfinfo.get_abbrev_table(95) |
| 30 | #~ print id(abbrevtable) |
| 31 | #~ pprint.pprint(abbrevtable._abbrev_map) |
eliben | c6db4c4 | 2011-09-20 16:03:59 +0300 | [diff] [blame] | 32 | |
eliben | a98028e | 2011-09-21 12:09:53 +0300 | [diff] [blame] | 33 | #~ ab1 = abbrevtable.get_abbrev(2) |
| 34 | #~ print ab1.has_children() |
| 35 | #~ for name, form in ab1.iter_attr_specs(): |
| 36 | #~ print name, form |
| 37 | |
| 38 | #~ print dwarfinfo.get_abbrev_table(0).get_abbrev(1).has_children() |
eliben | c6db4c4 | 2011-09-20 16:03:59 +0300 | [diff] [blame] | 39 | |
| 40 | #~ for cu in dwarfinfo._CU: |
| 41 | #~ print cu, cu.header |
| 42 | |
| 43 | |
eliben | 033b44f | 2011-09-19 15:48:39 +0300 | [diff] [blame] | 44 | |
| 45 | |
| 46 | #~ print efile.get_section_by_name('.debug_info').name |
eliben | 54e39b2 | 2011-09-19 13:10:57 +0300 | [diff] [blame] | 47 | |
| 48 | #~ print '===> %s segments!' % efile.num_segments() |
Eli Bendersky | e0735d5 | 2011-09-08 20:12:44 +0300 | [diff] [blame] | 49 | |
eliben | 033b44f | 2011-09-19 15:48:39 +0300 | [diff] [blame] | 50 | #~ for sec in efile.iter_sections(): |
| 51 | #~ print type(sec), sec.name |
| 52 | #~ if isinstance(sec, SymbolTableSection): |
| 53 | #~ print ' linked string table:', sec.stringtable.name |
Eli Bendersky | e0735d5 | 2011-09-08 20:12:44 +0300 | [diff] [blame] | 54 | |
eliben | 54e39b2 | 2011-09-19 13:10:57 +0300 | [diff] [blame] | 55 | #~ for seg in efile.iter_segments(): |
| 56 | #~ print type(seg), seg['p_type'], seg['p_offset'] |
Eli Bendersky | e0735d5 | 2011-09-08 20:12:44 +0300 | [diff] [blame] | 57 | |
eliben | 54e39b2 | 2011-09-19 13:10:57 +0300 | [diff] [blame] | 58 | #~ for sec in efile.iter_sections(): |
| 59 | #~ if isinstance(sec, SymbolTableSection): |
| 60 | #~ print 'symbol table "%s ~~~"' % sec.name |
| 61 | #~ for sym in sec.iter_symbols(): |
| 62 | #~ print '%-26s %s %s' % (sym.name, sym['st_info']['type'], sym['st_info']['bind']) |
Eli Bendersky | a42f82d | 2011-09-09 06:02:47 +0300 | [diff] [blame] | 63 | |