1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- import argparse
- import binascii
- import struct
- import sys
-
- parser = argparse.ArgumentParser()
- parser.add_argument("ifile", help="Input file (binary)")
- parser.add_argument("ofile", help="Output file (assembly)")
- args = parser.parse_args()
-
- try:
- idata = open(args.ifile, "rb").read()
- except:
- sys.exit("Could not open input file '{}'".format(args.ifile))
-
- odata = idata
-
- try:
- with open(args.ofile, "w") as ofile:
- ofile.write("// ASM-ified version of: {}\n\n".format(args.ifile))
- ofile.write(".cpu cortex-m0plus\n")
- ofile.write(".thumb\n\n")
- ofile.write(".section .boot3, \"ax\"\n\n")
- for offs in range(0, len(odata), 16):
- chunk = odata[offs:min(offs + 16, len(odata))]
- ofile.write(".byte {}\n".format(", ".join("0x{:02x}".format(b) for b in chunk)))
- except:
- sys.exit("Could not open output file '{}'".format(args.ofile))
|