#!/usr/bin/env python3 """Marks NTFS MFT records as deleted (clears the in-use bit) for test fixtures. Usage: ntfs-mark-deleted.py image.img path/file1 path/file2 ... Only the basename is matched (ntfscp writes files to the root directory). """ import os import struct import sys img, names = sys.argv[1], {os.path.basename(n) for n in sys.argv[2:]} f = open(img, "r+b") boot = f.read(512) bps = struct.unpack_from(" 0 else 1 << -rs f.seek(mft_lcn * bps * spc) data = f.read(rec * 4096) # Initial MFT is contiguous on small volumes count = 0 for i in range(len(data) // rec): r = bytearray(data[i * rec:(i + 1) * rec]) if r[:4] != b"FILE" or not (r[22] & 1): continue p = struct.unpack_from("