import hashlib import struct def fix_esp32_image(file_path): with open(file_path, "rb") as f: data = bytearray(f.read()) n_segments = data[1] pos = 0x18 checksum = 0xEF for i in range(n_segments): seg_len = struct.unpack("= pos + 1 + 32: print(f"Old Hash: {data[pos + 1 : pos + 33].hex()}") print(f"New Hash: {new_hash.hex()}") data[pos + 1 : pos + 33] = new_hash with open(file_path, "wb") as f: f.write(data) print(f"Fixed {file_path}") if __name__ == "__main__": files = [ "/home/sapient/Public/03_Projects_and_Dev/Meshcore_TDECK/Ultra-TDeck-v9.2.patched.bin", "/home/sapient/Public/03_Projects_and_Dev/Meshcore_TDECK/MeshOS-TDeck-1.1.8.patched.bin", ] for f in files: fix_esp32_image(f)