Index: scripts/update_package_script/update_package.py =================================================================== diff -u -r28ee439966c2b482352f1cadd913d558fcac2a05 -rdd30a8caf586169db067d42da875a31507628e8d --- scripts/update_package_script/update_package.py (.../update_package.py) (revision 28ee439966c2b482352f1cadd913d558fcac2a05) +++ scripts/update_package_script/update_package.py (.../update_package.py) (revision dd30a8caf586169db067d42da875a31507628e8d) @@ -1,4 +1,6 @@ +import os import can +import struct from scripts.base.base import Base @@ -17,7 +19,6 @@ def _get_target_stack(self): pass - def update_software_packages(self, packages_dir: str, stack_to_update: str = None): # 1. Verify signature # 2. Verify key @@ -27,5 +28,66 @@ # 6. Wait for the bootloader to ack/nack or timeout after 3000 ms # 7. Send the entire file # 8. Show progress - pass + + signature_start_in_bytes = bytes(self.SIGNATURE_START, 'utf-8') + signature_end_in_bytes = bytes(self.SIGNATURE_END, 'utf-8') + + for file in os.listdir(packages_dir): + if file.endswith(".bin"): + signature_line = '' + xml_report_bytes = bytearray() + has_signature_been_found = False + found = 0 + with open(os.path.join(packages_dir, file), 'rb') as f: + for line in f: + if signature_start_in_bytes in line: + if signature_end_in_bytes in line: + signature_line = line[len(signature_start_in_bytes):line.find(signature_end_in_bytes)] + xml_start = line[line.find(signature_end_in_bytes) + len(signature_end_in_bytes):] + print((xml_start[0]), [hex(j) for j in xml_start], bytearray(xml_start)) + has_signature_been_found = True + a = int(xml_start[0]) + b = int(xml_start[1]) + code = (a << 8) + b + print(a, b, code) + found = 0 + for s in range(0, 0xFF): + test = ((s % 19) << 8) + (s % 23) + if code == test: + print("breaking {} {} {}".format(code, test, s)) + found = s + break + xml_list = list() + for d in range(2,len(xml_start)): + value = xml_start[d] + xml_list.append((value - found) % 256) + found += 211 + + converted_xml = ''.join(chr(c) for c in xml_list) + + print(xml_list, converted_xml.replace('\n', '')) + #test = struct.unpack('c', bytearray(xml_start[:1])) + #print(test, xml_list[:].decode('utf-8')) + else: + pass + # TODO fill up + elif has_signature_been_found: + xml_start = line + xml_list = list() + for d in xml_start: + value = d + xml_list.append((value - found) % 256) + found += 211 + + converted_xml = ''.join(chr(c) for c in xml_list) + + print(converted_xml.replace('\n', '')) + + if "" in converted_xml: + print(line) + f.close() + + + + \ No newline at end of file