A tool for deriving PKG packet encryption keys for ps4 written in c++
| 1 | #pragma once |
| 2 | |
| 3 | #include <cstdint> |
| 4 | #include <map> |
| 5 | #include <memory> |
| 6 | #include <string> |
| 7 | #include <variant> |
| 8 | #include <vector> |
| 9 | |
| 10 | namespace ShadPKG::Decompiler::Analysis { |
| 11 | class Type; |
| 12 | } |
| 13 | |
| 14 | namespace ShadPKG::Decompiler::IR { |
| 15 | |
| 16 | enum class OpCode { |
| 17 | NOP, |
| 18 | MOV, |
| 19 | ADD, |
| 20 | SUB, |
| 21 | MUL, |
| 22 | DIV, |
| 23 | AND, |
| 24 | OR, |
| 25 | XOR, |
| 26 | SHL, |
| 27 | SHR, |
| 28 | CMP, |
| 29 | LEA, |
| 30 | PUSH, |
| 31 | POP, |
| 32 | MOVSX, |
| 33 | MOVZX, |
| 34 | BSWAP, |
| 35 | FISTTP, |
| 36 | LEAVE, |
| 37 | INT, |
| 38 | JMP, |
| 39 | JE, |
| 40 | JNE, |
| 41 | JG, |
| 42 | JGE, |
| 43 | JL, |
| 44 | JLE, |
| 45 | JA, |
| 46 | JAE, |
| 47 | JB, |
| 48 | JBE, |
| 49 | JS, |
| 50 | JNS, |
| 51 | JO, |
| 52 | JNO, |
| 53 | CALL, |
| 54 | RET, |
| 55 | // High-level |
| 56 | PHI, |
| 57 | LOAD, |
| 58 | STORE |
| 59 | }; |
| 60 | |
| 61 | struct Operand { |
| 62 | enum class Type { Register, Immediate, Memory, Variable }; |
| 63 | Type type; |
| 64 | uint64_t value; // For Immediate or Register ID |
| 65 | std::string name; // For Variable |
| 66 | |
| 67 | // Extended Info |
| 68 | std::string regName; // Name of register if type == Register |
| 69 | uint64_t memBase = 0; // Register ID |
| 70 | std::string memBaseName; // Name of base register |
| 71 | int64_t memDisp = 0; // Displacement |
| 72 | }; |
| 73 | |
| 74 | struct Instruction { |
| 75 | uint64_t address; |
| 76 | OpCode opcode; |
| 77 | std::vector<Operand> operands; |
| 78 | std::string disassembly; // Original assembly for reference |
| 79 | }; |
| 80 | |
| 81 | struct BasicBlock { |
| 82 | uint64_t id; |
| 83 | uint64_t startAddress; |
| 84 | uint64_t endAddress; |
| 85 | std::vector<Instruction> instructions; |
| 86 | std::vector<uint64_t> successors; |
| 87 | std::vector<uint64_t> predecessors; |
| 88 | |
| 89 | // Switch Metadata: Value -> Target Block ID |
| 90 | std::map<int64_t, uint64_t> switchMap; |
| 91 | }; |
| 92 | |
| 93 | struct LocalVariable { |
| 94 | std::string name; |
| 95 | int stackOffset; |
| 96 | int size; |
| 97 | std::shared_ptr<Analysis::Type> complexType; |
| 98 | }; |
| 99 | |
| 100 | struct Function { |
| 101 | enum class Category { Unknown, GameLogic, Physics, System, Library }; |
| 102 | |
| 103 | std::string name; |
| 104 | uint64_t address; |
| 105 | std::vector<std::shared_ptr<BasicBlock>> basicBlocks; |
| 106 | std::string signature; |
| 107 | Category category = Category::Unknown; |
| 108 | std::vector<LocalVariable> locals; |
| 109 | }; |
| 110 | |
| 111 | } // namespace ShadPKG::Decompiler::IR |
| 112 |