367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
231 lines
13 KiB
Python
231 lines
13 KiB
Python
#!/usr/bin/env python3
|
|
"""Reproduce fixed lifecycle contracts from existing pinned executable captures.
|
|
|
|
Offline only: no process reads, account data, engine calls or executable writes.
|
|
Addresses are evidence, not a callable interface. Missing/deviating code fails
|
|
closed rather than proposing a guessed vtable or state transition.
|
|
"""
|
|
import argparse
|
|
import os
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import struct
|
|
import capstone
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
BASE=0x140000000
|
|
PIN='c49ce22c3e0aaeb7a7007a5c5cb792e4c3e6cdecc55a1145a5933fc113e3e57f'
|
|
|
|
def audit():
|
|
image=(ROOT/'runtime/native-client/_classic_beta_/WowB.exe').read_bytes()
|
|
if os.name=='nt':
|
|
from windows_image_profile import source_bytes
|
|
image=source_bytes(image)
|
|
if hashlib.sha256(image).hexdigest()!=PIN:raise ValueError('Pinned image identity differs')
|
|
pe=struct.unpack_from('<I',image,0x3c)[0]
|
|
count=struct.unpack_from('<H',image,pe+6)[0]
|
|
optional=struct.unpack_from('<H',image,pe+20)[0]
|
|
sections=[struct.unpack_from('<4I',image,pe+24+optional+i*40+8) for i in range(count)]
|
|
def image_read(address,size):
|
|
rva=address-BASE
|
|
for _,start,length,offset in sections:
|
|
if start<=rva and rva+size<=start+length:return image[offset+rva-start:offset+rva-start+size]
|
|
raise ValueError('Fixed image range unavailable')
|
|
decoder=capstone.Cs(capstone.CS_ARCH_X86,capstone.CS_MODE_64)
|
|
pages={};checks=[]
|
|
def instruction(address,mnemonic,operands):
|
|
page=address&~4095
|
|
if page not in pages:
|
|
path=ROOT/'runtime/native-handler-code'/f'{page:x}.bin'
|
|
if not path.exists():path=ROOT/'runtime/native-netclient'/f'live-{page-BASE:x}.bin'
|
|
data=path.read_bytes()
|
|
if len(data)!=4096:raise ValueError('Expected fixed executable page')
|
|
pages[page]=data
|
|
raw=pages[page][address-page:address-page+15]
|
|
item=next(decoder.disasm(raw,address,count=1),None)
|
|
if not item or (item.mnemonic,item.op_str)!=(mnemonic,operands):
|
|
raise ValueError('Saved lifecycle instruction differs at '+hex(address))
|
|
checks.append({'address':hex(address),'instruction':mnemonic+' '+operands})
|
|
for spec in (
|
|
(0x141e4e975,'call','0x1445b7db0'),
|
|
(0x141e47a68,'call','0x1445b7db0'),
|
|
(0x141e46d71,'mov','edx, 0x10'),
|
|
(0x141e46d81,'call','0x1445b8b30'),
|
|
(0x141e46dbc,'mov','dword ptr [rbx + 0x30], 0x10'),
|
|
(0x141e48fc7,'mov','qword ptr [rsi + rax*8 + 0x1a0], r14'),
|
|
(0x141e4914f,'mov','byte ptr [rax + rsi + 0x218], r12b'),
|
|
(0x141e4918b,'movzx','r8d, byte ptr [rdi + 0x10]'),
|
|
(0x141e49190,'lea','rdx, [rdi + 0x18]'),
|
|
(0x141e49198,'mov','rcx, rsi'),
|
|
(0x141e4919b,'call','0x141e46a80'),
|
|
(0x141e491a0,'mov','rcx, rdi'),
|
|
(0x141e491a3,'call','0x141e4e950'),
|
|
(0x141e491a8,'xor','r9d, r9d'),
|
|
(0x141e491b2,'mov','r8d, 0xfffffffe'),
|
|
(0x141e491b8,'mov','rcx, rdi'),
|
|
(0x141e491bb,'call','0x14452a5d0'),
|
|
(0x141e4e9bc,'mov','rax, rbx'),
|
|
(0x141e53eac,'je','0x141e53f02'),
|
|
(0x141e53efa,'call','qword ptr [rax + 0x38]'),
|
|
(0x141e53eec,'call','qword ptr [rax + 0x40]'),
|
|
(0x141e53ede,'call','qword ptr [rax + 0x48]'),
|
|
(0x141e53ec6,'mov','byte ptr [rbx + 0xac], cl'),
|
|
(0x141e46086,'mov','dword ptr [rdi + 0x98], 4'),
|
|
(0x141e460df,'call','0x141e448c0'),
|
|
(0x141e4627f,'call','0x141e4aca0'),
|
|
(0x141e47b4d,'cmp','edi, 4'),
|
|
(0x141e47c13,'mov','dword ptr [rbx + 0x98], 5'),
|
|
(0x141e47e1a,'mov','dword ptr [rbx + 0x98], 2'),
|
|
(0x141e47f4f,'mov','dword ptr [rbx + 0x98], 2'),
|
|
(0x1422bcc44,'call','0x141e47b20'),
|
|
(0x1422bcec9,'call','rax'),
|
|
(0x14224df93,'mov','byte ptr [rcx + 0x7e8], 1'),
|
|
(0x14224e18b,'lea','rdx, [r14 + 0x30]'),
|
|
(0x14224e18f,'lea','rcx, [r13 + 0x838]'),
|
|
(0x14224e196,'call','0x140855bc0'),
|
|
(0x14224e1bb,'mov','rdx, qword ptr [r14 + 0x50]'),
|
|
(0x141e4b4e5,'mov','rbx, qword ptr [rax + 0x38]'),
|
|
(0x141e4b500,'call','rbx'),
|
|
(0x141e45218,'mov','qword ptr [rax + 8], rbx'),
|
|
(0x141e4522b,'mov','qword ptr [rbx + 0x220], rax'),
|
|
(0x141e44a9e,'mov','qword ptr [rbx + 0x28], rbp'),
|
|
(0x1434dc098,'mov','rax, qword ptr [rcx]'),
|
|
(0x1434dc09b,'call','qword ptr [rax + 0x10]'),
|
|
(0x141e43825,'mov','edx, 0x13'),
|
|
(0x141e43834,'call','0x141e54190'),
|
|
(0x141e43af2,'mov','edx, 0x14'),
|
|
(0x141e43afc,'call','0x141e54190'),
|
|
(0x14216e1b0,'lea','rax, [rip + 0x35dd039]'),
|
|
(0x14216e1b7,'ret',''),
|
|
(0x14224deb6,'mov','rax, qword ptr [rip + 0x5a16f23]'),
|
|
(0x14224decb,'call','rax'),
|
|
(0x14224ded7,'call','0x1445b8330'),
|
|
(0x1422bf09d,'mov','qword ptr [rsi + 0xc90], rbx'),
|
|
(0x1422bd5de,'cmp','qword ptr [rbx + 0xc90], 0'),
|
|
(0x1422bd5ec,'mov','rax, qword ptr [rbx + 0xca8]'),
|
|
(0x1422bd616,'call','0x142414e80'),
|
|
(0x1422bd622,'mov','qword ptr [rbx + 0xc90], 0'),
|
|
(0x1422bd644,'mov','byte ptr [rbx + 0xca0], 1'),
|
|
(0x140225b11,'cmp','byte ptr [rip + 0x54da561], 0'),
|
|
(0x140225b18,'movzx','r8d, byte ptr [rip + 0x5dd4a39]'),
|
|
(0x140225b2b,'cmp','qword ptr [rip + 0x5ddf375], 0'),
|
|
(0x140225b3d,'cmp','qword ptr [rip + 0x54ede7b], 0'),
|
|
(0x140225b4e,'cmp','byte ptr [rip + 0x5c48e21], 0'),
|
|
(0x140225b61,'call','0x1422bb300'),
|
|
(0x1422bb306,'mov','ebx, dword ptr [rip + 0x3bf1f04]'),
|
|
(0x1422bb34d,'movzx','eax, byte ptr [rip + 0x3bb6da4]'),
|
|
(0x1422bbec0,'mov','rsi, rdx'),
|
|
(0x1422bbf7c,'movups','xmm0, xmmword ptr [rsi]'),
|
|
(0x1422bbf83,'movups','xmmword ptr [r14 + 8], xmm0'),
|
|
(0x1422bc0e3,'call','0x141e4f4b0'),
|
|
(0x1422bc15f,'call','0x141e46020'),
|
|
(0x142175f50,'call','0x1422bbe90'),
|
|
(0x141e4f606,'call','0x140917ab0'),
|
|
(0x141e4f60b,'movzx','eax, word ptr [rbx + 0x18]'),
|
|
(0x141e4f620,'add','rsi, 0xa0'),
|
|
(0x140917acc,'mov','edx, dword ptr [rdx + 0x10]'),
|
|
(0x140917af0,'movups','xmm0, xmmword ptr [rbx]'),
|
|
(0x140917af8,'mov','eax, dword ptr [rbx]'),
|
|
(0x1408e49c8,'call','0x1407fe7f0'),
|
|
(0x1407fe90b,'call','0x1407fd9e0'),
|
|
(0x1407fdca0,'mov','byte ptr [r15 + 0x164], al'),
|
|
(0x1423f99e7,'mov','dword ptr [rip + 0x3ab3823], edi'),
|
|
(0x1423f99f7,'mov','byte ptr [rip + 0x3a74f78], 1'),
|
|
(0x141e4ca8b,'movsxd','r12, r8d'),
|
|
(0x141e4caa8,'shl','rax, 5'),
|
|
(0x141e4cafe,'mov','eax, dword ptr [rcx]'),
|
|
(0x141e4d13f,'mov','rbx, qword ptr [rdx]'),
|
|
(0x141e4d149,'mov','r15d, dword ptr [rdx + 0x10]'),
|
|
(0x14091e6e0,'mov','eax, 0x10'),
|
|
(0x1409e95f0,'mov','eax, 0x20'),
|
|
(0x141e4e8fd,'mov','r8d, 0x2220'),
|
|
(0x141e4deb0,'mov','rax, qword ptr [rcx]'),
|
|
(0x141e460f3,'mov','r8, qword ptr [rbx]'),
|
|
(0x141e460f6,'mov','rdx, rdi'),
|
|
(0x141e460f9,'mov','rcx, rax'),
|
|
(0x141e460fc,'call','0x141e446f0'),
|
|
(0x141e44712,'mov','qword ptr [rbx], rbp'),
|
|
(0x141e44722,'call','qword ptr [rax + 0x18]'),
|
|
(0x141e448a9,'mov','qword ptr [rax + 8], rdi'),
|
|
(0x141e433e4,'mov','rsi, r9'),
|
|
(0x1434dbf2a,'mov','r13, qword ptr [rax + 8]'),
|
|
(0x1434dbfe3,'mov','r9, qword ptr [rsp + 0x68]'),
|
|
(0x1434dbfe8,'mov','r8, rdi'),
|
|
(0x1434dbfeb,'mov','rdx, rsi'),
|
|
(0x1434dbfee,'mov','rcx, r15'),
|
|
(0x1434dbff1,'call','r13'),
|
|
(0x141e4cfc8,'mov','rax, qword ptr [rcx]'),
|
|
(0x141e4cfcb,'call','qword ptr [rax + 0x90]'),
|
|
(0x141e4d0c8,'or','byte ptr [rsi + 0x2248], 4'),
|
|
(0x141e47150,'cmp','esi, 4'),
|
|
(0x141e471cd,'cmp','eax, 6'),
|
|
(0x141e4f4c8,'cmp','qword ptr [rdx + 0x10], rsi'),
|
|
(0x141e4f4cc,'jl','0x141e4f509'),
|
|
(0x141e4f4eb,'movabs','rax, 0x8000000000000000'),
|
|
(0x141e4f4f9,'mov','qword ptr [rdx], rsi'),
|
|
(0x141e4f61b,'call','0x140885f60'),
|
|
):instruction(*spec)
|
|
vtable=0x144efa998
|
|
slots={0x30:0x141e47960,0x38:0x1422bcb40,0x40:0x1422bc740,
|
|
0x48:0x1422bd130,0x50:0x14224deb0,0x58:0x1422be450,0x78:0x1422bee30}
|
|
for offset,expected in slots.items():
|
|
if struct.unpack('<Q',image_read(vtable+offset,8))[0]!=expected:raise ValueError('Pinned ClientConnection vtable differs')
|
|
listener=0x144e5a748
|
|
listener_slots={0x8:0x141e43370,0x10:0x141e43ba0,0x18:0x141e43870,0x20:0x141e43280}
|
|
for offset,expected in listener_slots.items():
|
|
if struct.unpack('<Q',image_read(listener+offset,8))[0]!=expected:raise ValueError('Pinned transport-listener vtable differs')
|
|
pipe_slots={0:0x141e4ca60,8:0x141e4d120,0x10:0x1401d9200,0x18:0x141e4e8e0,
|
|
0x20:0x14091e6e0,0x28:0x1409e95f0,0x30:0x141e4c8f0,0x38:0x141e4c9e0,0x40:0x141e4ca20}
|
|
for offset,expected in pipe_slots.items():
|
|
if struct.unpack('<Q',image_read(0x144e59fe8+offset,8))[0]!=expected:raise ValueError('Pinned TCP packet-pipe vtable differs')
|
|
return {'kind':'offline-pinned-engine-lifecycle-contract','image_sha256':PIN,
|
|
'engine_calls_made':False,'native_engine_adoption_proven':False,
|
|
'client_connection_vtable':hex(vtable),
|
|
'vtable_slots':{hex(k):hex(v) for k,v in slots.items()},
|
|
'transport_listener':{'netclient_field':'0x220','vtable':hex(listener),
|
|
'owner_field':'0x8','tcp_wrapper_listener_field':'0x28',
|
|
'vtable_slots':{hex(k):hex(v) for k,v in listener_slots.items()}},
|
|
'tcp_packet_pipe':{'vtable':'0x144e59fe8','owner_offset':8,'connection_offset':16,
|
|
'holder_field_offset':'0x228','holder_field_is_indirect':True,
|
|
'holder_getter':'0x141e4de60','setup':'0x141e446f0',
|
|
'setup_arguments':['holder pointed to by owner+0x228','owner','actual connection'],
|
|
'setup_releases_previous_pipe_via_virtual':'0x18',
|
|
'write_descriptor_stride':32,'write_count_argument':'R8D','read_length_offset':16,
|
|
'vtable_slots':{hex(k):hex(v) for k,v in pipe_slots.items()},
|
|
'replacement_interface_fully_validated':False},
|
|
'world_auth_data_provider':{'callback_slot':'0x147c64de0','observed_function':'0x14216e1b0',
|
|
'returns_owned_string_at':'0x14574b1f0','data_buffer_read':False,
|
|
'consumer':'0x14224deb0','writer_reference':'0x14217551f'},
|
|
'character_list_consumption':{'typed_handler':'0x1422bee30','owned_pending_field':'0xc90',
|
|
'poll':'0x1422bd580','readiness_callback_field':'0xca8','consumer':'0x142414e80',
|
|
'consumed_marker_field':'0xca0','readiness_predicate':'0x140225b00'},
|
|
'realm_context_adoption':{'candidate':'0x1422bbe90','saved_caller':'0x142175f50',
|
|
'first_context_copy_bytes':'0x68','realm_properties_source_offset':'0x68',
|
|
'address_vector_source_offset':'0x1b0','open_realm_call':'0x1422bc15f',
|
|
'argument_layout_fully_validated':False,'account_session_region_read':False,
|
|
'address_elements':{'stride':'0xa0','tag_offset':'0x10','port_field_offset':'0x18',
|
|
'copy_routine':'0x140917ab0','pointer_variant_unverified':True},
|
|
'vector_transfer':{'function':'0x141e4f4b0','owned_source_storage_moved':True,
|
|
'borrowed_source_deep_copied':True,'borrowed_capacity_bit':63}},
|
|
'glue_feature_readiness':{'wire_opcode':'0x470064','constructor':'0x1407fe7f0',
|
|
'reader':'0x1407fd9e0','handler':'0x1423f9440','phase_global':'0x145ead210',
|
|
'initialized_global':'0x145e6e976','account_authentication_implied':False},
|
|
'queue_events':{'0x12':{'virtual_offset':'0x30','meaning':'packet'},
|
|
'0x13':{'virtual_offset':'0x38','meaning':'connected'},
|
|
'0x14':{'virtual_offset':'0x40','meaning':'disconnected'},
|
|
'0x15':{'virtual_offset':'0x48','meaning':'connect-failed'},
|
|
'0x16':{'field_offset':'0xac','meaning':'destruction-marker'}},
|
|
'checked_instructions':checks,
|
|
'code_pages':{hex(k):hashlib.sha256(v).hexdigest() for k,v in sorted(pages.items())}}
|
|
|
|
def main():
|
|
parser=argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--output',type=Path,default=ROOT/'runtime/native-lifecycle-contract.json')
|
|
args=parser.parse_args()
|
|
output=args.output.resolve()
|
|
if not output.is_relative_to(ROOT/'runtime'):raise ValueError('Private audit output must stay in runtime')
|
|
result=audit();output.write_text(json.dumps(result,indent=2)+'\n');output.chmod(0o600)
|
|
print('Verified pinned lifecycle instructions, vtable slots and event mapping; no engine calls.')
|
|
if __name__=='__main__':main()
|