import os import can import struct from scripts.base.base import Base class SoftwareUpdateScript(Base): def __init__(self): super().__init__() def _verify_signature(self): pass def _verify_key(self): pass 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 # 3. Read XML file for to find the packages to update # 4. Decrypt the content # 5. Send the data to bootloader # 6. Wait for the bootloader to ack/nack or timeout after 3000 ms # 7. Send the entire file # 8. Show progress 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()