Advertisement
Al-Azif

prx.cpp

Sep 26th, 2020
1,856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.92 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. #include <errno.h>
  8. #include <sys/ioccom.h>
  9. #include <kernel.h>
  10.  
  11. #include "stdafx.h"
  12.  
  13. #include "mira_substitute.h"
  14.  
  15. // We need to provide an export to force the expected stub library to be generated
  16. __declspec (dllexport) void dummy()
  17. {
  18. }
  19.  
  20. Substitute substitute;
  21.  
  22. struct substitute_hook* sceSysmoduleLoadModule_ref;
  23. struct substitute_hook* sceScreenShotDisableNotification_ref;
  24. struct substitute_hook* sceScreenShotEnableNotification_ref;
  25. struct substitute_hook* sceScreenShotIsDisabled_ref;
  26. struct substitute_hook* sceScreenShotIsVshScreenCaptureDisabled_ref;
  27. struct substitute_hook* sceScreenShotSetOverlayImage_ref;
  28. struct substitute_hook* sceScreenShotSetOverlayImageWithOrigin_ref;
  29. struct substitute_hook* sceVideoRecordingSetInfo_ref;
  30.  
  31. // Don't do anything to silence notifications
  32. int32_t sceScreenShotDisableNotification_hook()
  33. {
  34.     SUBSTITUTE_WAIT(sceScreenShotDisableNotification_ref)
  35.  
  36.     printf("sceScreenShotDisableNotification was called but not executed\n");
  37.     return 0;
  38. }
  39.  
  40. // Don't do anything to silence notifications
  41. int32_t sceScreenShotEnableNotification_hook()
  42. {
  43.     SUBSTITUTE_WAIT(sceScreenShotEnableNotification_ref)
  44.  
  45.     printf("sceScreenShotEnableNotification was called but not executed\n");
  46.     return 0;
  47. }
  48.  
  49. // Always return false, so sceScreenShotEnable()/sceScreenShotDisable() effectively do nothing
  50. int32_t sceScreenShotIsDisabled_hook()
  51. {
  52.     SUBSTITUTE_WAIT(sceScreenShotIsDisabled_ref)
  53.  
  54.     printf("sceScreenShotIsDisabled was called but not executed\n");
  55.     return 0;
  56. }
  57.  
  58. // Always return false, to enable screenshots on the PS4's menu
  59. int32_t sceScreenShotIsVshScreenCaptureDisabled_hook()
  60. {
  61.     SUBSTITUTE_WAIT(sceScreenShotIsVshScreenCaptureDisabled_ref)
  62.  
  63.     printf("sceScreenShotIsVshScreenCaptureDisabled was called but not executed\n");
  64.     return 0;
  65. }
  66.  
  67. // Don't add overlay
  68. int32_t sceScreenShotSetOverlayImage_hook(const char*filePath, int32_t offsetX, int32_t offsetY)
  69. {
  70.     SUBSTITUTE_WAIT(sceScreenShotSetOverlayImage_ref)
  71.  
  72.     printf("sceScreenShotSetOverlayImage was called but not executed\n");
  73.     return 0;
  74. }
  75.  
  76. // Don't add overlay
  77. int32_t sceScreenShotSetOverlayImageWithOrigin_hook(const char *filePath, int32_t marginX, int32_t marginY, int8_t origin)
  78. {
  79.     SUBSTITUTE_WAIT(sceScreenShotSetOverlayImageWithOrigin_ref)
  80.  
  81.     printf("sceScreenShotSetOverlayImageWithOrigin was called but not executed\n");
  82.     return 0;
  83. }
  84.  
  85. // Video capture settings
  86. int32_t sceVideoRecordingSetInfo_hook(int32_t info, const void *pInfo, size_t infoLen)
  87. {
  88.     // Make all permission level changes to zero
  89.     if (info == 0xA007)
  90.     {
  91.         uint32_t level = 0;
  92.         return SUBSTITUTE_CONTINUE(int, sceVideoRecordingSetInfo_ref, (int32_t), info, (const void *), &level, (size_t), sizeof(level)); // return sceVideoRecordingSetInfo(info, &level, sizeof(level));
  93.     }
  94.  
  95.     // Clear guards rather than create them
  96.     if (info == 0xA008)
  97.     {
  98.         return SUBSTITUTE_CONTINUE(int, sceVideoRecordingSetInfo_ref, (int32_t), info, (const void *), nullptr, (size_t), 0); // return sceVideoRecordingSetInfo(info, nullptr, 0);
  99.     }
  100.  
  101.     // Make copyright info empty
  102.     if (info == 0x0A01)
  103.     {
  104.         char copyright = 0;
  105.         return SUBSTITUTE_CONTINUE(int, sceVideoRecordingSetInfo_ref, (int32_t), info, (const void *), &copyright, (size_t), sizeof(copyright)); // return sceVideoRecordingSetInfo(info, &copyright, sizeof(copyright));
  106.     }
  107.  
  108.     // Use real function
  109.     return SUBSTITUTE_CONTINUE(int, sceVideoRecordingSetInfo_ref, (int32_t), info, (const void *), &pInfo, (size_t), infoLen); // return sceVideoRecordingSetInfo(info, &pInfo, infoLen);
  110. }
  111.  
  112. int sceSysmoduleLoadModule_hook(uint16_t id)
  113. {
  114.     // Wait during sceSysmoduleLoadModule_ref is fully initialized
  115.     SUBSTITUTE_WAIT(sceSysmoduleLoadModule_ref)
  116.  
  117.     // Execute sysmodule anyway
  118.     int ret = SUBSTITUTE_CONTINUE(int, sceSysmoduleLoadModule_ref, (uint16_t), id);
  119.  
  120.     // If id is SCE_SYSMODULE_SCREEN_SHOT
  121.     if (id == 0x009C)
  122.     {
  123.         printf("SCE_SYSMODULE_SCREEN_SHOT detected. Hooking ...\n");
  124.  
  125.         sceScreenShotDisableNotification_ref = substitute.Hook(SUBSTITUTE_MAIN_MODULE, "sceScreenShotDisableNotification", (void*)sceScreenShotDisableNotification_hook, SUBSTITUTE_IAT_NAME);
  126.         if (!sceScreenShotDisableNotification_ref)
  127.         {
  128.             printf("[ScreenshotEnabler] (sceScreenShotDisableNotification) Unable to hook (%p) !\n", sceScreenShotDisableNotification_ref);
  129.             return 0;
  130.         } else {
  131.             printf("[ScreenshotEnabler] (sceScreenShotDisableNotification) Hook enable !\n");
  132.         }
  133.  
  134.         sceScreenShotEnableNotification_ref = substitute.Hook(SUBSTITUTE_MAIN_MODULE, "sceScreenShotEnableNotification", (void*)sceScreenShotEnableNotification_hook, SUBSTITUTE_IAT_NAME);
  135.         if (!sceScreenShotEnableNotification_ref)
  136.         {
  137.             printf("[ScreenshotEnabler] (sceScreenShotEnableNotification) Unable to hook (%p) !\n", sceScreenShotEnableNotification_ref);
  138.             return 0;
  139.         } else {
  140.             printf("[ScreenshotEnabler] (sceScreenShotEnableNotification) Hook enable !\n");
  141.         }
  142.  
  143.         sceScreenShotIsDisabled_ref = substitute.Hook(SUBSTITUTE_MAIN_MODULE, "sceScreenShotIsDisabled", (void*)sceScreenShotIsDisabled_hook, SUBSTITUTE_IAT_NAME);
  144.         if (!sceScreenShotIsDisabled_ref)
  145.         {
  146.             printf("[ScreenshotEnabler] (sceScreenShotIsDisabled) Unable to hook (%p) !\n", sceScreenShotIsDisabled_ref);
  147.             return 0;
  148.         } else {
  149.             printf("[ScreenshotEnabler] (sceScreenShotIsDisabled) Hook enable !\n");
  150.         }
  151.  
  152.         sceScreenShotIsVshScreenCaptureDisabled_ref = substitute.Hook(SUBSTITUTE_MAIN_MODULE, "sceScreenShotIsVshScreenCaptureDisabled", (void*)sceScreenShotIsVshScreenCaptureDisabled_hook, SUBSTITUTE_IAT_NAME);
  153.         if (!sceScreenShotIsVshScreenCaptureDisabled_ref)
  154.         {
  155.             printf("[ScreenshotEnabler] (sceScreenShotIsVshScreenCaptureDisabled) Unable to hook (%p) !\n", sceScreenShotIsVshScreenCaptureDisabled_ref);
  156.             return 0;
  157.         } else {
  158.             printf("[ScreenshotEnabler] (sceScreenShotIsVshScreenCaptureDisabled) Hook enable !\n");
  159.         }
  160.  
  161.         sceScreenShotSetOverlayImage_ref = substitute.Hook(SUBSTITUTE_MAIN_MODULE, "sceScreenShotSetOverlayImage", (void*)sceScreenShotSetOverlayImage_hook, SUBSTITUTE_IAT_NAME);
  162.         if (!sceScreenShotSetOverlayImage_ref)
  163.         {
  164.             printf("[ScreenshotEnabler] (sceScreenShotSetOverlayImage) Unable to hook (%p) !\n", sceScreenShotSetOverlayImage_ref);
  165.             return 0;
  166.         } else {
  167.             printf("[ScreenshotEnabler] (sceScreenShotSetOverlayImage) Hook enable !\n");
  168.         }
  169.  
  170.         sceScreenShotSetOverlayImageWithOrigin_ref = substitute.Hook(SUBSTITUTE_MAIN_MODULE, "sceScreenShotSetOverlayImageWithOrigin", (void*)sceScreenShotSetOverlayImageWithOrigin_hook, SUBSTITUTE_IAT_NAME);
  171.         if (!sceScreenShotSetOverlayImageWithOrigin_ref)
  172.         {
  173.             printf("[ScreenshotEnabler] (sceScreenShotSetOverlayImageWithOrigin) Unable to hook (%p) !\n", sceScreenShotSetOverlayImageWithOrigin_ref);
  174.             return 0;
  175.         } else {
  176.             printf("[ScreenshotEnabler] (sceScreenShotSetOverlayImageWithOrigin) Hook enable !\n");
  177.         }
  178.     }
  179.  
  180.         // If id is SCE_SYSMODULE_VIDEO_RECORDING
  181.     if (id == 0x0085)
  182.     {
  183.         printf("SCE_SYSMODULE_VIDEO_RECORDING detected. Hooking ...\n");
  184.  
  185.         sceVideoRecordingSetInfo_ref = substitute.Hook(SUBSTITUTE_MAIN_MODULE, "sceVideoRecordingSetInfo", (void*)sceVideoRecordingSetInfo_hook, SUBSTITUTE_IAT_NAME);
  186.         if (!sceVideoRecordingSetInfo_ref)
  187.         {
  188.             printf("[ScreenshotEnabler] (sceVideoRecordingSetInfo) Unable to hook (%p) !\n", sceVideoRecordingSetInfo_ref);
  189.             return 0;
  190.         } else {
  191.             printf("[ScreenshotEnabler] (sceVideoRecordingSetInfo) Hook enable !\n");
  192.         }
  193.     }
  194.  
  195.     return ret;
  196. }
  197.  
  198. int main()
  199. {
  200.     printf("[ScreenshotEnabler] Main called !\n");
  201.  
  202.     sceSysmoduleLoadModule_ref = substitute.Hook(SUBSTITUTE_MAIN_MODULE, "sceSysmoduleLoadModule", (void*)sceSysmoduleLoadModule_hook, SUBSTITUTE_IAT_NAME);
  203.     if (!sceSysmoduleLoadModule_ref)
  204.     {
  205.         printf("[ScreenshotEnabler] (sceSysmoduleLoadModule) Unable to hook (%p) !\n", sceSysmoduleLoadModule_ref);
  206.         return 0;
  207.     } else {
  208.         printf("[ScreenshotEnabler] (sceSysmoduleLoadModule) Hook enable !\n");
  209.     }
  210.  
  211.     return 0;
  212. }
  213.  
  214. int fini()
  215. {
  216.     if (sceSysmoduleLoadModule_ref)
  217.         substitute.Unhook(sceSysmoduleLoadModule_ref);
  218.  
  219.     if (sceScreenShotDisableNotification_ref)
  220.         substitute.Unhook(sceScreenShotDisableNotification_ref);
  221.  
  222.     if (sceScreenShotEnableNotification_ref)
  223.         substitute.Unhook(sceScreenShotEnableNotification_ref);
  224.  
  225.     if (sceScreenShotIsDisabled_ref)
  226.         substitute.Unhook(sceScreenShotIsDisabled_ref);
  227.  
  228.     if (sceScreenShotIsVshScreenCaptureDisabled_ref)
  229.         substitute.Unhook(sceScreenShotIsVshScreenCaptureDisabled_ref);
  230.  
  231.     if (sceScreenShotSetOverlayImage_ref)
  232.         substitute.Unhook(sceScreenShotSetOverlayImage_ref);
  233.  
  234.     if (sceScreenShotSetOverlayImageWithOrigin_ref)
  235.         substitute.Unhook(sceScreenShotSetOverlayImageWithOrigin_ref);
  236.  
  237.     if (sceVideoRecordingSetInfo_ref)
  238.         substitute.Unhook(sceVideoRecordingSetInfo_ref);
  239.  
  240.     return 0;
  241. }
  242.  
  243. extern "C"
  244. {
  245.     int module_start(size_t args, const void *argp)
  246.     {
  247.         return main();
  248.     }
  249.  
  250.     int module_stop(size_t args, const void *argp)
  251.     {
  252.         return fini();
  253.     }
  254. }
  255.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement