Welcome, guest | Sign In | My Account | Store | Cart

Just another hex dumper written in one of our favorite languages ...

Python, 26 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import sys

PRINT = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abc\
defghijklmnopqrstuvwxyz{|}~'

def main():
    try:
        data = open(sys.argv[1], 'rb')
        for number in xrange(0, os.path.getsize(sys.argv[1]), 16):
            part = data.read(16)
            sys.stdout.write('%08X | %s | %s\n' % (number,
                                                   hexit(part).ljust(47),
                                                   clean(part)))
        data.close()
    except:
        sys.stdout.write('Usage: %s <filename>' % os.path.basename(sys.argv[0]))

def hexit(string):
    return ' '.join('%02X' % ord(c) for c in string)

def clean(string):
    return ''.join(c in PRINT and c or '.' for c in string)

if __name__ == '__main__':
    main()

You may find it helpful to pipe the output to the "more" utility.