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 <mutex> |
| 6 | #include <optional> |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
| 10 | namespace ShadPKG::Decompiler::Analysis { |
| 11 | |
| 12 | enum class SymbolSource { |
| 13 | Auto, // Derived from ELF, analysis, or default naming |
| 14 | User // Explicitly renamed by user |
| 15 | }; |
| 16 | |
| 17 | enum class SymbolType { Function, GlobalVariable, Label, StringLiteral }; |
| 18 | |
| 19 | struct SymbolInfo { |
| 20 | uint64_t address; |
| 21 | std::string name; |
| 22 | SymbolType type; |
| 23 | SymbolSource source; |
| 24 | |
| 25 | // Optional: Original name from ELF if renamed? |
| 26 | std::string originalName; |
| 27 | }; |
| 28 | |
| 29 | enum class XRefType { |
| 30 | Call, // Function call |
| 31 | Read, // Data read |
| 32 | Write, // Data write |
| 33 | Jump // Control flow jump |
| 34 | }; |
| 35 | |
| 36 | struct XRef { |
| 37 | uint64_t sourceAddress; // Where the reference happens |
| 38 | uint64_t targetAddress; // What is being referenced |
| 39 | XRefType type; |
| 40 | }; |
| 41 | |
| 42 | class SymbolDatabase { |
| 43 | public: |
| 44 | // Singleton access (Project-scoped ideally, but singleton for now for |
| 45 | // simplicity) In a real multi-project app, pass this instance around. |
| 46 | |
| 47 | SymbolDatabase() = default; |
| 48 | |
| 49 | // Symbol Management |
| 50 | void addSymbol(uint64_t address, const std::string &name, SymbolType type, |
| 51 | SymbolSource source = SymbolSource::Auto); |
| 52 | void renameSymbol(uint64_t address, |
| 53 | const std::string &newName); // Sets source = User |
| 54 | std::optional<SymbolInfo> getSymbol(uint64_t address) const; |
| 55 | std::string getSymbolName( |
| 56 | uint64_t address) const; // Returns name or "sub_XXXX"/"var_XXXX" fallback |
| 57 | |
| 58 | // Cross-References |
| 59 | void addXRef(uint64_t source, uint64_t target, XRefType type); |
| 60 | std::vector<XRef> getXRefsTo(uint64_t target) const; |
| 61 | std::vector<XRef> getXRefsFrom(uint64_t source) const; |
| 62 | |
| 63 | // Bulk loading (e.g. from ELF analysis) |
| 64 | void clear(); |
| 65 | |
| 66 | const std::map<uint64_t, SymbolInfo> &getSymbols() const { return symbols_; } |
| 67 | |
| 68 | private: |
| 69 | mutable std::mutex mutex_; |
| 70 | std::map<uint64_t, SymbolInfo> symbols_; |
| 71 | std::map<uint64_t, std::vector<XRef>> xrefsTo_; // Who calls Target? |
| 72 | std::map<uint64_t, std::vector<XRef>> xrefsFrom_; // Who does Source call? |
| 73 | }; |
| 74 | |
| 75 | } // namespace ShadPKG::Decompiler::Analysis |
| 76 |