-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeepmage-hexdump
executable file
·34 lines (29 loc) · 1.22 KB
/
deepmage-hexdump
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
27
28
29
30
31
32
33
34
#!/usr/bin/env python3
#######################
# This file is a part #
# of the deepmage #
# project, released #
# under the GNU GPL 3 #
# license #
# (see the COPYING #
# file for details) #
#######################
import argparse
# noinspection PyUnresolvedReferences
import hy
import libdeepmage.bitstream_reader
from libdeepmage.deepmage import hex_representation, bit_representation
parser = argparse.ArgumentParser("deepmage-hexdump")
parser.add_argument('filename', metavar='file', type=str, help='Path to a file to edit')
parser.add_argument('-w', '--wordsize', metavar='wordsize', type=int, default=8,
help='Size of words (in bits)')
parser.add_argument('-c', '--cols', metavar='cols', type=int, default=16)
parser.add_argument('-b', '--bits', action='store_true')
args = parser.parse_args()
representation = bit_representation if args.bits else hex_representation
with open(args.filename, 'rb') as f:
reader = libdeepmage.bitstream_reader.FileReader(f, 1024)
reader.set_wordsize(args.wordsize)
for i in range(0, reader.get_wordcount(), args.cols):
view = reader.get_view(i, args.cols)
print(''.join([representation(view[j]) + ' ' for j in range(args.cols)]))