#!/usr/bin/env python3 """Probe one pinned Rosetta lookup helper in ARM Unicorn with synthetic tables. No Rosetta installer, process runtime, translator or native ARM library is run. This is a behavioral experiment for the inspected metadata helper only. """ import argparse import hashlib import json from pathlib import Path import struct import subprocess from differential import ROOT, State, reference, states from unicorn import UcError from evidence import write_evidence BINARY_SHA256 = "2285868ea879cc62d7dbde393a161f2b7452e94a74cb92be2df2d9465df03208" FUNCTION_SHA256 = "c8822c4fa899675b4bf7e9c90713cd7483ea039f408eb11ccaa2c42aff220da4" RAM = 0x200000 RAM_SIZE = 0x10000 def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("binary", type=Path) parser.add_argument("--output", type=Path, required=True) args = parser.parse_args() if hashlib.sha256(args.binary.read_bytes()).hexdigest() != BINARY_SHA256: raise ValueError("Rosetta binary differs from reviewed build 26A434") subprocess.run([str(ROOT / "dev/cargo"), "build", "--locked", "-p", "stela-cli"], check=True) row = json.loads(subprocess.check_output([str(ROOT / "target/debug/stela"), "binary-text", str(args.binary)]))[0]["slice"] symbol, address = next((name, value) for name, value in row["defined_text_symbols"].items() if "30find_arm_offset_for_x86_offset" in name) section = next(s for s in row["sections"] if s["guest_address"] <= address < s["guest_address"] + len(bytes.fromhex(s["data_hex"]))) offset = address - section["guest_address"] code = bytes.fromhex(section["data_hex"])[offset:offset + 116] if hashlib.sha256(code).hexdigest() != FUNCTION_SHA256: raise ValueError("Rosetta lookup function differs from inspected source") reports = [] # Disassembly shows begin/end pointers at +0x38/+0x40 and a 12-byte stride. # Each row compares word 0 to the requested key and returns word 1. for count in (0, 1, 2, 7, 128): entries = [(i * 8, 0x100 + i * 12, 0xfedc0000 + i) for i in range(count)] queries = {0, 1, 6, 0xffffffff} if entries: queries.update((entries[0][0], entries[count // 2][0], entries[-1][0], entries[-1][0] + 1)) for query in sorted(queries): for flags, original in enumerate(states(all_flags=True)): initial = State.from_buffer_copy(original) initial.x[0], initial.x[1], initial.x[2] = RAM, query, RAM + 0x1000 initial.sp = RAM + 0x8000 memory = bytearray(b"\xa5" * RAM_SIZE) struct.pack_into("