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 | #include <cstring> |
| 6 | #include <string> |
| 7 | #include <vector> |
| 8 | |
| 9 | namespace MemoryPatcher { |
| 10 | |
| 11 | extern uintptr_t g_eboot_address; |
| 12 | extern uint64_t g_eboot_image_size; |
| 13 | extern std::string g_game_serial; |
| 14 | extern std::string patchFile; |
| 15 | |
| 16 | enum PatchMask : uint8_t { |
| 17 | None, |
| 18 | Mask, |
| 19 | Mask_Jump32, |
| 20 | }; |
| 21 | |
| 22 | struct patchInfo { |
| 23 | std::string gameSerial; |
| 24 | std::string modNameStr; |
| 25 | std::string offsetStr; |
| 26 | std::string valueStr; |
| 27 | bool isOffset; |
| 28 | bool littleEndian; |
| 29 | PatchMask patchMask; |
| 30 | int maskOffset; |
| 31 | }; |
| 32 | |
| 33 | extern std::vector<patchInfo> pending_patches; |
| 34 | |
| 35 | std::string convertValueToHex(const std::string type, const std::string valueStr); |
| 36 | |
| 37 | void OnGameLoaded(); |
| 38 | void AddPatchToQueue(patchInfo patchToAdd); |
| 39 | void ApplyPendingPatches(); |
| 40 | |
| 41 | void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr, bool isOffset, |
| 42 | bool littleEndian, PatchMask patchMask = PatchMask::None, int maskOffset = 0); |
| 43 | |
| 44 | static std::vector<int32_t> PatternToByte(const std::string& pattern); |
| 45 | uintptr_t PatternScan(const std::string& signature); |
| 46 | |
| 47 | } // namespace MemoryPatcher |