Advertisement
Jo-Milk

Reflex Jo-Milk source PS3.h

Nov 17th, 2019
1,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.99 KB | None | 0 0
  1. CDECL_BEGIN
  2. int _sys_printf(const char *format, ...);
  3. int _sys_vsprintf(char *s, const char *format, va_list arg);
  4. CDECL_END
  5.  
  6. struct opd_s
  7. {
  8.     uint32_t sub;
  9.     uint32_t toc;
  10. };
  11.  
  12. opd_s ParseAddr(int Address,int TOC) {
  13.     opd_s GLS = { Address, TOC };
  14.     return GLS;
  15. }
  16.  
  17. opd_s ReflexBegin1_t = { (0xDA4C + 0x25e0000), 0x2618de0 };
  18. void(*ReflexBegin1)(uint64_t) = (void(*)(uint64_t))&ReflexBegin1_t;
  19. opd_s ReflexBegin2_t = { (0x14F34 + 0x25e0000), 0x2618de0 };
  20. void(*ReflexBegin2)(uint64_t) = (void(*)(uint64_t))&ReflexBegin2_t;
  21. opd_s ReflexBegin3_t = { (0x16470 + 0x25e0000), 0x2618de0 };
  22. void(*ReflexBegin3)(uint64_t) = (void(*)(uint64_t))&ReflexBegin3_t;
  23. opd_s ReflexBegin4_t = { (0x16B04 + 0x25e0000), 0x2618de0 };
  24. void(*ReflexBegin4)(uint64_t) = (void(*)(uint64_t))&ReflexBegin4_t;
  25. opd_s ReflexBegin5_t = { (0x16AB8 + 0x25e0000), 0x2618de0 };
  26. void(*ReflexBegin5)(uint64_t) = (void(*)(uint64_t))&ReflexBegin5_t;
  27.  
  28. void Sleep(uint64_t ms)
  29. {
  30.     sys_timer_usleep(ms * 1000);
  31. }
  32.  
  33. int32_t sys_dbg_read_process_memory(uint64_t address, void *data, size_t size)
  34. {
  35.     system_call_4(904, (uint64_t)sys_process_getpid(), address, size, (uint64_t)data);
  36.     return_to_user_prog(int32_t);
  37. }
  38.  
  39. template<typename T>
  40. int32_t ReadProcessMemory(uint32_t address, T data, size_t size)
  41. {
  42.     return sys_dbg_read_process_memory(address, &data, size);
  43. }
  44.  
  45. int32_t sys_dbg_write_process_memory(uint64_t address, const void *data, size_t size)
  46. {
  47.     system_call_4(905, (uint64_t)sys_process_getpid(), address, size, (uint64_t)data);
  48.     return_to_user_prog(int32_t);
  49. }
  50. void SetMemory(int Address,char* bytes,int length)
  51. {
  52.         for (int i = 0; i < length; i++)
  53.         {
  54.             *(char*)(Address + (i)) = bytes[i];
  55.         }
  56. }
  57. template<typename T>
  58. int32_t WriteProcessMemory(uint32_t address, const T value, size_t size)
  59. {
  60.     return sys_dbg_write_process_memory(address, &value, size);
  61. }
  62.  
  63. void HookFunctionStart(uint32_t functionStartAddress, uint32_t newFunction, uint32_t functionStub)
  64. {
  65.     uint32_t normalFunctionStub[8], hookFunctionStub[4];
  66.     sys_dbg_read_process_memory(functionStartAddress, normalFunctionStub, 0x10);
  67.     normalFunctionStub[4] = 0x3D600000 + ((functionStartAddress + 0x10 >> 16) & 0xFFFF);
  68.     normalFunctionStub[5] = 0x616B0000 + (functionStartAddress + 0x10 & 0xFFFF);
  69.     normalFunctionStub[6] = 0x7D6903A6;
  70.     normalFunctionStub[7] = 0x4E800420;
  71.     sys_dbg_write_process_memory(functionStub, normalFunctionStub, 0x20);
  72.     hookFunctionStub[0] = 0x3D600000 + ((newFunction >> 16) & 0xFFFF);
  73.     hookFunctionStub[1] = 0x616B0000 + (newFunction & 0xFFFF);
  74.     hookFunctionStub[2] = 0x7D6903A6;
  75.     hookFunctionStub[3] = 0x4E800420;
  76.     sys_dbg_write_process_memory(functionStartAddress, hookFunctionStub, 0x10);
  77. }
  78.  
  79. void UnHookFunctionStart(uint32_t functionStartAddress, uint32_t functionStub)
  80. {
  81.     uint32_t normalFunctionStub[4];
  82.     sys_dbg_read_process_memory(functionStub, normalFunctionStub, 0x10);
  83.     sys_dbg_write_process_memory(functionStartAddress, normalFunctionStub, 0x10);
  84. }
  85.  
  86. int32_t HookFunction(uint32_t address, uint32_t function)
  87. {
  88.     uint32_t opcode[4];
  89.     opcode[0] = 0x3D600000 + ((function >> 16) & 0xFFFF);
  90.     opcode[1] = 0x616B0000 + (function & 0xFFFF);
  91.     opcode[2] = 0x7D6903A6;
  92.     opcode[3] = 0x4E800420;
  93.     return sys_dbg_write_process_memory(address, &opcode, 0x10);
  94. }
  95.  
  96. int32_t HookFunctionLinked(uint32_t address, uint32_t function)
  97. {
  98.     uint32_t opcode[4];
  99.     opcode[0] = 0x3D600000 + ((function >> 16) & 0xFFFF);
  100.     opcode[1] = 0x616B0000 + (function & 0xFFFF);
  101.     opcode[2] = 0x7D6903A6;
  102.     opcode[3] = 0x4E800421;
  103.     return sys_dbg_write_process_memory(address, &opcode, 0x10);
  104. }
  105.  
  106. int32_t BranchLinkedHook(uint32_t branchFrom, uint32_t branchTo)
  107. {
  108.     uint32_t branch;
  109.     if (branchTo > branchFrom)
  110.         branch = 0x48000001 + (branchTo - branchFrom);
  111.     else
  112.         branch = 0x4C000001 - (branchFrom - branchTo);
  113.     return sys_dbg_write_process_memory(branchFrom, &branch, 4);
  114. }
  115.  
  116. int32_t BranchHook(uint32_t branchFrom, uint32_t branchTo)
  117. {
  118.     uint32_t branch;
  119.     if (branchTo > branchFrom)
  120.         branch = 0x48000000 + (branchTo - branchFrom);
  121.     else
  122.         branch = 0x4C000000 - (branchFrom - branchTo);
  123.     return sys_dbg_write_process_memory(branchFrom, &branch, 4);
  124. }
  125.  
  126. bool yesno_dialog_result = false;
  127. bool yesno_dialog_input = false;
  128.  
  129. void YesNoDialogCallBack(int button_type, void *userdata)
  130. {
  131.     switch (button_type)
  132.     {
  133.     case CELL_MSGDIALOG_BUTTON_YES:
  134.         yesno_dialog_result = true;
  135.         break;
  136.     case CELL_MSGDIALOG_BUTTON_NO:
  137.         yesno_dialog_result = false;
  138.         break;
  139.     }
  140.     yesno_dialog_input = false;
  141. }
  142.  
  143. bool DrawYesNoMessageDialog(const char *format, ...)
  144. {
  145.     va_list argptr;
  146.     char text[CELL_MSGDIALOG_STRING_SIZE];
  147.     va_start(argptr, format);
  148.     _sys_vsprintf(text, format, argptr);
  149.     va_end(argptr);
  150.     cellMsgDialogOpen2(CELL_MSGDIALOG_TYPE_SE_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_YESNO | CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_ON | CELL_MSGDIALOG_TYPE_DEFAULT_CURSOR_NO, text, YesNoDialogCallBack, NULL, NULL);
  151.     yesno_dialog_input = true;
  152.     while (yesno_dialog_input)
  153.     {
  154.         Sleep(16);
  155.         cellSysutilCheckCallback();
  156.     }
  157.     return yesno_dialog_result;
  158. }
  159.  
  160. bool ok_dialog_result = false;
  161. bool ok_dialog_input = false;
  162.  
  163. void OkDialogCallBack(int button_type, void *userdata)
  164. {
  165.     switch (button_type)
  166.     {
  167.     case CELL_MSGDIALOG_BUTTON_OK:
  168.         ok_dialog_result = true;
  169.         break;
  170.     }
  171.     ok_dialog_input = false;
  172. }
  173.  
  174. bool DrawOkayMessageDialog(const char *format, ...)
  175. {
  176.     va_list argptr;
  177.     char text[CELL_MSGDIALOG_STRING_SIZE];
  178.     va_start(argptr, format);
  179.     _sys_vsprintf(text, format, argptr);
  180.     va_end(argptr);
  181.     cellMsgDialogOpen2(CELL_MSGDIALOG_TYPE_SE_TYPE_NORMAL | CELL_MSGDIALOG_TYPE_BUTTON_TYPE_OK | CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_ON | CELL_MSGDIALOG_TYPE_DEFAULT_CURSOR_OK, text, OkDialogCallBack, NULL, NULL);
  182.     ok_dialog_input = true;
  183.     while (ok_dialog_input)
  184.     {
  185.         Sleep(16);
  186.         cellSysutilCheckCallback();
  187.     }
  188.     return ok_dialog_result;
  189. }
  190.  
  191. sys_prx_id_t LoadSPRX(const char *path)
  192. {
  193.     return sys_prx_load_module(path, 0, NULL);
  194. }
  195.  
  196. void StartSPRX(sys_prx_id_t prxID)
  197. {
  198.     int modres;
  199.     sys_prx_start_module(prxID, 0, NULL, &modres, 0, NULL);
  200. }
  201.  
  202. static int connect_to_CAPPI(void)
  203. {
  204.  struct sockaddr_in sin;
  205.  int s;
  206.  
  207.  sin.sin_family = AF_INET;
  208.  sin.sin_addr.s_addr = 0x7F000001; //127.0.0.1 (localhost)
  209.  sin.sin_port = htons(6333);
  210.  s = socket(AF_INET, SOCK_STREAM, 0);
  211.  if (s < 0)
  212.  {
  213.   return -1;
  214.  }
  215.  
  216.  if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
  217.  {
  218.   return -1;
  219.  }
  220.  
  221.  return s;
  222. }
  223.  
  224.  
  225. static int connect_to_webman(void)
  226. {
  227.  struct sockaddr_in sin;
  228.  int s;
  229.  
  230.  sin.sin_family = AF_INET;
  231.  sin.sin_addr.s_addr = 0x7F000001; //127.0.0.1 (localhost)
  232.  sin.sin_port = htons(80);         //http port (80)
  233.  s = socket(AF_INET, SOCK_STREAM, 0);
  234.  if (s < 0)
  235.  {
  236.   return -1;
  237.  }
  238.  
  239.  if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
  240.  {
  241.   return -1;
  242.  }
  243.  
  244.  return s;
  245. }
  246.  
  247. static void sclose(int *socket_e)
  248. {
  249.  if (*socket_e != -1)
  250.  {
  251.   shutdown(*socket_e, SHUT_RDWR);
  252.   socketclose(*socket_e);
  253.   *socket_e = -1;
  254.  }
  255. }
  256.  
  257.  
  258. static void send_wm_request(const char *cmd)
  259. {
  260.  // send command
  261.  int conn_s = -1;
  262.  conn_s = connect_to_webman();
  263.  
  264.  struct timeval tv;
  265.  tv.tv_usec = 0;
  266.  tv.tv_sec = 3;
  267.  setsockopt(conn_s, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
  268.  setsockopt(conn_s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
  269.  
  270.  if (conn_s >= 0)
  271.  {
  272.   char wm_cmd[1048];
  273.   int cmd_len = sprintf(wm_cmd, "GET %s HTTP/1.0\r\n", cmd);
  274.   send(conn_s, wm_cmd, cmd_len, 0);
  275.   sclose(&conn_s);
  276.  }
  277. }
  278.  
  279. static void send_CCAPI_request(const char *cmd)
  280. {
  281.  // send command
  282.  int conn_s = -1;
  283.  conn_s = connect_to_CAPPI();
  284.  
  285.  struct timeval tv;
  286.  tv.tv_usec = 0;
  287.  tv.tv_sec = 3;
  288.  setsockopt(conn_s, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
  289.  setsockopt(conn_s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
  290.  
  291.  if (conn_s >= 0)
  292.  {
  293.   char wm_cmd[1048];
  294.   int cmd_len = sprintf(wm_cmd, "GET %s HTTP/1.0\r\n", cmd);
  295.   send(conn_s, wm_cmd, cmd_len, 0);
  296.   sclose(&conn_s);
  297.  }
  298. }
  299.  
  300. void fixSpaces(char** szReturn) {
  301.  char *str = *szReturn;
  302.  char _returnStr[512];// = (char*)Malloc(128);
  303.  
  304.  _returnStr[0] = '\0';
  305.  
  306.  int dwStrIndex = 0;
  307.  
  308.  for (int i = 0; i < strlen(str) + 1; i++) {
  309.   if (str[i] != 0x20) {
  310.    _returnStr[dwStrIndex] = str[i];
  311.    dwStrIndex++;
  312.   }
  313.   else
  314.   {
  315.    _returnStr[dwStrIndex] = '%';
  316.    _returnStr[dwStrIndex + 1] = '2';
  317.    _returnStr[dwStrIndex + 2] = '0';
  318.    dwStrIndex += 3;
  319.   }
  320.  
  321.  
  322.   _returnStr[dwStrIndex] = '\0';
  323.  }
  324.  
  325.  *szReturn = _returnStr;
  326. }
  327.  
  328. void DoNotify(char *szFormat,int id = 0) {
  329.  char _notify_buffer[512];
  330.  if(CCAPI == true)
  331.  {
  332.  snprintf(_notify_buffer, 512, "/ccapi/notify?id=%i&msg=%s",id,szFormat);
  333.  send_CCAPI_request(_notify_buffer);
  334.  }
  335.  else if(WebMan == true)
  336.  {
  337.  fixSpaces(&szFormat);
  338.  snprintf(_notify_buffer, 512, "/notify.ps3mapi?msg=%s", szFormat);
  339.  send_wm_request(_notify_buffer);
  340.  }
  341. }
  342.  
  343. void ShutDownPS3() {
  344.  char _notify_buffer[512];
  345.  if(CCAPI == true)
  346.  {
  347.  snprintf(_notify_buffer, 512, "/ccapi/shutdown?mode=1");
  348.  send_CCAPI_request(_notify_buffer);
  349.  }
  350.  else if(WebMan == true)
  351.  {
  352.  snprintf(_notify_buffer, 512, "/shutdown.ps3");
  353.  send_wm_request(_notify_buffer);
  354.  }
  355. }
  356. void RestartPS3() {
  357.  char _notify_buffer[512];
  358.  if(CCAPI == true)
  359.  {
  360.  snprintf(_notify_buffer, 512, "/ccapi/shutdown?mode=2");
  361.  send_CCAPI_request(_notify_buffer);
  362.  }
  363.  else if(WebMan == true)
  364.  {
  365.  snprintf(_notify_buffer, 512, "/restart.ps3");
  366.  send_wm_request(_notify_buffer);
  367.  }
  368. }
  369. void Buzzer(int snd = 1)
  370. {
  371.  char _notify_buffer[512];
  372.  if(CCAPI == true)
  373.  {
  374.  snprintf(_notify_buffer, 512, "/ccapi/ringbuzzer?type=%i",snd);
  375.  send_CCAPI_request(_notify_buffer);
  376.  }
  377.  else if(WebMan == true)
  378.  {
  379.  snprintf(_notify_buffer, 512, "/buzzer.ps3mapi?mode=%i",snd);
  380.  send_wm_request(_notify_buffer);
  381.  }
  382. }
  383.  
  384. void AreYouCCAPIorWebMan()
  385. {
  386.     int CCAPI_s = -1;
  387.     CCAPI_s = connect_to_CAPPI();
  388.     if(CCAPI_s != -1)
  389.     {
  390.         CCAPI = true;
  391.         /*WebMan = false;
  392.         NoCW = false;*/
  393.     }
  394.     else
  395.     {
  396.         int web_s = -1;
  397.         web_s= connect_to_webman();
  398.         if(web_s >= 0)
  399.         {
  400.         CCAPI = false;
  401.         /*WebMan = true;
  402.         NoCW = false;*/
  403.         }
  404.         else
  405.         {
  406.             CCAPI = false;
  407.             /*WebMan = false;
  408.             NoCW = true;*/
  409.         }
  410.     }
  411.  
  412. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement