Last active
July 7, 2023 02:38
-
-
Save TheFlash2k/15a45723cbab870dac0478e017890fb4 to your computer and use it in GitHub Desktop.
A simple script to convert an hex to bytes based on endianess.
This file contains hidden or 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 python3 | |
import argparse | |
import struct | |
def pack_address(address, arch, byte_order): | |
_ = { 'x64' : { 'little' : '<Q', 'big' : '>Q' }, 'x86' : { 'little' : '<I', 'big' : '>Q' } } | |
return struct.pack(_[arch][byte_order], address) | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-t', '--type', choices=['little', 'big'], default='little', help='Specify little or big') | |
parser.add_argument('address', type=str, help='Address') | |
parser.add_argument('-a', '--arch', choices=['x86', 'x64'], default='x86', help='Specify x86 or x64 (default: x86)') | |
args = parser.parse_args() | |
address_packed = pack_address(int(args.address, 16), args.arch, args.type) | |
print(f'Packed address: {address_packed}') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment