Skip to content

Instantly share code, notes, and snippets.

@lorek123 lorek123/converter.py
Last active Jul 22, 2018

Embed
What would you like to do?
#! 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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.