"""Check refusal of changed game code/constants without writing modified binaries.""" import importlib.util import json import sys import tempfile from pathlib import Path from unittest.mock import patch spec = importlib.util.spec_from_file_location("lift_rng", Path(__file__).parents[1] / "tools/lift_rng.py") lift = importlib.util.module_from_spec(spec) spec.loader.exec_module(lift) source = Path(sys.argv[1]) original = source.read_bytes() image, slice_offset = lift.arm64_image(original) ranges = [("function", lift.FUNCTION_VA, lift.BODY_SIZE), ("seed constructor", lift.SEED_VA, lift.SEED_SIZE), ("constants", lift.CONSTANT_VA, 32)] for label, address, length in ranges: changed = bytearray(original) changed[slice_offset + lift.file_range(image, address, length)] ^= 1 with tempfile.TemporaryDirectory() as folder: out = Path(folder) / "generated" with patch.object(Path, "read_bytes", return_value=bytes(changed)): try: lift.generate(source, out) except ValueError: assert not out.exists(), "Rejected input produced output artifacts" print(f"PASS: changed {label} rejected before output") else: raise AssertionError(f"Changed {label} accepted")