Skip to content

Instantly share code, notes, and snippets.

@lorek123
Last active July 22, 2018 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorek123/561e4f7b5f61618029cc70672e3d7308 to your computer and use it in GitHub Desktop.
Save lorek123/561e4f7b5f61618029cc70672e3d7308 to your computer and use it in GitHub Desktop.
#! 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