"""scripts/renhdrum.py: RenHDrum (renhdrum.dll, renhdrum.so) built from third_party/renhdrum, and checked before it ships (no network, no Rust, nothing loaded or run). `check` reads the file's headers only. Over made-up PE and ELF images: a good one passes; one needing a library a player would have to install (the VC++ Runtime, llvm-mingw's libunwind.dll or libc++; a libstdc++) fails and names it; one without an export host/rumble_renhdrum.c binds fails and names it; one for another machine fails; one of the other system's format fails (a Linux library named renhdrum.dll: Windows refuses it with a "Bad Image" box, 0xc000012f); a file that is neither stops with a message, not a traceback. The script never loads the library (no ctypes): checking never runs it. `build` is run with cargo and the toolchain stubbed: the command is a locked, offline build of the tracked source, for x86_64-pc-windows-gnullvm linked by the llvm-mingw given (the unwinder static, no time stamp) or for x86_64-unknown-linux-gnu linked by the C compiler given (no build id), with no local path in it either way; the source is copied out of the tree with build.rs, and libopus from third_party/opus where build.rs reads it (its demo program left out); libopus is compiled by the same C compiler that links it, its paths relative; cargo reads crates.io only from the crates Cargo.lock names, unpacked from the cache (each checked by its Cargo.lock SHA-256, one that is not refused); what fails the check is not copied out. A Rust download whose SHA-256 is not the pinned one is refused and not kept. (Triforce) It is built by hand; nx2/build.py copies it beside the game when third_party/renhdrum/ has it, and nx2/make_game.py stages it with the game's other files. third_party/renhdrum holds the source, with its upstream archive named. py -3 -I -B tests/test_renhdrum.py """ import contextlib import hashlib import importlib.util import io import os import re from pathlib import Path import shutil import struct import subprocess import tempfile import unittest from unittest import mock ROOT = Path(__file__).resolve().parents[1] def load(name, path): spec = importlib.util.spec_from_file_location(name, path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module rh = load("renhdrum_under_test", ROOT / "scripts" / "renhdrum.py") EXPORTS = rh.EXPORTS GOOD_IMPORTS = ("kernel32.dll", "ntdll.dll", "api-ms-win-core-synch-l1-2-0.dll", "api-ms-win-crt-heap-l1-1-0.dll") def elf(needed=("libc.so.6", "libgcc_s.so.1", "libm.so.6"), exports=EXPORTS, machine=62): """A 64-bit ELF with three sections: .dynstr, .dynamic (DT_NEEDED each of `needed`), .dynsym (`exports`, defined)""" strtab = bytearray(b"\0") def add(name): at = len(strtab) strtab.extend(name.encode() + b"\0") return at needs = [add(n) for n in needed] syms = [add(n) for n in exports] dynamic = b"".join(struct.pack("