883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
77 lines
5.4 KiB
Python
77 lines
5.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Independently parse the import patch and Windows unwind/relocation tables.
|
|
No game launch, file installation, auth bypass or real-client compatibility claim.
|
|
"""
|
|
from pathlib import Path
|
|
import struct,sys,shutil
|
|
try:import pefile,capstone
|
|
except ImportError:
|
|
print('SKIP: optional local PE audit requires pefile');sys.exit(77)
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0,str(ROOT/'ops'))
|
|
from native_pe_bridge import add_import,add_imports,build,sha,ORIGINAL,fast_pe,validate_bridge_imports,validate_adapter_locations
|
|
if not Path('/mnt/Games/Games/WoW-Forever/_classic_beta_/WowB.exe').exists() or not shutil.which('clang') or not shutil.which('lld-link'):
|
|
print('SKIP: optional audit requires installed Forever and Windows-target compiler/linker');sys.exit(77)
|
|
assert sha(Path('/mnt/Games/Games/WoW-Forever/_classic_beta_/WowB.exe').read_bytes())==ORIGINAL
|
|
validate_adapter_locations(Path('/mnt/Games/Games/WoW-Forever/_classic_beta_/WowB.exe').read_bytes())
|
|
source=Path.home()/'Projects/WoW-Hybrid/wine-forever/drive_c/windows/system32/d3d11.dll'
|
|
if not source.exists():print('SKIP: optional PE audit requires the original Wine DXVK dependency');sys.exit(77)
|
|
baseline=source.read_bytes()
|
|
before=fast_pe(baseline);patched=add_import(baseline);after=fast_pe(patched)
|
|
old_imports=before.DIRECTORY_ENTRY_IMPORT;new_imports=after.DIRECTORY_ENTRY_IMPORT
|
|
assert len(new_imports)==len(old_imports)+1
|
|
for old,new in zip(old_imports,new_imports):
|
|
assert tuple(getattr(old.struct,k) for k in ('OriginalFirstThunk','TimeDateStamp','ForwarderChain','Name','FirstThunk'))==tuple(getattr(new.struct,k) for k in ('OriginalFirstThunk','TimeDateStamp','ForwarderChain','Name','FirstThunk'))
|
|
assert [(x.name,x.ordinal,x.address) for x in old.imports]==[(x.name,x.ordinal,x.address) for x in new.imports]
|
|
assert new_imports[-1].dll==b'GWNativeBridge.dll'
|
|
assert [i.name for i in new_imports[-1].imports]==[b'gw_bridge_abi']
|
|
assert after.verify_checksum()
|
|
assert tuple(getattr(before.OPTIONAL_HEADER.DATA_DIRECTORY[4],k) for k in ('VirtualAddress','Size'))==tuple(getattr(after.OPTIONAL_HEADER.DATA_DIRECTORY[4],k) for k in ('VirtualAddress','Size'))
|
|
# Every original file byte remains identical except the four explicit header
|
|
# fields and one formerly empty section header. No original code/data edits.
|
|
allowed=set()
|
|
for off,size in ((before.FILE_HEADER.get_field_absolute_offset('NumberOfSections'),2),
|
|
(before.OPTIONAL_HEADER.get_field_absolute_offset('SizeOfImage'),4),
|
|
(before.OPTIONAL_HEADER.get_field_absolute_offset('CheckSum'),4),
|
|
(before.OPTIONAL_HEADER.DATA_DIRECTORY[1].get_file_offset(),8),
|
|
(before.sections[-1].get_file_offset()+40,40)):
|
|
allowed.update(range(off,off+size))
|
|
position=0
|
|
for offset in sorted(allowed):
|
|
assert baseline[position:offset]==patched[position:offset]
|
|
position=offset+1
|
|
assert baseline[position:]==patched[position:len(baseline)]
|
|
try:add_import(patched)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Repeated patch accepted')
|
|
# The optional wire DLL must preserve every original import and header boundary.
|
|
combined=fast_pe(add_imports(baseline,(("GWNativeBridge.dll","gw_bridge_abi"),("GWNativeWire.dll","gw_wire_abi"))))
|
|
assert [row.dll for row in combined.DIRECTORY_ENTRY_IMPORT]==[row.dll for row in old_imports]+[b'GWNativeBridge.dll',b'GWNativeWire.dll']
|
|
for old,new in zip(old_imports,combined.DIRECTORY_ENTRY_IMPORT):
|
|
assert [(x.name,x.ordinal,x.address) for x in old.imports]==[(x.name,x.ordinal,x.address) for x in new.imports]
|
|
for invalid in ((),(("other.dll","entry"),),(("GWNativeWire.dll","wrong_entry"),),(("GWNativeBridge.dll","gw_bridge_abi"),)*2):
|
|
try:add_imports(baseline,invalid)
|
|
except ValueError:pass
|
|
else:raise AssertionError('Unknown or duplicate dependency accepted')
|
|
binary,exports=build();dll=pefile.PE(data=binary)
|
|
callback=exports['gw_bridge_callback']
|
|
assert any(row.struct.BeginAddress<=callback<row.struct.EndAddress for row in dll.DIRECTORY_ENTRY_EXCEPTION)
|
|
assert any(row.type==10 for block in dll.DIRECTORY_ENTRY_BASERELOC for row in block.entries)
|
|
validate_bridge_imports(dll)
|
|
for name in ('gw_bridge_callback','gw_registration_get_state'):
|
|
assert any(row.struct.BeginAddress<=exports[name]<row.struct.EndAddress for row in dll.DIRECTORY_ENTRY_EXCEPTION)
|
|
assert dll.OPTIONAL_HEADER.AddressOfEntryPoint==0
|
|
assert exports['gw_bridge_data']!=callback
|
|
data_rva=exports['gw_poll_host_data']
|
|
assert struct.unpack('<II',dll.get_data(data_rva,8))==(1,1080)
|
|
decoder=capstone.Cs(capstone.CS_ARCH_X86,capstone.CS_MODE_64)
|
|
instructions=[]
|
|
for instruction in decoder.disasm(dll.get_data(exports['gw_poll_host_callback'],160),exports['gw_poll_host_callback']):
|
|
if instruction.mnemonic=='int3':break
|
|
instructions.append(instruction)
|
|
assert instructions and not any(i.mnemonic=='call' or 'rsp' in i.op_str for i in instructions)
|
|
assert any(i.mnemonic=='jmp' and (i.op_str=='rax' or i.op_str.startswith('qword ptr [rip')) for i in instructions)
|
|
assert struct.unpack('<II',dll.get_data(exports['gw_packet_host_data'],8))==(1,16440)
|
|
assert any(row.struct.BeginAddress<=exports['gw_packet_poll_callback']<row.struct.EndAddress for row in dll.DIRECTORY_ENTRY_EXCEPTION)
|
|
print('Original IATs/code/certificate bytes preserved; new dependency, checksum, Windows callback unwind and relocation tables verified. Signature is intentionally invalid for the experimental derivative.')
|