[Wisp-cvs] wisp/users/dig bindump.py,NONE,1.1 elfdump.py,1.2,1.3
Status: Alpha
Brought to you by:
digg
From: <di...@us...> - 2003-04-14 22:31:27
|
Update of /cvsroot/wisp/wisp/users/dig In directory sc8-pr-cvs1:/tmp/cvs-serv10001 Modified Files: elfdump.py Added Files: bindump.py Log Message: extracted bindump.py from elfdump.py --- NEW FILE: bindump.py --- #! /usr/bin/python #### bindump.py - generic binary dumping routines # # Copyleft © 2003 by Andres Soolo (di...@us...) # This file is licensed under the GNU GPL v2. If you # don't know what that means, please do read the GPL. # #### @(#) $Id: bindump.py,v 1.1 2003/04/14 22:31:23 digg Exp $ from __future__ import nested_scopes import string def state_enum (field_name, value, dict): print '%s: %i' % (field_name, value), try: print '(' + dict[value] + ')' except: print '- INVALID' def enum_shortly (length, value, dict): try: print ('%%-%is' % length) % dict[value], except: print ('%%%ix' % length) % value, def flags_shortly (pattern, value): r = '' badp = 0 v = value for i in range(len(pattern)): if v & 1: c = pattern[-1 - i] if c == '-': badp = 1 r = c + r else: r = '-' + r v >>= 1 if v: badp = 1 if not badp: print r, else: print ('%%%ix' % len(pattern)) % value, def asciiz (all, start): stop = string.find(all, chr(0), start) if stop == -1: return all[start:] else: return all[start:stop] Index: elfdump.py =================================================================== RCS file: /cvsroot/wisp/wisp/users/dig/elfdump.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- elfdump.py 12 Apr 2003 12:06:32 -0000 1.2 +++ elfdump.py 14 Apr 2003 22:31:23 -0000 1.3 @@ -11,43 +11,11 @@ from __future__ import nested_scopes import sys -import string import struct +from bindump import * from elf import * args = sys.argv[1:] - -def state_enum (field_name, value, dict): - print '%s: %i' % (field_name, value), - try: print '(' + dict[value] + ')' - except: print '- INVALID' - -def enum_shortly (length, value, dict): - try: print ('%%-%is' % length) % dict[value], - except: print ('%%%ix' % length) % value, - -def flags_shortly (pattern, value): - r = '' - badp = 0 - v = value - for i in range(len(pattern)): - if v & 1: - c = pattern[-1 - i] - if c == '-': badp = 1 - r = c + r - else: - r = '-' + r - v >>= 1 - if v: badp = 1 - if not badp: print r, - else: print ('%%%ix' % len(pattern)) % value, - -def asciiz (all, start): - stop = string.find(all, chr(0), start) - if stop == -1: - return all[start:] - else: - return all[start:stop] if args: for filename in args: |