-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlnDsoChecksum.py
53 lines (38 loc) · 967 Bytes
/
lnDsoChecksum.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#/usr/bin/python3
import sys
import xxhash;
#
#_____________
def usage():
print("lnDsoChecksum : Add a checksum to the fw to check its integrity");
print("\tlnDsoChecksum.py intput_bin_file checksumed_bin_file\n");
#
#_____________
def write32(f,v):
n_byte = v.to_bytes(4,byteorder='little')
f.write(n_byte)
#
#_____________
if(len(sys.argv)!=3):
usage();
exit(-1);
infile=sys.argv[1];
outfile=sys.argv[2];
print("lnDsoChecksum: checksuming %s => %s " %(infile,outfile))
print("Reading file..")
file=open(infile,"rb")
content=file.read(-1)
file.close();
binSize=len(content)
print("%d bytes read " % (binSize))
binSize-=4*4 # Skip 4 first words = MSP / Reset / size / xxhash
payload = content[16:]
lnHash=xxhash.xxh32(payload,0x100).intdigest()
print("digest %x " % (lnHash))
result=open(outfile,"wb")
result.write(content[0:8])
write32(result,binSize)
write32(result,lnHash)
result.write(payload)
result.close()
print("Done")