Files
pbz-cppbypass/tools/verify_build.py
T
KintaroModding 434f11d743 Allow additional project JavaScript and JSON modules in bypass 1.1
Normalize unlisted module paths with the game's pinned helper and release its
FString output with the matching allocator. Keep engine and outside paths on
original validation, log additional accepted modules, and test malformed paths
and allocation cleanup through the production adapters.

Update scope documentation and keep earlier gameplay results separate from a
new DLL's pending game test. Native tests and offline verification pass.
2026-11-04 17:20:13 +01:00

72 lines
3.5 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={}
for key,path in [('game',args.game),('ue4ss',args.ue4ss)]:
digest=hashlib.sha256(path.read_bytes()).hexdigest()
expected=re.search(rf'{key}_sha256\[\] = "([0-9a-f]+)"',profile)[1]
assert digest==expected,(key,'SHA mismatch')
report[key+'_sha256']=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'
prologues.write_bytes(game.get_data(0x62f65a0,64)+game.get_data(0x62f65e0,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')