"""Scrub build-host paths from shipped binary/text artifacts (NEFF payloads, compile logs). NEFF = 1024-byte header + tar(.gz) payload. Paths like /home/ubuntu/nkb/dataset/... are rewritten to /nkb/dataset/... inside every payload member; the header data_size (offset 16) and payload hash (offset 172; md5 when pkg_version == 2, else sha256) are rewritten so the runtime accepts it. Compile logs (*.log-neuron-cc.txt) are rewritten in place. python tools/scrub_paths.py dataset [--check] """ import hashlib, io, os, re, struct, sys, tarfile PAT = re.compile(rb"/(?:home|local/home|Users)/[^\s\x00\"']*?/(?:nkb|nki_kernel_bench)/") # any build-host checkout path def REPL(m): # SAME LENGTH: NEFF debug-info members are binary with length-prefixed strings return b"/" * (len(m.group(0)) - 4) + b"nkb/" TXT = re.compile(r"/(?:home|local/home|Users)/[^\s\"']*?/(?:nkb|nki_kernel_bench)/") def scrub_neff(p, check): raw = open(p, "rb").read() head, payload = raw[:1024], raw[1024:] if not PAT.search(payload) and b"\x1f\x8b" != payload[:2]: return False gz = payload[:2] == b"\x1f\x8b" src = tarfile.open(fileobj=io.BytesIO(payload), mode="r:gz" if gz else "r:") members = [(m, src.extractfile(m).read() if m.isfile() else None) for m in src.getmembers()] if not any(d is not None and PAT.search(d) for _, d in members): return False if check: return True out = io.BytesIO() with tarfile.open(fileobj=out, mode="w:gz" if gz else "w") as dst: for m, d in members: if d is not None: d = PAT.sub(REPL, d); m.size = len(d) dst.addfile(m, io.BytesIO(d)) else: dst.addfile(m) import hashlib, struct new = out.getvalue() pkg = struct.unpack("