MacIIROMDiskDriver/checksum.py

14 lines
306 B
Python
Raw Permalink Normal View History

2021-07-08 06:08:54 +00:00
import sys
import struct
with open(sys.argv[1], mode='rb') as file:
file.read(4) # discard first four bytes
rombin = file.read() # read rest of file
cksum = 0
2021-07-15 09:32:58 +00:00
count = 0;
2021-07-08 06:08:54 +00:00
for i in struct.unpack('>' + str(len(rombin)/2) + 'H', rombin):
2021-07-15 09:32:58 +00:00
cksum += i
count += 1
2021-07-08 06:08:54 +00:00
cksum &= 0xFFFFFFFF
print(hex(cksum))