Last active
April 28, 2022 10:49
-
-
Save c3rb3ru5d3d53c/6d68329d5302c5541415be44c9bbfbbf to your computer and use it in GitHub Desktop.
Get File Hex Bytes at an Offset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import argparse | |
__author__ = "@c3rb3ru5d3d53c" | |
parser = argparse.ArgumentParser( | |
prog=f'bytes', | |
description='Print Bytes from File', | |
epilog=f'Author: {__author__}' | |
) | |
parser.add_argument( | |
'-i', | |
'--input', | |
type=str, | |
default=None, | |
help='Input File', | |
required=True | |
) | |
parser.add_argument( | |
'-s', | |
'--seek', | |
type=int, | |
default=None, | |
help='File Seek', | |
required=True | |
) | |
parser.add_argument( | |
'-c', | |
'--count', | |
type=int, | |
default=None, | |
help='Byte Count', | |
required=True | |
) | |
args = parser.parse_args() | |
f = open(args.input, 'rb') | |
f.seek(args.seek) | |
data = f.read(args.count) | |
s = data.hex() | |
f.close() | |
print(" ".join(s[i:i+2] for i in range(0, len(s), 2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment