"""Subtractive TheOpenCD 3.1 copy using pycdlib's ready ISO filesystem. Never modifies the input ISO. The allowlist is deliberately explicit; newly cleared applications require a new manifest and a newly hashed output. Run with the project .venv/bin/python, not the system interpreter. """ from pathlib import Path from datetime import datetime, timezone import hashlib import json import os import re import shutil import tarfile import pycdlib ROOT = Path(__file__).resolve().parents[1] EVIDENCE = ROOT / 'docs/research/virtual-media-2026-10-21/theopencd31-cleaned-2026-10-22' BASE_CACHE = Path('/home/nuc/.cache/svits/original-media/theopencd31-cleaned') CACHE = Path(os.environ.get('SVITS_CLEAN_CD_CACHE_DIR', str(BASE_CACHE))) ORIGINAL = Path('/tmp/svits-software-library/theopencd-3.1/TheOpenCD-3.1.iso') ORIGINAL_SHA = 'bd64d55791778fb988115947d3a8193bb352316dfd40d3ce5d7b52c519d02e20' RESEARCH = Path('/tmp/svits-cd-relay-source-audit-20261022') SOURCE_INPUTS = [ ('7z423.tar.bz2', RESEARCH / 'windows-run_2026-10-22T08-11-23.380Z/7zip-423-source', 'cdad70aa91891fc501aa27d6bd2d813cd8044ca593cbf91f327b61b65fdad210', '7-Zip 4.23, including Windows projects and DOC/7zip.nsi', 'https://sourceforge.net/projects/sevenzip/files/7-Zip/4.23/7z423.tar.bz2/download'), ('abiword-2.4.1-cleaned-source.tar.gz', BASE_CACHE / 'abiword-2.4.1-cleaned-source.tar.gz', '48826943fcc0c7065a18dff1a19762377ca4ba9e810359a4dd38626711c2ece9', 'AbiWord 2.4.1 source, including vendored libraries; unused font and compiled dictionary blobs removed with a modification manifest', 'https://old-releases.ubuntu.com/ubuntu/pool/main/a/abiword/abiword_2.4.1.orig.tar.gz'), ('notepad2-1.0.12-src.zip', Path('/tmp/svits-seven-readiness-20261022/notepad2-1012-src.zip'), '16566be7ad3eaf02242f44aa92db379f3f3d2ad81e636efb8d7795b672529191', 'Author source snapshot; external Scintilla is not included. Binary uses its separate native freeware redistribution grant.', 'https://web.archive.org/web/20050101000000id_/http://www.flos-freeware.ch/zip/np2src.zip'), ('zlib-1.2.2.tar.gz', Path('/tmp/svits-theopencd31-cleaned-20261022/zlib-1.2.2.tar.gz'), 'ebb6f4ded5d95b9c4915c60b53926e4268c4ff06079a4ee15b1714df16d61881', 'Exact zlib 1.2.2 matching the retained AbiWord zlib1.dll version resource', 'https://zlib.net/fossils/zlib-1.2.2.tar.gz'), ] def sha(path): h = hashlib.sha256() with path.open('rb') as stream: for block in iter(lambda: stream.read(1024 * 1024), b''): h.update(block) return h.hexdigest() def verified_copy(source, target, expected): if sha(source) != expected: raise ValueError(f'Input hash mismatch: {source}') if target.exists(): if sha(target) != expected: raise ValueError(f'Existing cache differs: {target}') else: shutil.copy2(source, target) def main(): EVIDENCE.mkdir(parents=True, exist_ok=True) CACHE.mkdir(parents=True, exist_ok=True) if sha(ORIGINAL) != ORIGINAL_SHA: raise ValueError('Original identity mismatch') archive = CACHE.parent / 'archive' archive.mkdir(exist_ok=True) archived = archive / 'TheOpenCD-3.1-original.iso' if not archived.exists(): os.link(ORIGINAL, archived) if sha(archived) != ORIGINAL_SHA: raise ValueError('Archived original identity mismatch') original_source = RESEARCH / 'source-payloads/pool/main/a/abiword/abiword_2.4.1.orig.tar.gz' if sha(original_source) != '93d623d5af1c919e8970884832f9ebb8ae27439fb17d7330b63fbffd32f7dec6': raise ValueError('AbiWord source identity mismatch') source_output = CACHE / 'abiword-2.4.1-cleaned-source.tar.gz' if CACHE != BASE_CACHE: verified_copy(SOURCE_INPUTS[1][1], source_output, SOURCE_INPUTS[1][2]) if not source_output.exists(): import io removed_source = [] with tarfile.open(original_source) as upstream, tarfile.open(source_output, 'w:gz') as cleaned: for member in upstream: if member.name.lower().endswith(('.ttf', '.hash')): removed_source.append(member.name) continue cleaned.addfile(member, upstream.extractfile(member) if member.isfile() else None) note = ('Modified source copy, 22 October 2026. Derived from the exact AbiWord 2.4.1 source archive.\n' 'Unused font files and compiled dictionary hashes were removed; no application source was changed.\n' 'Portable binary subset omits Dingbats.ttf, american.hash and installer/uninstaller components.\n' 'Original GPL and component notices remain. The retained zlib1.dll is 1.2.2; exact source is supplied separately.\n' 'Removed source paths:\n' + '\n'.join(removed_source) + '\n').encode() entry = tarfile.TarInfo('abiword-2.4.1/SVITS-MODIFICATIONS.txt') entry.size = len(note) cleaned.addfile(entry, io.BytesIO(note)) (EVIDENCE / 'removed-source-data.json').write_text(json.dumps(removed_source, indent=2) + '\n') tree = CACHE / 'tree' if tree.exists(): if (CACHE / 'OpenCD31-cleaned-windows.iso').exists(): raise ValueError('A completed output exists; use a new evidence revision') shutil.rmtree(tree) tree.mkdir() original = pycdlib.PyCdlib() original.open(str(ORIGINAL)) retained = [] deleted = [] portable = RESEARCH / 'windows-extracted/notepad2/Notepad2_Install/app' allowed_files = {'/programs/7zip/7zipSetup.exe', '/disctree/en/about.html', '/disctree/img/sys/pg-logo.png'} for directory, _, names in original.walk(joliet_path='/'): for name in names: path = directory.rstrip('/') + '/' + name record = original.get_record(joliet_path=path) if path in allowed_files: target = tree / path.removeprefix('/') target.parent.mkdir(parents=True, exist_ok=True) original.get_file_from_iso(str(target), joliet_path=path) retained.append({'originalPath': path, 'outputPath': path, 'bytes': target.stat().st_size, 'sha256': sha(target), 'change': 'unchanged'}) else: if path.startswith('/programs/sokoban/'): reason = 'Removed entire game: actual du Peloux level data has non-commercial/notification terms.' elif path.startswith('/programs/pdfcreator/'): reason = 'Removed entire installer: AFPL monitor and MS/Adobe redistributable grants not closed.' elif path.startswith('/programs/notepad2/'): reason = 'Removed installer wrapper; exact embedded portable EXE and native notice retained.' elif path.startswith('/programs/abiword/'): reason = 'Removed installer wrapper and unreviewed Dingbats font/compiled dictionary; exact embedded portable application files retained.' elif path.startswith('/programs/'): reason = 'Removed entire application in this revision: exact nested runtime/source/data review not complete; no assertion of a general prohibition.' elif path.startswith(('/casper/', '/pool/', '/dists/', '/install/', '/isolinux/', '/preseed/', '/.disk/')) or path == '/ubuntu': reason = 'Removed Ubuntu boot/live subsystem as a whole; this cleaned copy is the Windows application subset.' elif path.startswith('/bin/') or path in ['/start.exe', '/start.ini', '/start.bmp', '/autorun.inf']: reason = 'Removed original launcher and autorun: exact helper/Gecko source mapping not closed; use Explorer.' else: reason = 'Removed supplementary content/menu references outside the retained, reviewed Windows subset.' deleted.append({'originalPath': path, 'bytes': record.data_length, 'reason': reason}) for filename in ['Notepad2.exe', 'Notepad2.txt']: source = portable / filename target = tree / 'programs/notepad2' / filename target.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(source, target) retained.append({'originalPath': '/programs/notepad2/Notepad2_Install.exe!app/' + filename, 'outputPath': '/programs/notepad2/' + filename, 'bytes': target.stat().st_size, 'sha256': sha(target), 'change': 'exact embedded bytes extracted; wrapper removed'}) abiword = RESEARCH / 'windows-extracted/abiword/AbiwordSetup' for source in sorted(p for p in abiword.rglob('*') if p.is_file()): rel = source.relative_to(abiword) if rel.parts[0] != 'AbiWord' and rel.as_posix() not in ['copying.txt', 'readme.txt', 'dictionary/ispell_dictionary_list.xml']: continue target = tree / 'programs/abiword' / rel target.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(source, target) retained.append({'originalPath': '/programs/abiword/AbiwordSetup.exe!' + rel.as_posix(), 'outputPath': '/programs/abiword/' + rel.as_posix(), 'bytes': source.stat().st_size, 'sha256': sha(source), 'change': 'exact embedded bytes extracted; installer, font and dictionary removed'}) original.close() sources = [] for filename, source, expected, components, url in SOURCE_INPUTS: expected = expected or sha(source) target = CACHE / filename verified_copy(source, target, expected) (tree / 'sources').mkdir(exist_ok=True) os.link(target, tree / 'sources' / filename) sources.append({'filename': filename, 'localFile': str(target), 'researchLocalFile': str(source), 'bytes': target.stat().st_size, 'sha256': expected, 'components': components, 'originURL': url}) license_dir = tree / 'notices' license_dir.mkdir() t = tarfile.open(SOURCE_INPUTS[0][1]) (license_dir / 'LGPL-2.1.txt').write_bytes(t.extractfile('DOC/copying.txt').read()) t.close() t = tarfile.open(original_source) member = next(m for m in t.getmembers() if m.name == 'abiword-2.4.1/abi/COPYING') (license_dir / 'GPL-2.0.txt').write_bytes(t.extractfile(member).read()) t.close() shutil.copy2(portable / 'Notepad2.txt', license_dir / 'Notepad2-native-notice.txt') scintilla_notice = EVIDENCE / 'Scintilla-License-original161.txt' if sha(scintilla_notice) != 'e6e6b5250a9d5a2964496712dda87d84753d4ac1ed35080e4a7a149b9749c6e6': raise ValueError('Scintilla supporting notice identity mismatch') shutil.copy2(scintilla_notice, license_dir / 'Scintilla-License.txt') (license_dir / 'README.txt').write_text( 'MODIFIED COPY, 22 October 2026. Not an official TheOpenCD release.\n' 'Derived by subtraction from TheOpenCD 3.1; original SHA256: ' + ORIGINAL_SHA + '\n' 'Collection/menu copyright 2004 TheOpenCD Project; native GPLv2-or-later header remains in disctree/en/about.html.\n' 'The original menu logo remains as an attributed upstream asset, with its editable/native source context.\n' 'TheOpenCD is an upstream trademark. No upstream endorsement is claimed.\n' '7-Zip 4.23 copyright 1999-2005 Igor Pavlov, LGPL2.1-or-later; original notices are inside its unchanged installer.\n' 'RAR decoding includes code derived from unRAR. It must not be used to recreate a RAR-compatible compressor.\n' 'AbiWord 2.4.1: GPL2-or-later and original vendored-library notices; exact portable files retained, no binary patches.\n' 'AbiWord installer/uninstaller, Dingbats font and compiled dictionary removed; source archive omits unused fonts and dictionary blobs with a modification notice.\n' 'Exact retained zlib1.dll is version 1.2.2; its matching source is supplied separately.\n' 'Notepad2 1.0.12 copyright 2004 Florian Balmer: native binary grant permits free use/distribution, no distribution/download fee except the medium.\n' 'Notepad2 portable EXE and notice are byte-exact from the original CD installer; the wrapper is removed.\n' 'Author Notepad2 source is supplied as supplementary material; its separate Scintilla dependency is not claimed included.\n' 'Scintilla copyright and permission notice is supplied as supporting documentation, from the contemporary upstream 1.61 source archive.\n' 'This notice does not assert an exact Scintilla source-version match for the Notepad2 binary.\n' 'No application binaries were patched. Removed components are enumerated in deleted-manifest.json.\n' 'SVITS modification notes/build glue are GPL2-or-later. No warranty.\n', encoding='utf8') readme = ( 'CLEANED WINDOWS APPLICATIONS\nDerived from TheOpenCD 3.1; modified copy, not an official upstream release.\n\n' 'Open programs in Windows Explorer.\n' ' programs/7zip/7zipSetup.exe 7-Zip 4.23 installer\n' ' programs/abiword/AbiWord/bin/AbiWord.exe AbiWord 2.4.1 portable application\n' ' programs/notepad2/Notepad2.exe Notepad2 1.0.12 portable editor\n\n' 'Original directory names and retained application bytes are preserved.\n' 'AbiWord installer/uninstaller, Dingbats font and compiled dictionary are removed.\n' 'The launcher, autorun and Ubuntu boot/live system have been removed.\n' 'Sokoban, PDFCreator and applications with incomplete component review are absent.\n' 'This does not declare other free applications prohibited. This revision includes only the closed subset.\n' 'Source archives are in sources; license notices are in notices.\n' 'deleted-manifest.json lists every omitted original file and the reason.\n' 'The unmodified original has been archived separately and is not overwritten.\n') (tree / 'README.txt').write_text(readme, encoding='utf8') # Windows 2000 Notepad does not render lone LF as a line break. for document in [tree / 'README.txt', *license_dir.glob('*.txt')]: text = document.read_text(encoding='utf8') document.write_text(text, encoding='utf8', newline='\r\n') (tree / 'deleted-manifest.json').write_text(json.dumps(deleted, indent=2) + '\n') (EVIDENCE / 'deleted-manifest.json').write_text(json.dumps(deleted, indent=2) + '\n') (EVIDENCE / 'retained-manifest.json').write_text(json.dumps(retained, indent=2) + '\n') (EVIDENCE / 'source-files.json').write_text(json.dumps({'payloads': sources}, indent=2) + '\n') # New compact ISO: no original boot blocks, hidden deleted extents or live OS. iso = pycdlib.PyCdlib() iso.new(interchange_level=3, joliet=3, rock_ridge='1.09', vol_ident='OCD31_CLEANED') def iso_directory(rel): return '/' + '/'.join(re.sub('[^A-Z0-9_]', '_', part.upper()) for part in rel.split('/')) for directory in sorted((p for p in tree.rglob('*') if p.is_dir()), key=lambda p: (len(p.parts), str(p))): rel = directory.relative_to(tree).as_posix() iso.add_directory(iso_path=iso_directory(rel), joliet_path='/' + rel, rr_name=directory.name) output_inventory = [] for path in sorted(p for p in tree.rglob('*') if p.is_file()): rel = path.relative_to(tree).as_posix() stem, dot, extension = path.name.rpartition('.') primary_name = re.sub('[^A-Z0-9_]', '_', (stem if dot else extension).upper()) if dot: primary_name += '.' + re.sub('[^A-Z0-9_]', '_', extension.upper()) parent = path.parent.relative_to(tree).as_posix() primary_path = (iso_directory(parent) if parent != '.' else '') + '/' + primary_name + ';1' iso.add_file(str(path), iso_path=primary_path, joliet_path='/' + rel, rr_name=path.name) output_inventory.append({'path': '/' + rel, 'bytes': path.stat().st_size, 'sha256': sha(path)}) output = CACHE / 'OpenCD31-cleaned-windows.iso' if output.exists(): raise ValueError('Refusing to overwrite a previous output') iso.write(str(output)) iso.close() verify = pycdlib.PyCdlib() verify.open(str(output)) import io for row in output_inventory: body = io.BytesIO() verify.get_file_from_iso_fp(body, joliet_path=row['path']) if hashlib.sha256(body.getvalue()).hexdigest() != row['sha256']: raise ValueError('ISO readback mismatch: ' + row['path']) verify.close() (EVIDENCE / 'output-inventory.json').write_text(json.dumps(output_inventory, indent=2) + '\n') proof = {'created': datetime.now(timezone.utc).isoformat(), 'status': 'bytes-verified-not-yet-guest-tested', 'title': 'Cleaned Windows applications — derived from TheOpenCD 3.1', 'original': {'localFile': str(ORIGINAL), 'archiveFile': str(archived), 'bytes': ORIGINAL.stat().st_size, 'sha256': ORIGINAL_SHA}, 'output': {'localFile': str(output), 'filename': output.name, 'bytes': output.stat().st_size, 'sha256': sha(output)}, 'retainedApplications': ['7-Zip 4.23', 'AbiWord 2.4.1', 'Notepad2 1.0.12'], 'retainedOriginalFiles': sum(row['change'] == 'unchanged' for row in retained), 'retainedEmbeddedFiles': sum(row['change'] != 'unchanged' for row in retained), 'deletedOriginalFiles': len(deleted), 'sourceFiles': len(sources), 'sourceBytes': sum(s['bytes'] for s in sources), 'filesystemTool': 'pycdlib; new ISO with original selected bytes and explicit modification/source notices', 'readback': 'all output files match their supplied SHA256; no original extents are copied wholesale'} (EVIDENCE / 'ready-artifact.json').write_text(json.dumps(proof, indent=2) + '\n') print(json.dumps(proof, indent=2)) if __name__ == '__main__': main()