A tool for deriving PKG packet encryption keys for ps4 written in c++
| 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <array> |
| 7 | #include <filesystem> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | #include "common/shadpkg_types.h" |
| 11 | |
| 12 | class RIFGenerator { |
| 13 | public: |
| 14 | RIFGenerator(); |
| 15 | ~RIFGenerator(); |
| 16 | |
| 17 | // Valida il formato del Content ID |
| 18 | static bool ValidateContentID(const std::string& content_id); |
| 19 | |
| 20 | // Genera un file RIF per un Content ID specifico |
| 21 | bool GenerateRIF(const std::string& content_id, const std::filesystem::path& output_path); |
| 22 | |
| 23 | // Genera un timestamp deterministico basato sul Content ID |
| 24 | static u32 GenerateTimestamp(const std::string& content_id); |
| 25 | |
| 26 | // Genera il contenuto del file RIF |
| 27 | static std::vector<u8> GenerateRIFContent(const std::string& content_id); |
| 28 | |
| 29 | // Verifica se un file RIF è valido |
| 30 | static bool ValidateRIF(const std::filesystem::path& rif_path); |
| 31 | |
| 32 | private: |
| 33 | // Costanti per la struttura RIF |
| 34 | static constexpr u32 RIF_SIZE = 1024; |
| 35 | static constexpr std::array<u8, 4> RIF_MAGIC = {0x52, 0x49, 0x46, 0x00}; // "RIF\0" |
| 36 | static constexpr std::array<u8, 2> RIF_VERSION = {0x00, 0x01}; |
| 37 | static constexpr std::array<u8, 2> RIF_UNKNOWN = {0xFF, 0xFF}; |
| 38 | |
| 39 | // Offset per i vari campi nel file RIF |
| 40 | static constexpr u32 MAGIC_OFFSET = 0x00; |
| 41 | static constexpr u32 VERSION_OFFSET = 0x04; |
| 42 | static constexpr u32 UNKNOWN_OFFSET = 0x06; |
| 43 | static constexpr u32 PADDING_OFFSET = 0x08; |
| 44 | static constexpr u32 TIMESTAMP_OFFSET = 0x10; |
| 45 | static constexpr u32 CONTENT_ID_OFFSET = 0x40; |
| 46 | }; |