"""Replace one file's contents inside a FAT16 image, and scrub free space. Used on the CF card's boot partition (boot.fat). The kernel image is never moved: only the named file's cluster chain is rewritten, so BooSt finds nBkProOs.img exactly where it always did. Every cluster no live file owns is zeroed, and deleted directory entries are wiped, which removes the remnants of the LX NAND script that was deleted from this partition on 29 Sep 2026. python3 fatpatch.py boot.fat README.TXT newcontent.txt """ import struct, sys img, target, src = sys.argv[1], sys.argv[2].upper(), sys.argv[3] d = bytearray(open(img, 'rb').read()) new = open(src, 'rb').read() bps = struct.unpack('> 1)) + b) & 0xFF return s lfn_wiped = 0; pend = [] for i in range(rootents): o = root + i * 32 if d[o] == 0: break if d[o] == 0xE5: pend = []; continue if d[o+11] == 0x0F: pend.append(o); continue for q in pend: if d[q+13] != _sum(bytes(d[o:o+11])): d[q:q+32] = b'\xE5' + b'\0' * 31; lfn_wiped += 1 pend = [] entry = None; live = set() for i in range(rootents): o = root + i * 32; e = d[o:o+32] if e[0] == 0: break if e[0] == 0xE5: d[o:o+32] = b'\xE5' + b'\0' * 31 # wipe deleted entry continue if e[11] == 0x0F or e[11] & 0x08: continue name = e[0:8].decode().strip() + '.' + e[8:11].decode().strip() c = struct.unpack('