#!/usr/bin/env python3 """Check real true/false ARM64e entry blocks, not complete process loading. Uses the prebuilt CLI only. The structural plan selects source bytes; original Unicorn execution includes the real RET and is compared with native guest state. Apple dependencies, signatures, fixups and process setup remain unresolved. """ import argparse import ctypes import hashlib import importlib.util import json from pathlib import Path import platform import struct import subprocess import tempfile import time from differential import ROOT, State, states from evidence import write_evidence STOP = 0xffff0000 def digest(data): return hashlib.sha256(data).hexdigest() def require(condition, detail): if not condition: raise AssertionError(detail) def invoke(cli, *arguments): started = time.perf_counter_ns() result = subprocess.run([str(cli), *map(str, arguments)], check=True, capture_output=True, text=True) return json.loads(result.stdout), time.perf_counter_ns() - started def original_helpers(): path = ROOT / 'dev/block-differential.py' spec = importlib.util.spec_from_file_location('stela_block_reference', path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module def validate_run(report, expected, expected_pc, context): require(report['complete_binary_verified'] is False, f'{context}: invalid full-binary claim') require(report['pc'] == expected_pc, f'{context}: wrong guest PC') require(report['state'] == expected, f'{context}: register/state mismatch') require(report['outcome']['reason'] == {'kind': 'stop_address'}, f'{context}: no return stop') require(report['outcome']['blocks_executed'] == 1, f'{context}: unexpected block count') require(report['outcome']['last_exit'] == [STOP, 4], f'{context}: no architectural RET exit') def check_image(cli, path, exit_status, work, reference): preflight, _ = invoke(cli, 'plan-executable', path, '--architecture', 'arm64e') container = path.read_bytes() preflight_plan = preflight['plan'] start = preflight['slice_offset'] thin = container[start:start + preflight_plan['slice_bytes']] require(digest(container) == preflight['container_sha256'] and digest(thin) == preflight_plan['slice_sha256'], 'preflight input identity mismatch') offset = preflight_plan['entry']['file_offset'] entry_pc = preflight_plan['entry']['guest_address'] require(any(segment['initial_protection'] & 4 and segment['guest']['address'] <= entry_pc and entry_pc + 8 <= segment['guest']['address'] + segment['file']['bytes'] for segment in preflight_plan['segments']), 'entry pair is not fully file-backed executable code') known_source = struct.pack('