Move checksum correction after EFFS flag removal

This commit is contained in:
Nicola Corna 2017-01-04 10:52:18 +01:00
parent b149111c78
commit 236faf7da9

View file

@ -204,6 +204,17 @@ else:
f.seek(me_start + 0x24, 0)
f.write(pack("<I", flags))
f.seek(me_start, 0)
header = bytearray(f.read(0x30))
checksum = (0x100 - (sum(header) - header[0x1b]) & 0xff) & 0xff
print("Correcting checksum (0x{:02x})...".format(checksum))
# The checksum is just the two's complement of the sum of the first
# 0x30 bytes (except for 0x1b, the checksum itself). In other words,
# the sum of the first 0x30 bytes must be always 0x00.
f.seek(me_start + 0x1b, 0)
f.write(pack("B", checksum))
f.seek(ftpr_offset, 0)
if version[0] < 11 and f.read(4) != b"$CPD":
@ -256,16 +267,5 @@ else:
else:
print("Modules removal in ME v11 or greater is not yet supported")
f.seek(me_start, 0)
header = bytearray(f.read(0x30))
checksum = (0x100 - (sum(header) - header[0x1b]) & 0xff) & 0xff
print("Correcting checksum (0x{:02x})...".format(checksum))
# The checksum is just the two's complement of the sum of the first
# 0x30 bytes (except for 0x1b, the checksum itself). In other words,
# the sum of the first 0x30 bytes must be always 0x00.
f.seek(me_start + 0x1b, 0)
f.write(pack("B", checksum))
print("Done! Good luck!")