Uupdump __link__ 【720p · 8K】
# ------------------------------ # Helper functions # ------------------------------ def run_cmd(cmd, cwd=None, check=True): """Run shell command and return output.""" print(f"[RUN] {' '.join(cmd)}") result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True) if check and result.returncode != 0: print(f"ERROR: {result.stderr}") raise RuntimeError(f"Command failed: {' '.join(cmd)}") return result.stdout.strip()
import os import sys import json import hashlib import subprocess import argparse import concurrent.futures from pathlib import Path from urllib.parse import urljoin import requests from typing import Dict, List, Optional uupdump
# Resume support headers = {} if dest_path.exists(): existing_size = dest_path.stat().st_size if expected_size and existing_size == expected_size: print(f" [SKIP] {dest_path.name} already complete") return True headers['Range'] = f'bytes={existing_size}-' print(f" [DL] {url}") resp = requests.get(url, stream=True, headers=headers) resp.raise_for_status() mode = 'ab' if 'Range' in headers else 'wb' with open(dest_path, mode) as f: for chunk in resp.iter_content(chunk_size=8192): f.write(chunk) # Verify size if expected_size and dest_path.stat().st_size != expected_size: raise ValueError(f"Size mismatch for {dest_path.name}") # Verify SHA‑1 if expected_sha1: sha1 = hashlib.sha1() with open(dest_path, 'rb') as f: for chunk in iter(lambda: f.read(65536), b''): sha1.update(chunk) if sha1.hexdigest() != expected_sha1: raise ValueError(f"SHA‑1 mismatch for {dest_path.name}") return True help="Output ISO path"
# ------------------------------ # Main CLI # ------------------------------ def main(): parser = argparse.ArgumentParser(description="UUPdump-style Windows ISO builder") parser.add_argument("build", help="Build number, e.g., 22621.1") parser.add_argument("lang", help="Language code, e.g., en-us") parser.add_argument("edition", help="Edition, e.g., Professional") parser.add_argument("--out", "-o", help="Output ISO path", default="windows_install.iso") parser.add_argument("--work-dir", help="Working directory", default="UUP_workspace") parser.add_argument("--keep-temp", action="store_true", help="Keep temporary files") args = parser.parse_args() work_dir = Path(args.work_dir) work_dir.mkdir(exist_ok=True) try: print(f"Fetching UUP info for build {args.build}, lang {args.lang}, edition {args.edition}") uup_info = fetch_uup_info(args.build, args.lang, args.edition) print("Downloading UUP files...") uup_files_dir = download_uup_files(uup_info, work_dir, args.edition) print("Converting to ISO...") convert_to_iso(uup_files_dir, args.edition, Path(args.out), keep_temp=args.keep_temp) print("Done.") except Exception as e: print(f"Error: {e}") sys.exit(1) real tool would parse run_cmd(["wimlib-imagex"
def convert_to_iso(uup_dir: Path, edition: str, out_iso: Path, keep_temp=False): """ Convert downloaded UUP files to bootable ISO using external tools: - cabextract + wimlib-imagex to create install.wim/install.esd - mkisofs or oscdimg to build ISO """ temp_dir = uup_dir.parent / "iso_temp" temp_dir.mkdir(exist_ok=True) # Step 1: Extract all CABs (some contain Windows PE, boot files) extract_dir = temp_dir / "extract" extract_dir.mkdir(exist_ok=True) for cab in uup_dir.glob("*.cab"): print(f"Extracting {cab.name}") run_cmd(["cabextract", "-d", str(extract_dir), str(cab)]) # Step 2: Locate the main Windows image (install.wim or install.esd) # Usually inside a cab named something like `windows10.0-kb...-x64.cab` wim_file = None for possible in extract_dir.glob("*.wim"): wim_file = possible break if not wim_file: # Maybe compressed ESD for possible in extract_dir.glob("*.esd"): wim_file = possible break if not wim_file: raise RuntimeError("No WIM/ESD found in extracted UUP files") # Step 3: Apply image to a directory (or export single edition) mount_dir = temp_dir / "mount" mount_dir.mkdir(exist_ok=True) # Get edition index (usually 1 for single edition, but check) edition_index = 1 # For simplicity; real tool would parse run_cmd(["wimlib-imagex", "apply", str(wim_file), str(edition_index), str(mount_dir)]) # Step 4: Prepare ISO layout iso_root = temp_dir / "iso_root" iso_root.mkdir(exist_ok=True) # Copy boot files (UEFI/BIOS) # Usually: bootmgr, bootmgr.efi, efi/, boot/ # For simplicity, assume extracted files have them in `Windows/Boot/` boot_src = mount_dir / "Windows" / "Boot" if boot_src.exists(): run_cmd(["cp", "-r", str(boot_src), str(iso_root)]) # Copy the applied Windows image as install.wim (or use wimlib capture) install_wim = iso_root / "sources" / "install.wim" install_wim.parent.mkdir(exist_ok=True) run_cmd(["wimlib-imagex", "capture", str(mount_dir), str(install_wim), edition, "Windows UUP"]) # Step 5: Create ISO print(f"Creating ISO: {out_iso}") # Use genisoimage (Linux) or mkisofs run_cmd([ "genisoimage", "-b", "boot/etfsboot.com", "-no-emul-boot", "-boot-load-size", "8", "-boot-info-table", "-eltorito-alt-boot", "-e", "efi/microsoft/boot/efisys.bin", "-no-emul-boot", "-o", str(out_iso), str(iso_root) ]) if not keep_temp: run_cmd(["rm", "-rf", str(temp_dir)]) print(f"ISO created: {out_iso}")