883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
156 lines
11 KiB
Python
156 lines
11 KiB
Python
import json,struct,sys,tempfile
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'ops'))
|
|
import engine_pipe_host as pipe
|
|
def check_world_failure_reader():
|
|
failure=struct.pack('<IIIi8I',1,48,1,-6,0x1f6,11635,0,0,0,1048576,0,0)
|
|
decoded=pipe.decode_world_failure(failure)
|
|
assert decoded['phase']==1 and decoded['result']==-6 and decoded['source_opcode']==0x1f6
|
|
assert decoded['source_bytes']==11635 and decoded['capacity']==1048576
|
|
assert set(decoded)=={'phase','result','source_opcode','source_bytes','modern_opcode','modern_bytes','required','capacity','count','index'}
|
|
for offset,value in ((0,2),(4,47),(8,13)):
|
|
bad=bytearray(failure);struct.pack_into('<I',bad,offset,value)
|
|
try:pipe.decode_world_failure(bad);raise AssertionError('Malformed stage diagnostic accepted')
|
|
except ValueError:pass
|
|
for length in (0,47,49):
|
|
try:pipe.decode_world_failure((failure+b'\0')[:length]);raise AssertionError('Malformed diagnostic length accepted')
|
|
except ValueError:pass
|
|
print('World failure stage/result decoding is bounded48-byte metadata only; no packet/account payload exposed.')
|
|
|
|
for bit,state in ((1,0),(2,4),(4,5),(8,0xffffffff)):
|
|
lost=struct.pack('<IIIi8I',1,48,12,bit,0,0,0,0,0,0,0,state)
|
|
row=pipe.decode_world_failure(lost)
|
|
assert row['phase']==12 and row['result']==bit and row['index']==state
|
|
assert all(row[k]==0 for k in ('source_opcode','source_bytes','modern_opcode','modern_bytes','required','capacity','count'))
|
|
print('PASS phase12 reader: all four first-loss bits/raw state retained; phase13/invalid48B ABI refused, no process read.')
|
|
|
|
if "--world-failure-only" in sys.argv:
|
|
check_world_failure_reader()
|
|
raise SystemExit(0)
|
|
|
|
q=lambda *v:struct.pack('<'+'Q'*len(v),*v)
|
|
class Memory:
|
|
owner=0x100000;connection=0x200000;queue=0x300000;listener=0x400000;holder=0x500000;pipe=0x600000;data=0x180007000
|
|
def __init__(self):
|
|
self.memory={};self.writes=[]
|
|
for address,value in [(0x145e7a098,q(self.owner)),(self.owner,q(0x180009000)),(self.owner+0x98,struct.pack('<I',4)),(self.owner+0x1a0,q(self.connection)),(self.owner+0xa0,q(self.queue)),(self.owner+0x220,q(self.listener)),(self.owner+0x228,q(self.holder)),(self.holder,q(self.pipe)),(self.pipe,q(pipe.TABLE,self.owner,0)),(self.queue,q(self.owner)),(self.connection,q(0x1450396b0)),(self.connection+0x28,q(self.listener)),(self.listener+8,q(self.owner)),(pipe.TABLE-8,q(0x145001000,*pipe.METHODS)),(pipe.ENTRY,pipe.PREFIX),(0x1450396b0+17*8,q(0x1434db6b0,0x1434db7a0)),(self.data+0x1000,struct.pack('<II',1,1168)+bytes(1160)),(self.data,struct.pack('<II',1,640)+bytes(632))]:self.put(address,value)
|
|
def put(self,address,value):self.memory.update({address+i:b for i,b in enumerate(value)})
|
|
def read(self,address,size):return bytes(self.memory[address+i] for i in range(size))
|
|
def u64(self,address):return struct.unpack('<Q',self.read(address,8))[0]
|
|
def allowed(self,address,size,mode):return mode=='x'
|
|
def write(self,address,value):
|
|
assert address==self.pipe and len(value)==8 or self.data<=address and address+len(value)<=self.data+640
|
|
self.writes.append((address,len(value)));self.put(address,value)
|
|
def close(self):pass
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
root=Path(directory);(root/'runtime').mkdir();(root/'runtime/engine-poll-binding.json').write_text(json.dumps(dict(pid=123,owner=Memory.owner,bound_vtable=0x180009000,restored=False)))
|
|
(root/'runtime/engine-pipe-entry-preflight.json').write_text(json.dumps(dict(pid=123,verified_entries=[0x141e46020,pipe.ENTRY],previously_verified_queue=0x141e54190)))
|
|
exports=dict(gw_wire_pipe_data=0x7000,gw_wire_pipe_write=0x2000,gw_wire_pipe_read=0x2100,gw_wire_pipe_queries=0x8000,gw_wire_world_data=0x9000,gw_wire_entity_data=0xa000,gw_wire_motion_data=0xd000,gw_wire_movement_failure=0xe000,gw_wire_hotfix_data=0xf000)
|
|
for reject in ('','connected','method','owner','proof','connection','pipe','caller'):
|
|
memory=Memory();account=dict(state=2,server_proof_verified=1,transport_prepared=1)
|
|
memory.put(0x180009000,struct.pack('<II',1,432)+bytes(424))
|
|
memory.put(0x180009000+44,struct.pack('<I',0x67))
|
|
memory.put(0x18000a000,struct.pack('<12I',1,10288,1,1,0,1,0,0,0,0,1,0)+struct.pack('<Q16s4I',99,bytes(16),9010,3,1,7)+bytes(10288-88))
|
|
memory.put(0x18000d000,struct.pack('<8I',1,1056,7,3,2,2,1,0)+struct.pack('<Q16sII6fII',99,bytes(16),42,5000,1,2,3,4,5,6,1,0)+bytes(960))
|
|
memory.put(0x18000e000,struct.pack('<4Ii7I',1,48,0x420002,78,-2,0x2801,0,0x20,0,0,0x80,21))
|
|
memory.put(0x18000f000,struct.pack('<9Ii',1,40,2,1,70334,70334,1,16,400,0))
|
|
if reject=='connected':memory.put(memory.owner+0x98,struct.pack('<I',5))
|
|
if reject=='method':memory.put(pipe.TABLE+8,q(0x141e4d121))
|
|
if reject=='owner':memory.put(0x145e7a098,q(0))
|
|
if reject=='proof':account['server_proof_verified']=0
|
|
if reject=='connection':memory.put(memory.connection,q(0))
|
|
if reject=='pipe':memory.put(memory.pipe+16,q(memory.connection))
|
|
with patch.object(pipe,'ROOT',root),patch.object(pipe.host,'Access',return_value=memory),patch.object(pipe.wire,'module',return_value=(0x180000000,{'exports':exports},{})),patch.object(pipe.wire,'inspect_account',return_value=account):
|
|
if reject:
|
|
try:pipe.bind_setup_return(123,'0x1401dfad3' if reject=='caller' else None)
|
|
except ValueError:pass
|
|
else:raise AssertionError(reject)
|
|
assert not memory.writes
|
|
assert (root/'runtime/engine-pipe-bind-rejection.json').exists()
|
|
continue
|
|
pipe.bind_setup_return(123,None)
|
|
assert memory.u64(memory.pipe)==memory.data+184
|
|
assert struct.unpack('<10Q',memory.read(memory.data+176,80))==(0x145001000,0x180002000,0x180002100,*pipe.METHODS[2:])
|
|
memory.put(memory.data+72,struct.pack('<Q',(12<<32)|0x420003))
|
|
trace_count=34
|
|
memory.put(memory.data+80+4*pipe.COUNTERS.index('trace_count'),struct.pack('<I',trace_count))
|
|
for sequence in range(trace_count):
|
|
slot=sequence%32;row=struct.pack('<3I',2,0x1000+sequence,sequence)
|
|
memory.put(memory.data+256+slot*12,row)
|
|
assert pipe.inspect(123)['world_auth']==0
|
|
inspected=pipe.inspect(123)
|
|
assert inspected['hotfix']['queries']==2 and inspected['hotfix']['reply_bytes']==400
|
|
assert inspected['movement_failure']['flags_lo']==0x2801
|
|
assert inspected['movement_failure']['result']==-2
|
|
assert inspected['motion']['sent']==3
|
|
assert inspected['motion']['rows'][0]['destination']==[4,5,6]
|
|
assert inspected['entities']['server_creatures']==1
|
|
assert inspected['entities']['actors'][0]['entry']==9010
|
|
# ABI2 has no appended source-field ring. Both ordinary and
|
|
# field-only inspection must remain read-only usable fallbacks.
|
|
memory.put(0x18000a000,struct.pack('<12I',2,41008,1,1,0,1,0,0,0,0,1,0))
|
|
fallback=pipe.inspect(123);assert fallback['entities']['actors'][0]['entry']==9010 and 'source_unit_fields' not in fallback
|
|
field_only=pipe.inspect(123,unit_fields_only=True)
|
|
assert field_only['unit_fields_only'] and 'entities' not in field_only and 'source_unit_fields' not in field_only
|
|
assert inspected['world']['realm_context_bound']
|
|
assert inspected['world']['self_create_queued']
|
|
assert inspected['world']['active_mover_queued']
|
|
assert inspected['world']['movement_request']
|
|
assert not inspected['world']['active_mover_request']
|
|
assert not inspected['world']['movement_rejected']
|
|
assert not inspected['world']['move_init_active_mover_complete']
|
|
assert not inspected['world']['move_init_active_mover_bad_size']
|
|
memory.put(memory.data+0x2000+44,struct.pack('<I',256))
|
|
observed=pipe.inspect(123)['world']
|
|
assert observed['move_init_active_mover_complete']
|
|
assert not observed['move_init_active_mover_bad_size']
|
|
memory.put(memory.data+0x2000+44,struct.pack('<I',512))
|
|
malformed=pipe.inspect(123)['world']
|
|
assert not malformed['move_init_active_mover_complete']
|
|
assert malformed['move_init_active_mover_bad_size']
|
|
assert inspected['last_unsupported_out']==dict(opcode=0x420003,bytes=12)
|
|
assert len(inspected['trace'])==32
|
|
assert inspected['trace'][0]==dict(direction=2,opcode=0x1002,bytes=2)
|
|
assert inspected['trace'][-1]==dict(direction=2,opcode=0x1021,bytes=33)
|
|
pipe.restore(123,'0x1401dfad3')
|
|
assert memory.u64(memory.pipe)==pipe.TABLE
|
|
assert json.loads((root/'runtime/engine-pipe-binding.json').read_text())['restored']
|
|
# Cleanup can destroy the original pipe. Restore must not dereference it.
|
|
memory=Memory()
|
|
with patch.object(pipe,'ROOT',root),patch.object(pipe.host,'Access',return_value=memory),patch.object(pipe.wire,'module',return_value=(0x180000000,{'exports':exports},{})),patch.object(pipe.wire,'inspect_account',return_value=dict(state=2,server_proof_verified=1,transport_prepared=1)):
|
|
pipe.bind_setup_return(123,None);memory.put(memory.holder,q(0));memory.writes.clear()
|
|
pipe.restore(123,'0x1401dfad3');assert memory.writes==[(memory.data+8,4)]
|
|
print('Complete pipe clone, proof/ownership/type gates, public-only counters and freed-pipe-safe rollback verified.')
|
|
metadata=bytearray(256);struct.pack_into('<4I',metadata,0,1,256,1,2)
|
|
struct.pack_into('<6I',metadata,16,10,8,0,60,2,0)
|
|
public=pipe.decode_roster_diagnostics(metadata)
|
|
assert public['overall_reason']==2 and public['rows']==[dict(race=10,class_id=8,gender=0,level=60,reason=2)]
|
|
assert not public['names_or_guids_read'] and set(public['rows'][0])=={'race','class_id','gender','level','reason'}
|
|
for offset,value in ((0,3),(4,255),(8,256),(12,7),(36,1)):
|
|
changed=bytearray(metadata);struct.pack_into('<I',changed,offset,value)
|
|
try:pipe.decode_roster_diagnostics(changed);raise AssertionError('Invalid diagnostic metadata accepted')
|
|
except ValueError:pass
|
|
print('Credential-free roster metadata decoder rejects malformed ABI/reason/reserved fields; no client reads.')
|
|
struct.pack_into('<I',metadata,0,2);struct.pack_into('<I',metadata,36,29)
|
|
public=pipe.decode_roster_diagnostics(metadata)
|
|
assert public['abi']==2 and public['rows']==[dict(race=10,class_id=8,gender=0,level=60,reason=2,preview_race=29)]
|
|
for preview in (0,27,29):
|
|
struct.pack_into('<I',metadata,36,preview)
|
|
assert pipe.decode_roster_diagnostics(metadata)['rows'][0]['preview_race']==preview
|
|
struct.pack_into('<I',metadata,36,256)
|
|
try:pipe.decode_roster_diagnostics(metadata);raise AssertionError('Oversized preview race accepted')
|
|
except ValueError:pass
|
|
print('ABI2 preview race is distinct from source race and strict compatibility; legacy ABI1 remains readable.')
|
|
|
|
check_world_failure_reader()
|
|
|
|
# Corpse rows extend the actor-kind set without claiming them as gameobjects.
|
|
h=struct.pack('<12I',1,10288,0,0,0,0,0,0,0,0,1,0)
|
|
b=struct.pack('<Q16s4I',0xf101000000000001,bytes(16),0,7,1,0)
|
|
r=pipe.decode_entity_page(h,b)
|
|
assert r['actors'][0]['kind']==7 and r['sent_gameobjects']==0
|
|
try:pipe.decode_entity_page(h,struct.pack('<Q16s4I',1,bytes(16),0,6,1,0))
|
|
except ValueError:pass
|
|
else:raise AssertionError('Unsupported actor kind accepted')
|