The 2026-11-28 patch (Steam build 26936481, CL-304629_JKS-17496) moved every pinned function and shrank the script table from 241 to 221 rows (198 project scripts). The byte validator is unchanged; the lookup, text validator, normalizer and free helper only changed their relative calls. - build_profile.hpp: new exe hash, image size, timestamp, RVAs, counts and function digests. - verify_build.py reads the validator RVAs from the profile instead of fixed numbers. - Version 1.3; README, openmods files and mod.json name the new build. Offline: native tests and verify_build.py pass against the new PBZ.exe with UE4SS v4.0.0. The in-game test is pending.
76 lines
3.8 KiB
Python
76 lines
3.8 KiB
Python
"""Read-only verification against the user's supplied executables."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
sys.path.insert(0,str(Path(__file__).parent/'python'))
|
|
import pefile
|
|
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
parser=argparse.ArgumentParser()
|
|
parser.add_argument('game',type=Path)
|
|
parser.add_argument('ue4ss',type=Path)
|
|
parser.add_argument('--game-test-result', help='Record an observed game-test result; does not launch the game')
|
|
args=parser.parse_args()
|
|
profile=(ROOT/'src/build_profile.hpp').read_text()
|
|
report={}
|
|
digest=hashlib.sha256(args.game.read_bytes()).hexdigest()
|
|
assert digest==re.search(r'game_sha256\[\] = "([0-9a-f]+)"',profile)[1],('game','SHA mismatch')
|
|
report['game_sha256']=digest
|
|
digest=hashlib.sha256(args.ue4ss.read_bytes()).hexdigest()
|
|
ue4ss_builds=dict((sha,name) for name,sha in re.findall(r'\{"([^"]+)", "([0-9a-f]{64})"\}',profile))
|
|
assert digest in ue4ss_builds,('ue4ss','SHA not in ue4ss_builds')
|
|
report['ue4ss_sha256']=digest
|
|
report['ue4ss_build']=ue4ss_builds[digest]
|
|
game=pefile.PE(str(args.game),fast_load=True)
|
|
function_ranges=[]
|
|
for rva,size,digest in re.findall(r'\{0x([0-9a-f]+), 0x([0-9a-f]+), "([0-9a-f]+)"\}',profile):
|
|
rva,size=int(rva,16),int(size,16)
|
|
assert hashlib.sha256(game.get_data(rva,size)).hexdigest()==digest
|
|
report[hex(rva)]={'bytes':size,'sha256':digest}
|
|
function_ranges.append((rva,rva+size))
|
|
game.parse_data_directories(directories=[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_BASERELOC']])
|
|
for block in getattr(game,'DIRECTORY_ENTRY_BASERELOC',[]):
|
|
for reloc in block.entries:
|
|
if reloc.type:
|
|
for start,end in function_ranges:
|
|
assert not start<=reloc.rva<end,'Runtime code digest would require ASLR relocation'
|
|
report['code_digests_are_aslr_independent']=True
|
|
prologues=ROOT/'build/game-prologues.bin'
|
|
bytes_rva,text_rva=(int(re.search(rf'{n}_rva = (0x[0-9a-f]+)',profile)[1],16) for n in ('bytes','text'))
|
|
prologues.write_bytes(game.get_data(bytes_rva,64)+game.get_data(text_rva,64))
|
|
native=subprocess.run([str(ROOT/'build/native_hooks.exe'),str(prologues)],cwd=ROOT,
|
|
capture_output=True,text=True,check=True)
|
|
report['native_tests']=native.stdout.splitlines()
|
|
print(native.stdout,end='')
|
|
dll=ROOT/'dist/ue4ss/Mods/phantombladezero_cppbypass/dlls/main.dll'
|
|
mod=pefile.PE(str(dll),fast_load=True)
|
|
mod.parse_data_directories(directories=[0,1])
|
|
assert mod.FILE_HEADER.Machine==0x8664
|
|
exports={s.name for s in mod.DIRECTORY_ENTRY_EXPORT.symbols if s.name}
|
|
assert exports=={b'start_mod',b'uninstall_mod'}
|
|
ue=pefile.PE(str(args.ue4ss),fast_load=True)
|
|
ue.parse_data_directories(directories=[0])
|
|
ue_exports={s.name for s in ue.DIRECTORY_ENTRY_EXPORT.symbols if s.name}
|
|
for dep in mod.DIRECTORY_ENTRY_IMPORT:
|
|
if dep.dll.lower()==b'ue4ss.dll':
|
|
assert all(i.name in ue_exports for i in dep.imports),'Missing UE4SS import'
|
|
report['verified_ue4ss_imports']=len(dep.imports)
|
|
assert report.get('verified_ue4ss_imports')==17
|
|
report['dll_sha256']=hashlib.sha256(dll.read_bytes()).hexdigest()
|
|
report['dll_bytes']=dll.stat().st_size
|
|
report_path=ROOT/'research/verification.json'
|
|
previous=json.loads(report_path.read_text(encoding='utf-8')) if report_path.exists() else {}
|
|
same_dll=previous.get('dll_sha256')==report['dll_sha256']
|
|
report['game_test']=args.game_test_result or (previous.get('game_test') if same_dll else None) or \
|
|
'PENDING for this DLL; offline verification does not establish gameplay success'
|
|
if not same_dll and previous.get('game_test'):
|
|
report['previous_dll_game_test']={'dll_sha256':previous.get('dll_sha256'),
|
|
'result':previous['game_test']}
|
|
report_path.write_text(json.dumps(report,indent=2)+'\n',encoding='utf-8')
|
|
print('PASS: pinned executable hashes, ASLR-independent code digests, DLL exports and UE4SS imports')
|