diff --git a/linux/build/scripts/build-inner.sh b/linux/build/scripts/build-inner.sh index 1462193..f129449 100755 --- a/linux/build/scripts/build-inner.sh +++ b/linux/build/scripts/build-inner.sh @@ -313,38 +313,36 @@ post_process_for_reproducibility() { # marker plus the filename anchors the location. echo "post-process: byte-patching Rock Ridge TF dates on /live/filesystem.squashfs" sudo --non-interactive python3 - "${iso_file}" <<'PYEOF' -import sys, struct +import sys path = sys.argv[1] TF_HDR = b'TF\x1a\x01\x0e' # "TF" length=26 ver=1 flags=0x0e NAME_TAG = b'filesystem.squashfs' # appears in the NM Rock Ridge entry +patched = 0 with open(path, 'r+b') as f: data = f.read() -# Find TF entries near a "filesystem.squashfs" NM tag. We don't trust -# any single anchor; require both within a 96-byte window so we don't -# accidentally rewrite some other TF entry that happens to be near -# the NM tag of a different file. -patched = 0 -i = 0 -while True: - j = data.find(TF_HDR, i) - if j < 0: - break - # Look for the filename within ~96 bytes after this TF header. - window = data[j:j + 96] - if NAME_TAG in window: - # Date 1 starts at j + 5; copy its 7 bytes onto Date 2 (j+12) - # and Date 3 (j+19). - creation = data[j + 5:j + 12] - if creation[3:7] != b'\x00\x00\x00\x00': # sanity: not all zeroes - # only patch if MOD or ACCESS actually differs from CREATION - if data[j + 12:j + 19] != creation or data[j + 19:j + 26] != creation: - f.seek(j + 12) - f.write(creation) - f.seek(j + 19) - f.write(creation) - patched += 1 - print(f' patched TF at offset {j} (creation={creation.hex()})') - i = j + 1 + i = 0 + while True: + j = data.find(TF_HDR, i) + if j < 0: + break + # Look for the filename within ~96 bytes after this TF header + # — anchors both ends so we don't rewrite some other file's + # TF entry that happens to be near the NM tag. + window = data[j:j + 96] + if NAME_TAG in window: + # Date 1 (CREATION) starts at j+5, 7 bytes long. + # Copy onto Date 2 (MODIFICATION, j+12) and Date 3 (ACCESS, j+19). + creation = data[j + 5:j + 12] + if creation[0] != 0: # sanity: year byte must be non-zero + if (data[j + 12:j + 19] != creation + or data[j + 19:j + 26] != creation): + f.seek(j + 12) + f.write(creation) + f.seek(j + 19) + f.write(creation) + patched += 1 + print(f' patched TF at offset {j} (creation={creation.hex()})') + i = j + 1 print(f'post-process: byte-patcher fixed {patched} TF entr{"y" if patched == 1 else "ies"}') PYEOF