import hashlib import struct import tempfile import unittest from pathlib import Path from rewrite_baked_lua_string import stage def fixture(root, contents): digest = hashlib.md5(contents).digest() (root / (digest.hex() + ".bytes")).write_bytes(contents) # One block and one module, with a 3-byte LuaV block trailer. index = (struct.pack(">IIII", 255, 4, 1, 1) + bytes(8) + digest + struct.pack(">III", 0, len(contents), 1) + bytes(8) + struct.pack(">II", len(contents), 0) + b"\x00\x00\x80") index_hash = hashlib.md5(index).digest() (root / ("LuaV_" + index_hash.hex() + ".bytes")).write_bytes(index) selector = bytearray(66) selector[:4] = b"SRMI" for i in range(4): selector[28 + 4 * i:32 + 4 * i] = index_hash[4 * i:4 * i + 4][::-1] struct.pack_into("