1#!/usr/bin/env python3
2
3import subprocess as sp
4
5def main(args):
6    with open(args.disk, 'rb') as f:
7        f.seek(args.block * args.block_size)
8        block = (f.read(args.block_size)
9            .ljust(args.block_size, b'\xff'))
10
11    # what did you expect?
12    print("%-8s  %-s" % ('off', 'data'))
13    return sp.run(['xxd', '-g1', '-'], input=block).returncode
14
15if __name__ == "__main__":
16    import argparse
17    import sys
18    parser = argparse.ArgumentParser(
19        description="Hex dump a specific block in a disk.")
20    parser.add_argument('disk',
21        help="File representing the block device.")
22    parser.add_argument('block_size', type=lambda x: int(x, 0),
23        help="Size of a block in bytes.")
24    parser.add_argument('block', type=lambda x: int(x, 0),
25        help="Address of block to dump.")
26    sys.exit(main(parser.parse_args()))
27