X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=z.py;h=02d4f3f8381b242bc022465f4ff0870be5cf747f;hb=bd1a09f92c4ecdffd45cc01b3847ddea4fb90701;hp=dd2ab54fd09876b3b3d22995d5116a0e11fb01b4;hpb=a42f82d9f08a4194002d97f066548ebf1fc0058e;p=pyelftools.git diff --git a/z.py b/z.py index dd2ab54..02d4f3f 100644 --- a/z.py +++ b/z.py @@ -1,64 +1,30 @@ -import sys +# Just a script for playing around with pyelftools during testing +# please ignore it! +# + +import sys, pprint from elftools.elf.structs import ELFStructs from elftools.elf.elffile import ELFFile from elftools.elf.sections import * -# read a little-endian, 64-bit file -es = ELFStructs(True, 64) +from elftools.elf.relocation import * -stream = open('binfiles/z.elf', 'rb') -#stream = open('binfiles/z32.elf', 'rb') -efile = ELFFile(stream) +stream = open('test/testfiles/exe_simple64.elf', 'rb') +efile = ELFFile(stream) +print 'elfclass', efile.elfclass print '===> %s sections!' % efile.num_sections() -print '===> %s segments!' % efile.num_segments() - -for sec in efile.iter_sections(): - print type(sec), sec.name - if isinstance(sec, SymbolTableSection): - print ' linked string table:', sec.stringtable.name - -for seg in efile.iter_segments(): - print seg['p_type'], seg['p_offset'] - -for sec in efile.iter_sections(): - if isinstance(sec, SymbolTableSection): - print 'symbol table "%s ~~~"' % sec.name - for sym in sec.iter_symbols(): - print '%-26s %s %s' % (sym.name, sym['st_info']['type'], sym['st_info']['bind']) - - -#~ print 'num', efile.num_sections() -#~ sec = efile.get_section(39) -#~ print sec.header -#~ print sec.name -#~ print sec['sh_type'] -#~ print map(ord, sec.data()) - -#~ print sec.stream -#~ print map(ord, efile._stringtable) - -#~ print efile.header -#~ print dir(efile) -#~ print efile['e_type'] - -#~ shtable_offset = efile['e_shoff'] -#~ strtable_section_offset = shtable_offset + efile['e_shstrndx'] * efile['e_shentsize'] - -#~ # get to the section header for the sh string table -#~ print strtable_section_offset -#~ stream.seek(strtable_section_offset) -#~ sheader = es.Elf_Shdr.parse_stream(stream) -#~ print sheader - -#~ # yay, looks correct!! -#~ stream.seek(sheader.sh_offset) -#~ buf = stream.read(sheader.sh_size) -#~ for c in buf: - #~ sys.stdout.write('%02X' % ord(c)) - +print efile.header +dinfo = efile.get_dwarf_info() +from elftools.dwarf.locationlists import LocationLists +from elftools.dwarf.descriptions import describe_DWARF_expr +llists = LocationLists(dinfo.debug_loc_sec.stream, dinfo.structs) +for loclist in llists.iter_location_lists(): + print '----> loclist!' + for li in loclist: + print li + print describe_DWARF_expr(li.loc_expr, dinfo.structs) -#~ print es.Elf_Ehdr