#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-or-later """Derive the W^X linker script and build the offline Phase-1.0DQ ELF.""" from __future__ import annotations import argparse,hashlib,subprocess from pathlib import Path SDK_SCRIPT_SHA256="3bacf56a21602a1298752023a4c5b0c305954ddf6cdbce1464476fc9da9d9093" def main(): p=argparse.ArgumentParser();p.add_argument("--root",type=Path,required=True);a=p.parse_args();root=a.root.resolve();sdk=root/"work/toolchains/ps5-payload-sdk-v0.41";source_script=sdk/"target/lib/main.script";raw=source_script.read_bytes() if hashlib.sha256(raw).hexdigest()!=SDK_SCRIPT_SHA256:raise SystemExit("SDK linker script identity mismatch") text=raw.decode();needle="ph_text PT_LOAD FLAGS (0x7);" if text.count(needle)!=1:raise SystemExit("SDK text PHDR differs") out=root/"build/phase10dq";out.mkdir(parents=True,exist_ok=True);script=out/"observer-wx.script";script.write_text(text.replace(needle,"ph_text PT_LOAD FLAGS (0x5);"),newline="\n") source=root.parent/"chimera-retroarch/pkg/ps5/chimera_ps5_fake00000_inventory_observer.c";artifact=out/"chimera_fake00000_inventory_observer.elf";linkmap=out/"chimera_fake00000_inventory_observer.map" if not source.is_file():raise SystemExit("target source missing") def wsl(path):return "/mnt/c/"+path.as_posix().split(":/",1)[1] command=f"set -euo pipefail; '{wsl(sdk)}/bin/prospero-clang' -std=c11 -Wall -Wextra -Werror -O2 -fno-common -Wl,-T,'{wsl(script)}' -Wl,-Map,'{wsl(linkmap)}' -o '{wsl(artifact)}' '{wsl(source)}'" subprocess.run(["wsl.exe","bash","-lc",command],check=True) return 0 if __name__=="__main__":raise SystemExit(main())