883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
87 lines
5.5 KiB
Python
87 lines
5.5 KiB
Python
"""Synthetic exact-target/privacy check only; no fork, ptrace, game or API calls."""
|
|
from pathlib import Path
|
|
import struct,sys
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0,str(ROOT/'ops'))
|
|
import native_registration_trace as t
|
|
def literal_boundary():
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
base=0x20000000;table=0x30000000;namespace=table+32
|
|
owned="/fixture/owned/WowB.exe"
|
|
maps=(f"{base:x}-{base+4096:x} r--p 00000000 00:00 1 {owned}\n"
|
|
f"{base+4096:x}-{base+0x6000000:x} r-xp 00001000 00:00 1 {owned}\n"
|
|
f"{table:x}-{table+4096:x} rw-p 00000000 00:00 0")
|
|
dos=bytearray(64);dos[:2]=b"MZ";struct.pack_into("<I",dos,60,128)
|
|
nt=bytearray(84);nt[:4]=bytes.fromhex("50450000");struct.pack_into("<H",nt,24,0x20b);struct.pack_into("<I",nt,80,0x6000000)
|
|
expected_name=b"RegionalUniqueNamesEnabled"+bytes(1)
|
|
assert t.REGIONAL_EXACT_NAME==expected_name
|
|
callback=base+4096
|
|
memory={(base,64):bytes(dos),(base+128,84):bytes(nt),
|
|
(base+t.REGIONAL_NAME_RVA,len(expected_name)):expected_name,
|
|
(table,8):struct.pack("<Q",base+t.REGIONAL_NAME_RVA),
|
|
(table+8,8):struct.pack("<Q",callback),(namespace,1):bytes(1)}
|
|
reads=[]
|
|
def read(fd,size,address):
|
|
reads.append((address,size));assert(address,size)in memory
|
|
return memory[address,size]
|
|
probe=object.__new__(t.RegistrationTrace)
|
|
probe.pid=4242;probe.owned_image_path=owned;probe.exact_stops=0;probe.exact_rows=0;probe.events=[];probe.done=False
|
|
statuses=[]
|
|
def finish(status):statuses.append(status);probe.done=True
|
|
probe.finish=finish
|
|
with patch.object(t.Path,"read_text",return_value=maps),patch.object(t.os,"open",return_value=7),patch.object(t.os,"close"),patch.object(t.os,"pread",side_effect=read):
|
|
probe.exact_rebase()
|
|
assert probe.targets==(base+t.REGIONAL_REGISTER_RVA,0,0,0)
|
|
probe.observe_exact_global(SimpleNamespace(rcx=table,rdx=1,r8=namespace))
|
|
assert statuses==["exact-regional-global-binding-observed"]
|
|
assert len(probe.events)==1 and probe.events[0]["callback"]==hex(callback)and probe.events[0]["namespace_empty"]
|
|
assert not probe.events[0]["code_page_read"]
|
|
probe.done=False;probe.events=[];statuses.clear();memory[namespace,1]=b"C"
|
|
probe.observe_exact_global(SimpleNamespace(rcx=table,rdx=1,r8=namespace))
|
|
assert not statuses and not probe.events
|
|
assert(namespace,1)in reads
|
|
if "--literal-boundary-only"in sys.argv:
|
|
literal_boundary()
|
|
print("PASS exact NUL name/PE64 header and empty-namespace boundary; mocked reads only")
|
|
raise SystemExit(0)
|
|
literal_boundary()
|
|
TABLE=0x5000;NAME=0x9000;BASE=0x100000;END=0x110000;CALLBACK=BASE+0x123
|
|
def fixture(names,callback=CALLBACK,short=None,readable=True):
|
|
reads=[];memory={TABLE+i*16:struct.pack('<Q',n)for i,n in enumerate(names)}
|
|
# Nonmatching callback cells deliberately have no accessible data.
|
|
for i,n in enumerate(names):
|
|
if n==NAME:memory[TABLE+i*16+8]=struct.pack('<Q',callback)
|
|
def read(address,size):
|
|
reads.append((address,size))
|
|
assert size==8 and address in memory,'read escaped declared pointer cells'
|
|
return memory[address][:-1]if address==short else memory[address]
|
|
result=t.exact_global_callback(read,lambda a,n:readable and a==TABLE and n==len(names)*16,TABLE,len(names),NAME,(BASE,END))
|
|
return result,reads
|
|
r,reads=fixture([0xdead,NAME,0xbeef])
|
|
assert r['status']=='exact-global-binding-candidate'and r['callback']==CALLBACK and r['row_index']==1
|
|
assert r['callback_rva']==0x123 and r['callback_page']==BASE
|
|
assert reads==[(TABLE,8),(TABLE+16,8),(TABLE+32,8),(TABLE+24,8)]
|
|
r,reads=fixture([0xdead,0xbeef]);assert r=={'status':'not-this-registration','rows':2}and len(reads)==2
|
|
r,reads=fixture([NAME,NAME]);assert r['status']=='ambiguous-target-held'and len(reads)==2
|
|
r,reads=fixture([NAME],callback=END);assert r['status']=='non-image-callback-held'and'callback'not in r
|
|
r,reads=fixture([NAME],short=TABLE);assert r['status']=='short-name-pointer-held'and len(reads)==1
|
|
r,reads=fixture([NAME],readable=False);assert r['status']=='table-mapping-held'and not reads
|
|
for count in [0,-1,True,t.REGIONAL_MAX_ROWS+1]:
|
|
def denied(*args):raise AssertionError('invalid bound reached reader')
|
|
assert t.exact_global_callback(denied,denied,TABLE,count,NAME,(BASE,END))['status']=='row-count-held'
|
|
assert t.exact_global_callback(denied,lambda*a:True,2**64-8,1,NAME,(BASE,END))['status']=='table-mapping-held'
|
|
# Rebase only the explicitly owned source-image header mapping; no preferred-base assumption.
|
|
owned='/fixture/owned/WowB.exe'
|
|
maps='20000000-20001000 r--p 00000000 00:00 1 '+owned+'\n20001000-25000000 r-xp 00001000 00:00 1 '+owned
|
|
base,m=t.exact_owned_image(maps,owned);assert base==0x20000000 and len(m)==2
|
|
for changed in [maps.replace(owned,'/fixture/unowned/WowB.exe'),maps.replace(owned,owned+' (deleted)'),maps+'\n30000000-30001000 r--p 00000000 00:00 1 '+owned]:
|
|
try:t.exact_owned_image(changed,owned)
|
|
except ValueError:pass
|
|
else:raise AssertionError('unowned/deleted/ambiguous image accepted')
|
|
# Exact mode reserves one execution slot only; legacy arm behavior remains untouched.
|
|
probe=object.__new__(t.RegistrationTrace);probe.targets=(base+t.REGIONAL_REGISTER_RVA,0,0,0);probe.exact_regional_global=True
|
|
writes=[];probe.debug=lambda i,v=None:writes.append((i,v));probe.arm()
|
|
assert writes==[(0,base+t.REGIONAL_REGISTER_RVA),(1,0),(2,0),(3,0),(6,0),(7,1)]
|
|
print('PASS exact-global pointer equality/privacy/refusal, owned module rebase and one-slot preparation; no runtime observation')
|