A tool for deriving PKG packet encryption keys for ps4 written in c++
| 1 | /* |
| 2 | * ╔═══════════════════════════════════════════════════════════════════════════╗ |
| 3 | * ║ PS4 SYSTEM STUBS - HEADER ║ |
| 4 | * ╠═══════════════════════════════════════════════════════════════════════════╣ |
| 5 | * ║ Data structures and declarations based on shadPS4 emulator. ║ |
| 6 | * ║ Reference: https://github.com/shadps4-emu/shadPS4 ║ |
| 7 | * ╚═══════════════════════════════════════════════════════════════════════════╝ |
| 8 | */ |
| 9 | |
| 10 | #ifndef PS4_STUBS_H |
| 11 | #define PS4_STUBS_H |
| 12 | |
| 13 | #pragma once |
| 14 | |
| 15 | #include <cstdint> |
| 16 | #include <cstring> |
| 17 | |
| 18 | // ═══════════════════════════════════════════════════════════════════════════ |
| 19 | // COMMON TYPES |
| 20 | // ═══════════════════════════════════════════════════════════════════════════ |
| 21 | |
| 22 | using s8 = int8_t; |
| 23 | using s16 = int16_t; |
| 24 | using s32 = int32_t; |
| 25 | using s64 = int64_t; |
| 26 | using u8 = uint8_t; |
| 27 | using u16 = uint16_t; |
| 28 | using u32 = uint32_t; |
| 29 | using u64 = uint64_t; |
| 30 | |
| 31 | #define ORBIS_OK 0 |
| 32 | |
| 33 | // ═══════════════════════════════════════════════════════════════════════════ |
| 34 | // PAD (CONTROLLER) STRUCTURES - Based on shadPS4 |
| 35 | // ═══════════════════════════════════════════════════════════════════════════ |
| 36 | |
| 37 | constexpr int ORBIS_PAD_MAX_TOUCH_NUM = 2; |
| 38 | constexpr int ORBIS_PAD_MAX_DEVICE_UNIQUE_DATA_SIZE = 12; |
| 39 | constexpr int ORBIS_PAD_PORT_TYPE_STANDARD = 0; |
| 40 | constexpr int ORBIS_PAD_PORT_TYPE_SPECIAL = 2; |
| 41 | constexpr int ORBIS_PAD_PORT_TYPE_REMOTE_CONTROL = 16; |
| 42 | |
| 43 | enum class OrbisPadDeviceClass : s32 { |
| 44 | Invalid = -1, |
| 45 | Standard = 0, |
| 46 | Guitar = 1, |
| 47 | Drum = 2, |
| 48 | DjTurntable = 3, |
| 49 | Dancemat = 4, |
| 50 | Navigation = 5, |
| 51 | SteeringWheel = 6, |
| 52 | Stick = 7, |
| 53 | FightStick = 8, |
| 54 | Gun = 9, |
| 55 | }; |
| 56 | |
| 57 | struct OrbisPadAnalogButtons { |
| 58 | u8 l2; |
| 59 | u8 r2; |
| 60 | u8 padding[2]; |
| 61 | }; |
| 62 | |
| 63 | struct OrbisPadAnalogStick { |
| 64 | u8 x; |
| 65 | u8 y; |
| 66 | }; |
| 67 | |
| 68 | struct OrbisFQuaternion { |
| 69 | float x, y, z, w; |
| 70 | }; |
| 71 | |
| 72 | struct OrbisFVector3 { |
| 73 | float x, y, z; |
| 74 | }; |
| 75 | |
| 76 | struct OrbisPadTouch { |
| 77 | u16 x; |
| 78 | u16 y; |
| 79 | u8 id; |
| 80 | u8 reserve[3]; |
| 81 | }; |
| 82 | |
| 83 | struct OrbisPadTouchData { |
| 84 | u8 touchNum; |
| 85 | u8 reserve[3]; |
| 86 | u32 reserve1; |
| 87 | OrbisPadTouch touch[ORBIS_PAD_MAX_TOUCH_NUM]; |
| 88 | }; |
| 89 | |
| 90 | struct OrbisPadExtensionUnitData { |
| 91 | u32 extensionUnitId; |
| 92 | u8 reserve[1]; |
| 93 | u8 dataLength; |
| 94 | u8 data[10]; |
| 95 | }; |
| 96 | |
| 97 | struct OrbisPadData { |
| 98 | u32 buttons; |
| 99 | OrbisPadAnalogStick leftStick; |
| 100 | OrbisPadAnalogStick rightStick; |
| 101 | OrbisPadAnalogButtons analogButtons; |
| 102 | OrbisFQuaternion orientation; |
| 103 | OrbisFVector3 acceleration; |
| 104 | OrbisFVector3 angularVelocity; |
| 105 | OrbisPadTouchData touchData; |
| 106 | bool connected; |
| 107 | u64 timestamp; |
| 108 | OrbisPadExtensionUnitData extensionUnitData; |
| 109 | u8 connectedCount; |
| 110 | u8 reserve[2]; |
| 111 | u8 deviceUniqueDataLen; |
| 112 | u8 deviceUniqueData[ORBIS_PAD_MAX_DEVICE_UNIQUE_DATA_SIZE]; |
| 113 | }; |
| 114 | |
| 115 | struct OrbisPadTouchPadInformation { |
| 116 | float pixelDensity; |
| 117 | struct { |
| 118 | u16 x; |
| 119 | u16 y; |
| 120 | } resolution; |
| 121 | }; |
| 122 | |
| 123 | struct OrbisPadStickInformation { |
| 124 | u8 deadZoneLeft; |
| 125 | u8 deadZoneRight; |
| 126 | }; |
| 127 | |
| 128 | struct OrbisPadControllerInformation { |
| 129 | OrbisPadTouchPadInformation touchPadInfo; |
| 130 | OrbisPadStickInformation stickInfo; |
| 131 | u8 connectionType; |
| 132 | u8 connectedCount; |
| 133 | bool connected; |
| 134 | OrbisPadDeviceClass deviceClass; |
| 135 | u8 reserve[8]; |
| 136 | }; |
| 137 | |
| 138 | struct OrbisPadOpenParam { |
| 139 | u8 reserve[8]; |
| 140 | }; |
| 141 | |
| 142 | struct OrbisPadLightBarParam { |
| 143 | u8 r; |
| 144 | u8 g; |
| 145 | u8 b; |
| 146 | u8 reserve[1]; |
| 147 | }; |
| 148 | |
| 149 | struct OrbisPadVibrationParam { |
| 150 | u8 largeMotor; |
| 151 | u8 smallMotor; |
| 152 | }; |
| 153 | |
| 154 | // ═══════════════════════════════════════════════════════════════════════════ |
| 155 | // AUDIO OUT STRUCTURES - Based on shadPS4 |
| 156 | // ═══════════════════════════════════════════════════════════════════════════ |
| 157 | |
| 158 | constexpr int SCE_AUDIO_OUT_NUM_PORTS = 8; |
| 159 | constexpr int SCE_AUDIO_OUT_VOLUME_0DB = 32768; |
| 160 | |
| 161 | enum class OrbisAudioOutPort : s32 { |
| 162 | Main = 0, |
| 163 | Bgm = 1, |
| 164 | Voice = 2, |
| 165 | Personal = 3, |
| 166 | PadSpk = 4, |
| 167 | Aux = 127, |
| 168 | Audio3d = 128, |
| 169 | }; |
| 170 | |
| 171 | struct OrbisAudioOutPortState { |
| 172 | u16 output; |
| 173 | u8 channel; |
| 174 | u8 reserved8_1[1]; |
| 175 | s16 volume; |
| 176 | u16 rerouteCounter; |
| 177 | u64 flag; |
| 178 | }; |
| 179 | |
| 180 | struct OrbisAudioOutOutputParam { |
| 181 | s32 handle; |
| 182 | void* ptr; |
| 183 | }; |
| 184 | |
| 185 | // ═══════════════════════════════════════════════════════════════════════════ |
| 186 | // VIDEO OUT STRUCTURES - Based on shadPS4 |
| 187 | // ═══════════════════════════════════════════════════════════════════════════ |
| 188 | |
| 189 | constexpr int SCE_VIDEO_OUT_BUS_TYPE_MAIN = 0; |
| 190 | |
| 191 | enum class PixelFormat : u32 { |
| 192 | A8R8G8B8Srgb = 0x80000000, |
| 193 | A8B8G8R8Srgb = 0x80002200, |
| 194 | A2R10G10B10 = 0x88060000, |
| 195 | A2R10G10B10Srgb = 0x88000000, |
| 196 | A2R10G10B10Bt2020Pq = 0x88740000, |
| 197 | A16R16G16B16Float = 0xC1060000, |
| 198 | }; |
| 199 | |
| 200 | enum class TilingMode : u32 { |
| 201 | Tile = 0, |
| 202 | Linear = 1, |
| 203 | }; |
| 204 | |
| 205 | struct BufferAttribute { |
| 206 | PixelFormat pixel_format; |
| 207 | TilingMode tiling_mode; |
| 208 | u32 aspect_ratio; |
| 209 | u32 width; |
| 210 | u32 height; |
| 211 | u32 pitch_in_pixel; |
| 212 | u32 option; |
| 213 | u32 reserved0; |
| 214 | u64 reserved1; |
| 215 | }; |
| 216 | |
| 217 | struct FlipStatus { |
| 218 | u64 count; |
| 219 | u64 process_time; |
| 220 | u64 tsc; |
| 221 | s64 flip_arg; |
| 222 | u64 submit_tsc; |
| 223 | u64 reserved0; |
| 224 | s32 gc_queue_num; |
| 225 | s32 flip_pending_num; |
| 226 | s32 current_buffer; |
| 227 | u32 reserved1; |
| 228 | }; |
| 229 | |
| 230 | struct SceVideoOutVblankStatus { |
| 231 | u64 count; |
| 232 | u64 process_time; |
| 233 | u64 tsc; |
| 234 | u64 reserved; |
| 235 | u8 flags; |
| 236 | u8 pad[7]; |
| 237 | }; |
| 238 | |
| 239 | struct SceVideoOutResolutionStatus { |
| 240 | u32 width; |
| 241 | u32 height; |
| 242 | u32 paneWidth; |
| 243 | u32 paneHeight; |
| 244 | u64 refreshRate; |
| 245 | float screenSize; |
| 246 | u16 flags; |
| 247 | u16 reserved0; |
| 248 | u32 reserved1[3]; |
| 249 | }; |
| 250 | |
| 251 | struct SceVideoOutDeviceCapabilityInfo { |
| 252 | u64 capability; |
| 253 | }; |
| 254 | |
| 255 | struct SceVideoOutColorSettings { |
| 256 | float gamma; |
| 257 | }; |
| 258 | |
| 259 | // ═══════════════════════════════════════════════════════════════════════════ |
| 260 | // USER SERVICE STRUCTURES |
| 261 | // ═══════════════════════════════════════════════════════════════════════════ |
| 262 | |
| 263 | using OrbisUserServiceUserId = s32; |
| 264 | |
| 265 | // ═══════════════════════════════════════════════════════════════════════════ |
| 266 | // FUNCTION DECLARATIONS |
| 267 | // ═══════════════════════════════════════════════════════════════════════════ |
| 268 | |
| 269 | // ─────────────────────── INDIRECT CALL DISPATCH ─────────────────────── |
| 270 | // Called by decompiler-generated code for 'call rax' / 'call [rax+offset]'. |
| 271 | // Attempts to cast fn_ptr to the standard int64_t(a1..a6) signature and call it. |
| 272 | int64_t ps4_indirect_call(void* fn_ptr, |
| 273 | int64_t a1 = 0, int64_t a2 = 0, int64_t a3 = 0, |
| 274 | int64_t a4 = 0, int64_t a5 = 0, int64_t a6 = 0); |
| 275 | |
| 276 | extern "C" { |
| 277 | |
| 278 | // PAD |
| 279 | s32 scePadInit(); |
| 280 | s32 scePadOpen(OrbisUserServiceUserId userId, s32 type, s32 index, const OrbisPadOpenParam* pParam); |
| 281 | s32 scePadClose(s32 handle); |
| 282 | s32 scePadRead(s32 handle, OrbisPadData* pData, s32 num); |
| 283 | s32 scePadReadState(s32 handle, OrbisPadData* pData); |
| 284 | s32 scePadGetControllerInformation(s32 handle, OrbisPadControllerInformation* pInfo); |
| 285 | s32 scePadSetVibration(s32 handle, const OrbisPadVibrationParam* pParam); |
| 286 | s32 scePadSetLightBar(s32 handle, const OrbisPadLightBarParam* pParam); |
| 287 | s32 scePadResetLightBar(s32 handle); |
| 288 | s32 scePadResetOrientation(s32 handle); |
| 289 | s32 scePadSetMotionSensorState(s32 handle, bool bEnable); |
| 290 | s32 scePadGetHandle(OrbisUserServiceUserId userId, s32 type, s32 index); |
| 291 | |
| 292 | // Audio |
| 293 | s32 sceAudioOutInit(); |
| 294 | s32 sceAudioOutOpen(OrbisUserServiceUserId userId, s32 portType, s32 index, u32 length, u32 sampleRate, u32 paramType); |
| 295 | s32 sceAudioOutClose(s32 handle); |
| 296 | s32 sceAudioOutOutput(s32 handle, void* ptr); |
| 297 | s32 sceAudioOutOutputs(void* param, u32 num); |
| 298 | s32 sceAudioOutSetVolume(s32 handle, s32 flag, s32* vol); |
| 299 | s32 sceAudioOutGetPortState(s32 handle, OrbisAudioOutPortState* state); |
| 300 | s32 sceAudioOutGetLastOutputTime(s32 handle, u64* outputTime); |
| 301 | |
| 302 | // Video |
| 303 | s32 sceVideoOutOpen(OrbisUserServiceUserId userId, s32 busType, s32 index, const void* param); |
| 304 | s32 sceVideoOutClose(s32 handle); |
| 305 | void sceVideoOutSetBufferAttribute(BufferAttribute* attribute, u32 pixelFormat, u32 tilingMode, u32 aspectRatio, u32 width, u32 height, u32 pitchInPixel); |
| 306 | s32 sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum, const BufferAttribute* attribute); |
| 307 | s32 sceVideoOutUnregisterBuffers(s32 handle, s32 attributeIndex); |
| 308 | s32 sceVideoOutSetFlipRate(s32 handle, s32 rate); |
| 309 | s32 sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg); |
| 310 | s32 sceVideoOutGetFlipStatus(s32 handle, FlipStatus* status); |
| 311 | s32 sceVideoOutGetVblankStatus(s32 handle, SceVideoOutVblankStatus* status); |
| 312 | s32 sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status); |
| 313 | s32 sceVideoOutIsFlipPending(s32 handle); |
| 314 | s32 sceVideoOutWaitVblank(s32 handle); |
| 315 | s32 sceVideoOutGetDeviceCapabilityInfo(s32 handle, SceVideoOutDeviceCapabilityInfo* info); |
| 316 | s32 sceVideoOutColorSettingsSetGamma(SceVideoOutColorSettings* settings, float gamma); |
| 317 | s32 sceVideoOutAdjustColor(s32 handle, const SceVideoOutColorSettings* settings); |
| 318 | |
| 319 | // GNM |
| 320 | s32 sceGnmSubmitCommandBuffers(u32 count, void** dcbGpuAddrs, u32* dcbSizesInBytes, void** ccbGpuAddrs, u32* ccbSizesInBytes); |
| 321 | s32 sceGnmSubmitAndFlipCommandBuffers(u32 count, void** dcbGpuAddrs, u32* dcbSizesInBytes, void** ccbGpuAddrs, u32* ccbSizesInBytes, s32 videoHandle, s32 bufferIndex, s32 flipMode, s64 flipArg); |
| 322 | u32 sceGnmGetGpuCoreClockFrequency(); |
| 323 | s32 sceGnmFlushGarlic(); |
| 324 | |
| 325 | // User Service |
| 326 | s32 sceUserServiceInitialize(void* params); |
| 327 | s32 sceUserServiceTerminate(); |
| 328 | s32 sceUserServiceGetInitialUser(OrbisUserServiceUserId* userId); |
| 329 | s32 sceUserServiceGetLoginUserIdList(OrbisUserServiceUserId* userIdList); |
| 330 | s32 sceUserServiceGetUserName(OrbisUserServiceUserId userId, char* userName, size_t size); |
| 331 | |
| 332 | // System Service |
| 333 | s32 sceSystemServiceHideSplashScreen(); |
| 334 | s32 sceSystemServiceParamGetInt(s32 paramId, s32* value); |
| 335 | s32 sceSystemServiceParamGetString(s32 paramId, char* buf, size_t bufSize); |
| 336 | s32 sceSystemServiceGetStatus(void* status); |
| 337 | |
| 338 | // Save Data |
| 339 | s32 sceSaveDataInitialize3(void* params); |
| 340 | s32 sceSaveDataMount(void* mount); |
| 341 | s32 sceSaveDataUmount(void* umount); |
| 342 | s32 sceSaveDataDirNameSearch(void* search); |
| 343 | |
| 344 | // Common Dialog |
| 345 | s32 sceCommonDialogInitialize(); |
| 346 | s32 sceMsgDialogInitialize(); |
| 347 | s32 sceMsgDialogOpen(void* param); |
| 348 | s32 sceMsgDialogUpdateStatus(); |
| 349 | s32 sceMsgDialogTerminate(); |
| 350 | s32 sceMsgDialogGetResult(void* result); |
| 351 | |
| 352 | // Network |
| 353 | s32 sceNpSetNpTitleId(void* titleId, void* titleSecret); |
| 354 | s32 sceNpCheckCallback(); |
| 355 | s32 sceNetInit(); |
| 356 | s32 sceNetCtlInit(); |
| 357 | s32 sceNetCtlTerm(); |
| 358 | s32 sceNetCtlGetInfo(s32 code, void* info); |
| 359 | |
| 360 | // IME |
| 361 | s32 sceImeDialogInit(void* param, void* extended); |
| 362 | s32 sceImeDialogGetStatus(); |
| 363 | s32 sceImeDialogTerm(); |
| 364 | |
| 365 | // Sysmodule |
| 366 | s32 sceSysmoduleLoadModule(s32 id); |
| 367 | s32 sceSysmoduleUnloadModule(s32 id); |
| 368 | s32 sceSysmoduleIsLoaded(s32 id); |
| 369 | |
| 370 | } // extern "C" |
| 371 | |
| 372 | #endif // PS4_STUBS_H |
| 373 |