A tool for deriving PKG packet encryption keys for ps4 written in c++
| 1 | import os |
| 2 | import shutil |
| 3 | import subprocess |
| 4 | import sys |
| 5 | |
| 6 | # Configure paths |
| 7 | project_root = os.path.abspath(os.path.dirname(__file__)) |
| 8 | build_dir = os.path.join(project_root, "build") |
| 9 | |
| 10 | def run(cmd, cwd=project_root): |
| 11 | print(f"\nRunning: {' '.join(cmd)}\n") |
| 12 | result = subprocess.run(cmd, cwd=cwd) |
| 13 | if result.returncode != 0: |
| 14 | print("Error running command:", ' '.join(cmd)) |
| 15 | sys.exit(result.returncode) |
| 16 | |
| 17 | def check_conan(): |
| 18 | try: |
| 19 | subprocess.run(["conan", "--version"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 20 | except (FileNotFoundError, subprocess.CalledProcessError): |
| 21 | print("Conan not found. Please ensure it is installed and in your PATH.") |
| 22 | print("You can install it with: pip install conan") |
| 23 | sys.exit(1) |
| 24 | |
| 25 | def find_toolchain(search_path): |
| 26 | for root, dirs, files in os.walk(search_path): |
| 27 | if "conan_toolchain.cmake" in files: |
| 28 | return os.path.join(root, "conan_toolchain.cmake") |
| 29 | return None |
| 30 | |
| 31 | if __name__ == "__main__": |
| 32 | |
| 33 | os.makedirs(build_dir, exist_ok=True) |
| 34 | |
| 35 | check_conan() |
| 36 | |
| 37 | # Install dependencies with Conan |
| 38 | # This command is safe to rerun (idempotent if nothing changes) |
| 39 | conan_cmd = [ |
| 40 | "conan", "install", ".", |
| 41 | "--output-folder=build", |
| 42 | "--build=missing", |
| 43 | "-s", "build_type=Release" |
| 44 | ] |
| 45 | run(conan_cmd) |
| 46 | |
| 47 | # Find the toolchain file |
| 48 | toolchain_path = find_toolchain(build_dir) |
| 49 | if not toolchain_path: |
| 50 | print("Error: conan_toolchain.cmake not found after installation.") |
| 51 | sys.exit(1) |
| 52 | |
| 53 | print(f"Toolchain found: {toolchain_path}") |
| 54 | |
| 55 | # Relative path for cmake (or absolute, but cmake expects paths with correct / or \) |
| 56 | # Use absolute path for safety |
| 57 | toolchain_path = toolchain_path.replace("\\", "/") |
| 58 | |
| 59 | # CMake Configuration |
| 60 | cmake_cmd = [ |
| 61 | "cmake", |
| 62 | "-S", ".", |
| 63 | "-B", "build", |
| 64 | f"-DCMAKE_TOOLCHAIN_FILE={toolchain_path}", |
| 65 | "-DCMAKE_BUILD_TYPE=Release", |
| 66 | "-DBUILD_GUI=ON" |
| 67 | ] |
| 68 | |
| 69 | # Add -DCMAKE_POLICY_DEFAULT_CMP0091=NEW to correctly handle MSVC runtime with Conan |
| 70 | if sys.platform == "win32": |
| 71 | cmake_cmd.append("-DCMAKE_POLICY_DEFAULT_CMP0091=NEW") |
| 72 | |
| 73 | run(cmake_cmd) |
| 74 | |
| 75 | # Build |
| 76 | build_cmd = [ |
| 77 | "cmake", |
| 78 | "--build", "build", |
| 79 | "--config", "Release" |
| 80 | ] |
| 81 | run(build_cmd) |
| 82 | |
| 83 | print("\nBuild completed successfully!") |
| 84 |