367 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
17 lines
1.2 KiB
Python
17 lines
1.2 KiB
Python
"""Exact two-byte PE profile for the existing fixed-address native contracts."""
|
|
import hashlib,struct
|
|
from pathlib import Path
|
|
PIN='c49ce22c3e0aaeb7a7007a5c5cb792e4c3e6cdecc55a1145a5933fc113e3e57f'
|
|
def source_bytes(raw):
|
|
raw=bytes(raw)
|
|
if hashlib.sha256(raw).hexdigest()==PIN:return raw
|
|
pe=struct.unpack_from('<I',raw,0x3c)[0];offset=pe+24+70
|
|
if struct.unpack_from('<H',raw,pe+24)[0]!=0x20b or struct.unpack_from('<Q',raw,pe+48)[0]!=0x140000000 or struct.unpack_from('<H',raw,offset)[0]!=0x8100:raise ValueError('Unsupported Windows image profile')
|
|
restored=bytearray(raw);struct.pack_into('<H',restored,offset,0x8160)
|
|
if hashlib.sha256(restored).hexdigest()!=PIN:raise ValueError('Windows image differs beyond its exact PE relocation profile')
|
|
return bytes(restored)
|
|
def prepare(path):
|
|
path=Path(path);raw=path.read_bytes();original=source_bytes(raw);pe=struct.unpack_from('<I',original,0x3c)[0];patched=bytearray(original);struct.pack_into('<H',patched,pe+24+70,0x8100)
|
|
if raw!=patched:path.write_bytes(patched)
|
|
return {'original_sha256':PIN,'patched_sha256':hashlib.sha256(patched).hexdigest(),'preferred_base':'0x140000000','change':'PE DLL characteristics 0x8160 to0x8100; executable instructions unchanged'}
|