367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
95 lines
4.0 KiB
Python
95 lines
4.0 KiB
Python
"""Observe the original race-vector producer only on its natural Create call.
|
|
|
|
The caller and its direct target are pinned by the previously captured native
|
|
Create getter. No UI action, engine call, packet payload, customization data,
|
|
or memory-protection change is performed by this profile.
|
|
"""
|
|
|
|
import hashlib
|
|
import os
|
|
import struct
|
|
from pathlib import Path
|
|
|
|
ENTRY = 0x142407500
|
|
CALL_SITE = 0x140ED37F5
|
|
RETURN_ADDRESS = 0x140ED37FA
|
|
CALL_BYTES = bytes.fromhex("e8063d5301")
|
|
BODY_BYTES = 375
|
|
PREFIX = b""
|
|
OBSERVE_NATURAL_FIRST_USE = True
|
|
|
|
|
|
def inspect(read, readable, executable, stack_pointer):
|
|
"""Return bounded original code only for the exact observed call edge."""
|
|
base = {
|
|
"engine_calls_made": False,
|
|
"arguments_read": False,
|
|
"packet_payloads_read": False,
|
|
"memory_protection_changed": False,
|
|
}
|
|
if not readable(stack_pointer, 8):
|
|
return {**base, "available": False, "reason": "return-address-unreadable"}
|
|
raw_return = read(stack_pointer, 8)
|
|
if len(raw_return) != 8:
|
|
return {**base, "available": False, "reason": "return-address-short"}
|
|
if struct.unpack("<Q", raw_return)[0] != RETURN_ADDRESS:
|
|
return {**base, "available": False, "reason": "different-original-caller"}
|
|
if not executable(CALL_SITE, len(CALL_BYTES)):
|
|
return {**base, "available": False, "reason": "caller-not-executable"}
|
|
if read(CALL_SITE, len(CALL_BYTES)) != CALL_BYTES:
|
|
return {**base, "available": False, "reason": "caller-code-differs"}
|
|
if not executable(ENTRY, BODY_BYTES):
|
|
return {**base, "available": False, "reason": "producer-not-executable"}
|
|
body = read(ENTRY, BODY_BYTES)
|
|
if len(body) != BODY_BYTES:
|
|
return {**base, "available": False, "reason": "producer-short-read"}
|
|
return {**base, "available": True, "entry": hex(ENTRY),
|
|
"caller_verified": True, "bytes": len(body),
|
|
"sha256": hashlib.sha256(body).hexdigest(), "code": body}
|
|
|
|
|
|
def capture(pid, registers):
|
|
if registers.rip != ENTRY:
|
|
return {"available": False, "reason": "different-entry",
|
|
"engine_calls_made": False, "arguments_read": False}
|
|
try:
|
|
mappings = Path(f"/proc/{pid}/maps").read_text().splitlines()
|
|
spans = []
|
|
for line in mappings:
|
|
fields = line.split()
|
|
lo, hi = (int(value, 16) for value in fields[0].split("-"))
|
|
spans.append((lo, hi, fields[1]))
|
|
|
|
def permitted(address, size, permission):
|
|
return (type(address) is int and address > 0 and size > 0 and
|
|
any(lo <= address and address + size <= hi and permission in mode
|
|
for lo, hi, mode in spans))
|
|
|
|
fd = os.open(f"/proc/{pid}/mem", os.O_RDONLY)
|
|
try:
|
|
result = inspect(lambda address, size: os.pread(fd, size, address),
|
|
lambda address, size: permitted(address, size, "r"),
|
|
lambda address, size: permitted(address, size, "x"),
|
|
registers.rsp)
|
|
finally:
|
|
os.close(fd)
|
|
body = result.pop("code", None)
|
|
if body is not None:
|
|
root = Path(__file__).resolve().parents[1]
|
|
folder = root / "runtime/native-handler-code"
|
|
folder.mkdir(parents=True, exist_ok=True)
|
|
path = folder / f"{ENTRY:x}-{result['sha256'][:16]}.bin"
|
|
if path.exists():
|
|
if path.read_bytes() != body:
|
|
raise ValueError("Preserve existing producer capture")
|
|
else:
|
|
with path.open("xb") as output:
|
|
output.write(body)
|
|
path.chmod(0o600)
|
|
result["capture"] = str(path.relative_to(root))
|
|
return result
|
|
except (OSError, ValueError):
|
|
return {"available": False, "reason": "bounded-code-capture-failed",
|
|
"engine_calls_made": False, "arguments_read": False,
|
|
"packet_payloads_read": False, "memory_protection_changed": False}
|