#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Identify the Xbox firmware images we can see, by SHA-1 only. Firmware is Microsoft's (the flash BIOS with its kernel, the MCPX boot ROM) or a third party's under Microsoft's licence, and some of it holds keys. This script reads each candidate into memory, prints its size, SHA-1 and what MAME 0.285's `xbox`/`chihiro` drivers call it, and writes nothing else: no copy, no extract, no partial dump. Members of zip archives are read from the archive in memory. Where to look comes from the environment, never from this repository: - REDUMP_DIR: its "Microsoft - Xbox - BIOS Images" folder (Redump's flash dumps); - MAME_ROMPATH: `xbox.zip` and `chihiro.zip` (one or more folders, separated by ';'); - XBOX_FIRMWARE_DIR: any further folder of loose files (a frontend's BIOS folder). python -I scripts/census_firmware.py > tests/detectors/census-firmware-.txt """ from __future__ import annotations import hashlib import os import sys import zipfile from pathlib import Path # SHA-1s as MAME 0.285 lists them (`mame -listroms xbox chihiro`, run 2026-11-26). # These are identifications, not content: the bytes stay where the player keeps them. KNOWN = { "5d270675b54eb8071b480e42d22a3015ac211cef": "MCPX boot ROM 1.0 (mcpx_1_0.bin, 512 bytes)", "6c875f17f773aaec51eb434068bb6c657c4343c0": "MCPX boot ROM 1.1 (mcpx_1_1.bin, 512 bytes)", "d46cef771a63dc8024fe36d7ab5b959087ac999f": "flash 4134 (1 MiB), MAME xbox bios0", "67054fc88bda94e33e86f1b19be60efec0724fb6": "flash 3944 (1 MiB), MAME xbox bios1", "ab676b712204fb1728bf89f9cd541a8f5a64ab97": "flash 4034 (1 MiB), MAME xbox bios2", "dc955bd4d3ca71e01214a49e5d0aba615270c03c": "flash 4817 (1 MiB), MAME xbox bios3", "5108e1025f48071c07a6823661d708c66dee97a9": "flash 5101 (256 KiB), MAME xbox tbp", "40fa73277013be3168135e1768b09623a987ff63": "flash 5530 (256 KiB), MAME xbox tbp", "8b7ccc4648ccd78cdb7b65cfca09621eaf2d4238": "flash 5713 (256 KiB), MAME xbox tbp", "b9489e883c650b5e5fe2f83a32237dbf74f0e9f1": "flash 5838 (256 KiB), MAME xbox tbp", "c18cbc0fb01ad423f99eb6421a36f3915e37e843": "DSP56362 bootstrap ROM (boot-362.bin, MAME's GP DSP stand-in)", "b700b0041af8f84835e45d1d1250247bf7077188": "Chihiro flash (chihiro_xbox_bios.bin, 512 KiB)", } # Name fragments of Xbox firmware files in frontends' BIOS folders (xemu's and Batocera's # conventions); "cerbios" and "complex" are third-party modified flash images. XBOX_WORDS = ("xbox", "mcpx", "complex", "cerbios", "cromwell", "evox", "chihiro") def sha1(data: bytes) -> str: return hashlib.sha1(data).hexdigest() def report(label: str, data: bytes) -> None: digest = sha1(data) print(f"{len(data):>8} {digest} {label} -> {KNOWN.get(digest, 'not in MAME 0.285 xbox/chihiro')}") def scan_zip(path: Path) -> None: try: with zipfile.ZipFile(path) as archive: for member in archive.infolist(): if member.is_dir() or member.file_size > 16 << 20: continue report(f"{path.name}:{member.filename}", archive.read(member)) except (OSError, zipfile.BadZipFile) as error: print(f"unreadable {path.name}: {error}") def scan_folder(folder: Path, names: tuple[str, ...] | None = None) -> None: for path in sorted(folder.iterdir()): if names is not None and path.name not in names: continue if path.suffix.lower() == ".zip": scan_zip(path) elif path.is_file() and path.suffix.lower() == ".bin" and path.stat().st_size <= 16 << 20: report(path.name, path.read_bytes()) def main() -> int: redump = os.environ.get("REDUMP_DIR") if redump: folder = Path(redump) / "Microsoft - Xbox - BIOS Images" print(f"== REDUMP_DIR/{folder.name}") if folder.is_dir(): scan_folder(folder) for entry in filter(None, os.environ.get("MAME_ROMPATH", "").split(";")): print("== MAME_ROMPATH: xbox.zip, chihiro.zip") if Path(entry).is_dir(): scan_folder(Path(entry), ("xbox.zip", "chihiro.zip")) extra = os.environ.get("XBOX_FIRMWARE_DIR") if extra: # A frontend's BIOS folder holds every system's files: only loose files of an Xbox # firmware size are looked at (512 bytes, 256 KiB, 512 KiB, 1 MiB). # Names are not evidence, but they narrow a mixed folder: the SHA-1 decides. print("== XBOX_FIRMWARE_DIR (loose files of Xbox firmware sizes and names)") for path in sorted(Path(extra).iterdir()): named = any(word in path.name.lower() for word in XBOX_WORDS) if named and path.is_file() and path.stat().st_size in (512, 256 << 10, 512 << 10, 1 << 20): report(path.name, path.read_bytes()) return 0 if __name__ == "__main__": sys.exit(main())