12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import crcmod.predefined
- import re, struct, sys
- from greaseweazle import version
- def main(argv):
- in_f = open(argv[1], "rb")
- out_f = open(argv[2], "wb")
- hw_type = int(re.match("f(\d)", argv[3]).group(1))
- in_dat = in_f.read()
- in_len = len(in_dat)
- assert (in_len & 3) == 0, "input is not longword padded"
- crc16 = crcmod.predefined.Crc('crc-ccitt-false')
- out_f.write(struct.pack("<2H", in_len + 8, hw_type))
- out_f.write(in_dat)
- crc16.update(in_dat)
- in_dat = struct.pack("<2s2BH", b'GW', version.major, version.minor, hw_type)
- out_f.write(in_dat)
- crc16.update(in_dat)
- in_dat = struct.pack(">H", crc16.crcValue)
- out_f.write(in_dat)
- if __name__ == "__main__":
- main(sys.argv)
|