Seregon/ShadPKG

A tool for deriving PKG packet encryption keys for ps4 written in c++

C++/47.3 KB/No license
core/file_format/trp.h
1// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3 
4#pragma once
5 
6#include <vector>
7#include "common/shadpkg_endian.h"
8#include "common/io_file.h"
9#include "common/shadpkg_types.h"
10#include "core/crypto/crypto.h"
11 
12struct TrpHeader {
13 u32_be magic; // (0xDCA24D00)
14 u32_be version;
15 u64_be file_size; // size of full trp file
16 u32_be entry_num; // num entries
17 u32_be entry_size; // size of entry
18 u32_be dev_flag; // 1: dev
19 unsigned char digest[20]; // sha1 hash
20 u32_be key_index; // 3031300?
21 unsigned char padding[44];
22};
23 
24struct TrpEntry {
25 char entry_name[32];
26 u64_be entry_pos;
27 u64_be entry_len;
28 u32_be flag; // 3 = CONFIG/ESFM , 0 = PNG
29 unsigned char padding[12];
30};
31 
32class TRP {
33public:
34 TRP();
35 ~TRP();
36 bool Extract(const std::filesystem::path& trophyPath, const std::string titleId);
37 void GetNPcommID(const std::filesystem::path& trophyPath, int index);
38 
39private:
40 Crypto crypto;
41 std::vector<u8> NPcommID = std::vector<u8>(12);
42 std::array<u8, 16> np_comm_id{};
43 std::array<u8, 16> esfmIv{};
44 std::filesystem::path trpFilesPath;
45 static constexpr int iv_len = 16;
46};