forked from Imagelibrary/littlefs
This seems like a more fitting name now that this script has evolved
into more of a general purpose high-level CSV tool.
Unfortunately this does conflict with the standard csv module in Python,
breaking every script that imports csv (which is most of them).
Fortunately, Python is flexible enough to let us remove the current
directory before imports with a bit of an ugly hack:
# prevent local imports
__import__('sys').path.pop(0)
These scripts are intended to be standalone anyways, so this is probably
a good pattern to adopt.
32 lines
935 B
Python
Executable File
32 lines
935 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# prevent local imports
|
|
__import__('sys').path.pop(0)
|
|
|
|
import subprocess as sp
|
|
|
|
|
|
def main(args):
|
|
with open(args.disk, 'rb') as f:
|
|
f.seek(args.block * args.block_size)
|
|
block = (f.read(args.block_size)
|
|
.ljust(args.block_size, b'\xff'))
|
|
|
|
# what did you expect?
|
|
print("%-8s %-s" % ('off', 'data'))
|
|
return sp.run(['xxd', '-g1', '-'], input=block).returncode
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
import sys
|
|
parser = argparse.ArgumentParser(
|
|
description="Hex dump a specific block in a disk.")
|
|
parser.add_argument('disk',
|
|
help="File representing the block device.")
|
|
parser.add_argument('block_size', type=lambda x: int(x, 0),
|
|
help="Size of a block in bytes.")
|
|
parser.add_argument('block', type=lambda x: int(x, 0),
|
|
help="Address of block to dump.")
|
|
sys.exit(main(parser.parse_args()))
|