⬢ DragonFlyBSD Kernel Audit
DF-3094 / msdos_patch.py
← back to finding ↓ download raw
#!/usr/bin/env python3
# DF-3094: patch BPB fatsize (offset 22, u16, FAT12/16) so FAT copy #2 lies
# beyond device EOF -> fatentry() bread error during chain extension.
import sys, struct
img = bytearray(open(sys.argv[1],'rb').read())
old = struct.unpack_from('<H', img, 22)[0]
new = 0x7FFF
struct.pack_into('<H', img, 22, new)
open(sys.argv[1],'wb').write(bytes(img))
print("fatsize %d -> %d (image %d bytes = %d sectors)" % (old, new, len(img), len(img)//512))