Advertisement
BaSs_HaXoR

C++ SPRX Web Request

Nov 13th, 2014
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.04 KB | None | 0 0
  1. //Credits: SONY, BadLuckBrian
  2. //http://pastebin.com/x6dTz0bC#
  3. //http://www.nextgenupdate.com/forums/ps3-cheats-customization/754367-sprx-web-requests-simplified-2.html
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <cell/http.h>
  8. #include <netex/net.h>
  9.  
  10.  
  11.  
  12. #define HTTP_POOL_SIZE      (64 * 1024)
  13. #define HTTP_POOL_BUFFER 0x2110000            //change this to an address with a free size of 0x10000 bytes ! This one is for ghosts 1.14
  14. static char r_buffer[0x6000];  //MAX is 0x6000
  15.  
  16.  
  17. /*Some function remade due to them making the sprx freeze for some reasons, might fix eventually*/
  18.  
  19. void memCpy(void * destination, const void * source, size_t num){for(int i = 0; i < num; i++){ *((char*)destination+i) = *((char*)source+i); } }
  20. void memFree(char* ptr, int len){       for(int i=0;i < len; i++) { *(char*)(ptr+i) = 0x00;}}
  21. int strCmp(const char* str1, const char* str2)
  22. {
  23.         int diff = 0;
  24.  
  25.         if(*(str1) == 0x00 || *(str2) == 0x00) {return -1;}
  26.  
  27.      for(int i = 0; i < 0x600; i++)
  28.      {
  29.                  if(*(str1+i) == 0x00 || *(str2+i) == 0x00) {break;}
  30.                  if(*(str1+i) != *(str2+i)) {diff++;}
  31.      }
  32.  
  33.          return diff;
  34. }
  35. void SendRequest(char* url,  char* retBuffer, int bufMaxLen) //url = url to request ("http://www.google.com/")    | retBuffer = ptr where the answer will be written to  | bufMaxLen = Max length of the buffer
  36. {
  37.         if(bufMaxLen > 0x6000) {return;} //ERROR, bufMaxLen is TOO BIG
  38.  
  39.                 size_t numBuf = 0;
  40.                 CellHttpClientId client = 0;
  41.                 CellHttpTransId trans = 0;
  42.                 CellHttpUri uri;
  43.                 int ret;
  44.                 bool has_cl = true;
  45.                 uint64_t length = 0;
  46.                 uint64_t recvd;
  47.                 size_t poolSize = 0;
  48.                 void *uriPool = NULL;
  49.                         void *httpPool = NULL;
  50.                         const char *serverName;
  51.                         size_t localRecv = 0;
  52.  
  53.             serverName = url;  //set url
  54.                         memFree(r_buffer, bufMaxLen);
  55.  
  56.                         sys_net_initialize_network(); //init network
  57.  
  58.                         httpPool = (void*)HTTP_POOL_BUFFER; //address to: 0x10000 free bytes
  59.                         if (httpPool == NULL) { ret = -1; goto end; }
  60.  
  61.                         ret = cellHttpInit(httpPool, HTTP_POOL_SIZE);
  62.                         if (ret < 0) { goto end; }
  63.        
  64.                         ret = cellHttpCreateClient(&client);
  65.                         if (ret < 0) { goto end; }
  66.  
  67.                         ret = cellHttpUtilParseUri(NULL, serverName, NULL, 0, &poolSize);
  68.                         if (ret < 0) { goto end; }
  69.        
  70.                         char uriPoolAlloc[0x1024]; //allocate some space for the uri (a bit too much but eh)
  71.                         uriPool = uriPoolAlloc;
  72.                         if (NULL == uriPool) { goto end; } //fail
  73.        
  74.                         ret = cellHttpUtilParseUri(&uri, serverName, uriPool, poolSize, NULL);
  75.                         if (ret < 0) {memFree((char*)uriPool, sizeof(uriPool)); goto end; }  
  76.  
  77.                         ret = cellHttpCreateTransaction(&trans, client, CELL_HTTP_METHOD_GET, &uri);
  78.                         memFree((char*)uriPool, sizeof(uriPool));
  79.                         if (ret < 0) { goto end; }
  80.  
  81.                         ret = cellHttpSendRequest(trans, NULL, 0, NULL); //send it :D
  82.  
  83.                         {//make a new scope for the status
  84.                                 int code = 0;
  85.                                 ret = cellHttpResponseGetStatusCode(trans, &code);
  86.                                 if (ret < 0) { goto end; }
  87.                
  88.                         }//end of status scope
  89.  
  90.                         ret = cellHttpResponseGetContentLength(trans, &length);
  91.                         if (ret < 0) {
  92.                                 if (ret == CELL_HTTP_ERROR_NO_CONTENT_LENGTH) { has_cl = false;}
  93.                             else { goto end; }}
  94.                
  95.                         recvd = 0;
  96.  
  97.                         while ((!has_cl) || (recvd < length))
  98.                         {
  99.                                 ret = cellHttpRecvResponse(trans, r_buffer, bufMaxLen-1, &localRecv);
  100.                                 if (ret < 0) {goto end; } else if (localRecv == 0) break;
  101.                                 recvd += localRecv;
  102.                                 r_buffer[localRecv] = '\0'; //null terminate it
  103.                     }
  104.  
  105.                         ret = 0;
  106.  
  107.                         {for(int i = 0;i<bufMaxLen;i++){retBuffer[i] = r_buffer[i];}}  //OUTPUT
  108.  
  109.  
  110.  
  111.                         /* shutdown procedures */
  112.     end:
  113.         if (trans) {
  114.                 cellHttpDestroyTransaction(trans);
  115.                 trans = 0;
  116.         }
  117.  
  118.         if (client) {cellHttpDestroyClient(client);client = 0;}
  119.        
  120.  
  121.         cellHttpEnd();  //END OF HTTP
  122.  
  123.         if (httpPool) {  memFree((char*)httpPool, sizeof(httpPool)); httpPool = NULL;}
  124.  
  125.  
  126.         sys_net_finalize_network();
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement