Calculate and verify checksum for RGN binary payloads.

This commit is contained in:
Markus Birth 2019-10-12 22:06:23 +02:00
parent dd682c6da1
commit 8be7833770
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A

View File

@ -2,6 +2,7 @@
# Thanks to Herbert Oppmann (herby) for all your work! # Thanks to Herbert Oppmann (herby) for all your work!
from . import devices from . import devices
from .ansi import RESET, RED, GREEN
from .chksum import ChkSum from .chksum import ChkSum
from struct import unpack from struct import unpack
@ -30,6 +31,20 @@ class RgnBin:
self.load_from_bytes(rawdata) self.load_from_bytes(rawdata)
def load_from_bytes(self, payload: bytes): def load_from_bytes(self, payload: bytes):
self.payload = payload
print(repr(payload[0:10])) print(repr(payload[0:10]))
jmp = unpack("<L", payload[0:4])[0] jmp = unpack("<L", payload[0:4])[0]
print("{:08x}".format(jmp)) print("{:08x}".format(jmp))
def __str__(self):
txt = "Binary payload, {} Bytes".format(len(self.payload))
cksum = ChkSum()
cksum.add(self.payload)
exp_byte = cksum.get_expected()
last_byte = cksum.get_last_byte()
txt += "\n - Checksum: {:02x} (expected: {:02x}) = ".format(last_byte, exp_byte)
if cksum.is_valid():
txt += GREEN + "OK" + RESET
else:
txt += RED + "INVALID" + RESET
return txt