#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Identify the DS / DSi BIOS and firmware images on this machine by SHA-1. Looks in three places, each found through an environment variable, never a path in the repository: - ``$NO_INTRO_DIR``: the ``[BIOS]`` entries of the Nintendo DS and DSi folders (zips; each member is hashed in place); - ``$MAME_ROMPATH``: MAME's ``nds.zip`` (``biosnds7.rom``, ``biosnds9.rom``, firmware); - ``$FRONTEND_BIOS`` (optional): a frontend's BIOS folder (``bios7.bin``, ``bios9.bin``, ``firmware.bin``, ``dsi_*.bin``). Nothing is copied or kept; the SHA-1, size and name are printed. The images belong to Nintendo and are never committed (charter, licences point 9). python -I scripts/census_bios.py """ from __future__ import annotations import hashlib import os import sys import zipfile from pathlib import Path NO_INTRO_FOLDERS = ("Nintendo - Nintendo DS (Decrypted)", "Nintendo - Nintendo DSi (Decrypted)", "Nintendo - Nintendo DSi (Digital) (CDN) (Decrypted)") FRONTEND_NAMES = ("bios7.bin", "bios9.bin", "firmware.bin", "dsi_bios7.bin", "dsi_bios9.bin", "dsi_firmware.bin", "dsi_nand.bin") def report(origin: str, name: str, data: bytes) -> None: print(f"{hashlib.sha1(data).hexdigest()} {len(data):>9} {origin}: {name}") def zip_members(origin: str, path: Path) -> None: with zipfile.ZipFile(path) as archive: for member in archive.infolist(): if member.file_size > 64 << 20: print(f"{'(not hashed: larger than 64 MB)':40} {member.file_size:>9} {origin}: {member.filename}") continue report(origin, f"{path.name} / {member.filename}", archive.read(member)) def main() -> int: root = os.environ.get("NO_INTRO_DIR") if root: for folder in NO_INTRO_FOLDERS: for path in sorted((Path(root) / folder).glob("*.zip")): if path.name.startswith("[BIOS]"): zip_members("No-Intro", path) for entry in os.environ.get("MAME_ROMPATH", "").split(";"): path = Path(entry) / "nds.zip" if entry and path.exists(): zip_members("MAME", path) frontend = os.environ.get("FRONTEND_BIOS") if frontend: for name in FRONTEND_NAMES: path = Path(frontend) / name if path.exists(): report("frontend", name, path.read_bytes()) return 0 if __name__ == "__main__": sys.exit(main())