A tool for deriving PKG packet encryption keys for ps4 written in c++
| 1 | cmake_minimum_required(VERSION 3.16) |
| 2 | project(shadpkg) |
| 3 | |
| 4 | list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") |
| 5 | |
| 6 | # ╔══════════════════════════════════════════════════════════════════════════╗ |
| 7 | # ║ C++23 required for std::byteswap and modern features ║ |
| 8 | # ╚══════════════════════════════════════════════════════════════════════════╝ |
| 9 | set(CMAKE_CXX_STANDARD 23) |
| 10 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 11 | |
| 12 | # ╔══════════════════════════════════════════════════════════════════════════╗ |
| 13 | # ║ Options ║ |
| 14 | # ╚══════════════════════════════════════════════════════════════════════════╝ |
| 15 | option(BUILD_GUI "Build the GUI application" ON) |
| 16 | |
| 17 | # ╔══════════════════════════════════════════════════════════════════════════╗ |
| 18 | # ║ Find Required Packages ║ |
| 19 | # ╚══════════════════════════════════════════════════════════════════════════╝ |
| 20 | find_package(ZLIB REQUIRED) |
| 21 | find_package(CryptoPP REQUIRED) |
| 22 | find_package(fmt REQUIRED) |
| 23 | find_package(nlohmann_json REQUIRED) |
| 24 | find_package(capstone REQUIRED) |
| 25 | |
| 26 | if(BUILD_GUI) |
| 27 | find_package(imgui REQUIRED) |
| 28 | find_package(glfw3 REQUIRED) |
| 29 | find_package(OpenGL REQUIRED) |
| 30 | endif() |
| 31 | |
| 32 | # ╔══════════════════════════════════════════════════════════════════════════╗ |
| 33 | # ║ Core Library (shared between CLI and GUI) ║ |
| 34 | # ╚══════════════════════════════════════════════════════════════════════════╝ |
| 35 | set(CORE_SOURCES |
| 36 | core/file_format/pkg.cpp |
| 37 | core/file_format/trp.cpp |
| 38 | core/file_format/psf.cpp |
| 39 | core/file_format/rif_generator.cpp |
| 40 | core/file_format/pkg_type.cpp |
| 41 | core/file_format/iso_extractor.cpp |
| 42 | core/patcher/psn_bypass.cpp |
| 43 | core/patcher/elf_reconstruct.cpp |
| 44 | core/crypto/crypto.cpp |
| 45 | core/decompiler/DecompilerContext.cpp |
| 46 | core/decompiler/analysis/DominatorAnalysis.cpp |
| 47 | core/decompiler/analysis/StructuralAnalysis.cpp |
| 48 | core/decompiler/analysis/SymbolAnalysis.cpp |
| 49 | core/decompiler/analysis/SymbolDatabase.cpp |
| 50 | core/decompiler/analysis/DataFlowAnalysis.cpp |
| 51 | core/decompiler/analysis/JumpTableAnalysis.cpp |
| 52 | core/decompiler/lifter/VariableAnalysis.cpp |
| 53 | core/decompiler/codegen/CppEmitter.cpp |
| 54 | core/decompiler/ir/AST.cpp |
| 55 | common/io_file.cpp |
| 56 | common/path_util.cpp |
| 57 | common/error.cpp |
| 58 | common/assert.cpp |
| 59 | common/string_util.cpp |
| 60 | common/ntapi_stub.cpp |
| 61 | common/config.cpp |
| 62 | common/logging/backend.cpp |
| 63 | common/logging/filter.cpp |
| 64 | common/logging/text_formatter.cpp |
| 65 | common/thread.cpp |
| 66 | ) |
| 67 | |
| 68 | add_library(shadpkg_core STATIC ${CORE_SOURCES}) |
| 69 | |
| 70 | target_include_directories(shadpkg_core PUBLIC |
| 71 | ${CMAKE_SOURCE_DIR} |
| 72 | ${CMAKE_SOURCE_DIR}/core |
| 73 | ${CMAKE_SOURCE_DIR}/core/file_format |
| 74 | ${CMAKE_SOURCE_DIR}/core/crypto |
| 75 | ${CMAKE_SOURCE_DIR}/common |
| 76 | ) |
| 77 | |
| 78 | target_link_libraries(shadpkg_core PUBLIC ZLIB::ZLIB fmt::fmt cryptopp::cryptopp capstone::capstone nlohmann_json::nlohmann_json) |
| 79 | |
| 80 | if(WIN32) |
| 81 | target_compile_definitions(shadpkg_core PRIVATE _WIN32_WINNT=NTDDI_WIN10_RS5) |
| 82 | target_link_libraries(shadpkg_core PUBLIC onecore) |
| 83 | elseif(APPLE) |
| 84 | target_link_libraries(shadpkg_core PUBLIC "-framework CoreFoundation") |
| 85 | endif() |
| 86 | |
| 87 | # ╔══════════════════════════════════════════════════════════════════════════╗ |
| 88 | # ║ CLI Executable ║ |
| 89 | # ╚══════════════════════════════════════════════════════════════════════════╝ |
| 90 | add_executable(shadpkg main.cpp) |
| 91 | target_link_libraries(shadpkg PRIVATE shadpkg_core) |
| 92 | |
| 93 | if(WIN32) |
| 94 | target_compile_definitions(shadpkg PRIVATE _WIN32_WINNT=NTDDI_WIN10_RS5) |
| 95 | endif() |
| 96 | |
| 97 | # ╔══════════════════════════════════════════════════════════════════════════╗ |
| 98 | # ║ GUI Executable ║ |
| 99 | # ╚══════════════════════════════════════════════════════════════════════════╝ |
| 100 | if(BUILD_GUI) |
| 101 | set(GUI_SOURCES |
| 102 | gui/main_gui.cpp |
| 103 | gui/GUIContext.cpp |
| 104 | gui/StyleManager.cpp |
| 105 | gui/NavBar.cpp |
| 106 | gui/ConsoleLog.cpp |
| 107 | gui/views/ExtractorView.cpp |
| 108 | gui/views/InspectorView.cpp |
| 109 | gui/views/RIFView.cpp |
| 110 | gui/views/SettingsView.cpp |
| 111 | gui/views/DecompilerView.cpp |
| 112 | gui/views/StructEditorView.cpp |
| 113 | ) |
| 114 | |
| 115 | add_executable(shadpkg-gui ${GUI_SOURCES}) |
| 116 | |
| 117 | target_include_directories(shadpkg-gui PRIVATE |
| 118 | ${CMAKE_SOURCE_DIR} |
| 119 | ${CMAKE_SOURCE_DIR}/gui |
| 120 | ${CMAKE_SOURCE_DIR}/gui/include |
| 121 | ) |
| 122 | |
| 123 | target_precompile_headers(shadpkg-gui PRIVATE <cassert> "common/assert.h") |
| 124 | target_compile_definitions(shadpkg-gui PRIVATE IM_ASSERT=ASSERT) |
| 125 | |
| 126 | target_link_libraries(shadpkg-gui PRIVATE |
| 127 | shadpkg_core |
| 128 | imgui::imgui |
| 129 | glfw |
| 130 | OpenGL::GL |
| 131 | ) |
| 132 | |
| 133 | set(IMGUI_BINDINGS_DIR "") |
| 134 | if(DEFINED imgui_PACKAGE_FOLDER_RELEASE) |
| 135 | set(IMGUI_BINDINGS_DIR "${imgui_PACKAGE_FOLDER_RELEASE}/res/bindings") |
| 136 | elseif(DEFINED imgui_PACKAGE_FOLDER_DEBUG) |
| 137 | set(IMGUI_BINDINGS_DIR "${imgui_PACKAGE_FOLDER_DEBUG}/res/bindings") |
| 138 | endif() |
| 139 | |
| 140 | if(IMGUI_BINDINGS_DIR) |
| 141 | target_include_directories(shadpkg-gui PRIVATE "${IMGUI_BINDINGS_DIR}") |
| 142 | target_sources(shadpkg-gui PRIVATE |
| 143 | "${IMGUI_BINDINGS_DIR}/imgui_impl_glfw.cpp" |
| 144 | "${IMGUI_BINDINGS_DIR}/imgui_impl_opengl3.cpp" |
| 145 | ) |
| 146 | endif() |
| 147 | |
| 148 | if(WIN32) |
| 149 | target_compile_definitions(shadpkg-gui PRIVATE _WIN32_WINNT=NTDDI_WIN10_RS5) |
| 150 | # Windows-specific: Link shell32 for folder dialogs |
| 151 | target_link_libraries(shadpkg-gui PRIVATE shell32 ole32) |
| 152 | # Hide console window in release builds |
| 153 | set_target_properties(shadpkg-gui PROPERTIES WIN32_EXECUTABLE $<CONFIG:Release>) |
| 154 | elseif(APPLE) |
| 155 | target_link_libraries(shadpkg-gui PRIVATE "-framework Cocoa" "-framework IOKit") |
| 156 | endif() |
| 157 | |
| 158 | # ═══════════════════════════════════════════════════════════════════════ |
| 159 | # Copy resources to build directory |
| 160 | # ═══════════════════════════════════════════════════════════════════════ |
| 161 | if(EXISTS "${CMAKE_SOURCE_DIR}/gui/resources") |
| 162 | add_custom_command(TARGET shadpkg-gui POST_BUILD |
| 163 | COMMAND ${CMAKE_COMMAND} -E copy_directory |
| 164 | "${CMAKE_SOURCE_DIR}/gui/resources" |
| 165 | "$<TARGET_FILE_DIR:shadpkg-gui>/resources" |
| 166 | ) |
| 167 | endif() |
| 168 | endif() |
| 169 |