Seregon/ShadPKG

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

C++/47.3 KB/No license
gui/include/views/ExtractorView.h
ShadPKG / gui / include / views / ExtractorView.h
1// SPDX-FileCopyrightText: Copyright 2025 shadPKG
2// SPDX-License-Identifier: GPL-2.0-or-later
3 
4#pragma once
5 
6#include "../GUIContext.h"
7#include <string>
8 
9// ╔═══════════════════════════════════════════════════════════════════════════╗
10// ║ ExtractorView: Main PKG extraction interface ║
11// ║ ║
12// ║ Layout: ║
13// ║ ┌──────────────────────────────────────────────────────────────────────┐ ║
14// ║ │ SOURCE FILE │ ║
15// ║ │ [📦] [ path/to/file.pkg .......................... ] [ Browse ] │ ║
16// ║ │ *Drag & Drop enabled* │ ║
17// ║ ├──────────────────────────────────────────────────────────────────────┤ ║
18// ║ │ DECRYPTION SETTINGS │ ║
19// ║ │ [X] Enable RIF Decryption │ ║
20// ║ │ └── Key: [ path/to/file.rif ................... ] [ Browse ] │ ║
21// ║ │ Status: ✓ VALID | Content-ID: EP0001... │ ║
22// ║ ├──────────────────────────────────────────────────────────────────────┤ ║
23// ║ │ OUTPUT DESTINATION │ ║
24// ║ │ [📁] [ output/directory .......................... ] [ Browse ] │ ║
25// ║ │ [X] Create subfolder with TitleID │ ║
26// ║ ├──────────────────────────────────────────────────────────────────────┤ ║
27// ║ │ │ ║
28// ║ │ [ EXTRACT PKG ] │ ║
29// ║ │ │ ║
30// ║ │ Status: Extracting file.ext... │ ║
31// ║ │ [████████████████████░░░░░░░░░░░░] 65% │ ║
32// ║ └──────────────────────────────────────────────────────────────────────┘ ║
33// ╚═══════════════════════════════════════════════════════════════════════════╝
34 
35namespace ShadPKG::GUI {
36 
37class ExtractorView {
38public:
39 ExtractorView() = default;
40 ~ExtractorView() = default;
41 
42 // Render the view
43 void Draw(GUIContext &ctx);
44 
45 // Drag & drop callback (called from main window)
46 void OnFileDrop(GUIContext &ctx, const std::string &path);
47 
48 // PKG info after loading
49 struct PkgInfo {
50 std::string titleId;
51 std::string contentId;
52 std::string appVersion;
53 uint64_t pkgSize = 0;
54 bool valid = false;
55 };
56 
57 const PkgInfo &GetPkgInfo() const { return pkgInfo_; }
58 
59private:
60 // Input paths
61 char pkgPathBuf_[512] = "";
62 char rifPathBuf_[512] = "";
63 char outPathBuf_[512] = "";
64 
65 // Options
66 bool useRif_ = false;
67 bool createSubfolder_ = true;
68 
69 // RIF validation state
70 bool rifValid_ = false;
71 std::string rifContentId_;
72 
73 // PKG info
74 PkgInfo pkgInfo_;
75 bool pkgLoaded_ = false;
76 
77 // UI helpers
78 void DrawSourceSection(GUIContext &ctx);
79 void DrawDecryptionSection();
80 void DrawOutputSection();
81 void DrawExtractButton(GUIContext &ctx);
82 void DrawProgressSection(GUIContext &ctx);
83 
84 // File dialog helpers
85 bool ShowOpenFileDialog(const char *title, const char *filter, char *outPath,
86 size_t pathSize);
87 bool ShowSelectFolderDialog(const char *title, char *outPath,
88 size_t pathSize);
89 
90 // Validation
91 void ValidatePkgFile(GUIContext *ctx = nullptr);
92 void ValidateRifFile();
93 bool ValidatePath(const char *path);
94 
95 // Auto-detect RIF in same folder as PKG
96 void AutoDetectRif();
97};
98 
99} // namespace ShadPKG::GUI
100