summaryrefslogtreecommitdiff
path: root/scripts/scriptchecksum.py
blob: d40a12d683a4f86d81201cd820e8c243532b9ea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import struct
import sys

out = open(sys.argv[2], 'w')
sum = 0x1121
len = 0
with open(sys.argv[1], 'rb') as f:
	while True:
		byte = f.read(1)
		if not byte:
			break

		sum ^= ord(byte)
		for i in range(8):
			if(sum & 1):
				sum = (sum >> 1) ^ 0x8408
			else:
				sum >>= 1
		len += 1
	sum = ~sum & 0xFFFF
f.closed

out.write(struct.pack('<I', sum))
out.write(struct.pack('<I', 0x0200001E))
out.write(struct.pack('<I', 0x0200001E + len))
with open(sys.argv[1], 'rb') as f:
	out.write(f.read())
f.closed