The previous article mentioned the error reminders for exFAT boot checksum error, and if you need to verify that the boot checksum is correct, you need to implement the boot Checusum algorithm.
Python is used to implement this.
The boot checksum algorithm references the following:
exFAT Boot Checksum
This sector contains a repeating 32-bit checksum of the previous. The checksum calculation excludes volumeflags and Percentinuse fields in Boot sector (bytes 106, 107, 112). The checksum is repeated until the end of the sector. The number of repetitions depends on the size of the sector.
UNIT32 bootchecksum (constunsignedchardata[], intbytes)
{
UINT32 checksum = 0;
for (inti = 0; i < bytes; i++)
{
if (i = =] | |
Checksum = (checksum<<31) | (checksum>> 1) + data[i];
}
Returnchecksum;
Here need to extract to the exFAT boot sectors, you can use Winhex to obtain, through the Winhex to open the corresponding disk,copy of the first 12 sector data to the text.
Refer to the following example:
You can see one sector is the checksum of the former 0~10 sectors, which is a DWORD integer that repeats in this sector.
With the home algorithm and data, we can implement and verify the algorithm, Python code is as follows:
#!/usr/bin/python
#import os
if __name__ = = ' __main__ ':
dir = ' c:\\users\\admin\\desktop\\python_script\ \ '
file = ' ExFATCheckSum.TXT '
fd = open (dir + file, ' R ')
checksum = 0
ind = 0 for
(num,line) in Enumer Ate (FD):
if num > Break-
for-start in range (0,len), 2:
if 106==ind or 107==ind or 112==ind:< C12/>ind + + 1
continue
if start >= len (line)-2: Break
#print '%s:%d '% (line[start:start+2), int (line[start:start+2])
Checksum = Long (((checksum<<31) &0xffffffff) | ((checksum>>1) & 0xFFFFFFFF) + Long (line[start:start+2))
print ' sector:%d, byte:%d, checksum:%08x ' % (NUM, IND, CHECKSUM)
ind + + 1
print '%08x '%checksum
Experimental results refer to:
Checksum is 0xd9de1e08, consistent with one sector in the above data.
Algorithm validation OK.