Files
pbz-cppbypass/tools/verify_build.py
T
KintaroModding 78fc79b9d9 Support UE4SS v4.0.0 in bypass 1.2
UE4SS v4.0.0 (commit 30afe5ff) is the first official release since the
1195 build this mod was made for. The two are 36 commits apart, and none of
them touches the C++ mod interface: the pinned SDK headers are byte-identical
at both commits, and all 17 UE4SS functions the mod imports exist in both
DLLs. So one DLL serves both builds.

- build_profile.hpp: the single UE4SS hash becomes a list of verified
  builds, v4.0.0 (3843d81a..., the official release zip) and
  v3.0.1-1195-g1ceefac8 (e1fb9a7e...).
- compatibility.cpp: the startup check accepts a DLL from that list, logs
  "Verified UE4SS <build>", and still refuses any other UE4SS.dll.
- verify_build.py: checks the given UE4SS.dll against the list and records
  which build it is.
- prepare_sdk.py: pinned to v4.0.0; the regenerated headers are unchanged,
  only PROVENANCE.txt names the new commit.
- Version 1.2; README, mod.json and the openmods files name both builds.

Built with warnings as errors; the native hook test passes; verify_build.py
passes against the game's PBZ.exe with either UE4SS.dll and refuses a wrong
one. Not yet tested in game on v4.0.0.
2026-11-13 01:23:21 +01:00

75 lines
3.7 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'
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')