Last active
July 22, 2018 16:43
-
-
Save lorek123/561e4f7b5f61618029cc70672e3d7308 to your computer and use it in GitHub Desktop.
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
#! bin/env python3 | |
""" | |
BIN To JS converter by @lorek123 | |
thanks to chaosk for tips on python3 bytes related functions | |
""" | |
from argparse import ArgumentParser | |
from os.path import splitext, basename | |
def main(): | |
parser = ArgumentParser() | |
parser.add_argument("-i", "--in", dest="infile", | |
help="input file", metavar="infile", | |
default="payload.bin") | |
parser.add_argument("-o", "--out", dest="outfile", | |
help="output file", metavar="outfile", | |
default="out.js") | |
parser.add_argument("-v", "--verbose", | |
dest="verbose", default=False, | |
help="don't print converted file to stdout") | |
args = parser.parse_args() | |
with open(args.infile, "rb") as f: | |
dump = f.read() | |
with open(args.outfile, "w") as d: | |
out = ''.join(["const ", | |
splitext( | |
basename(args.infile))[0], | |
" = new Uint8Array([", | |
', '.join(f'0x{b:02X}' for b in dump), | |
"]);"]) | |
print(out, file=d) | |
if args.verbose: | |
print("Payload:") | |
print(out) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment