Advertisement
BaSs_HaXoR

CCAPI.h (Primetime00's alt.)

Dec 3rd, 2014
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.45 KB | None | 0 0
  1. //SOURCE: http://www.ps3hax.net/showthread.php?t=73600
  2. #ifndef _CCAPI_
  3. #define _CCAPI_
  4.  
  5. #if defined(_WIN32) || defined(WIN32)
  6. #include <winsock.h>
  7. typedef int ssize_t;
  8. #else
  9. #include <sys/socket.h>
  10. #include <netinet/in.h>
  11. #include <arpa/inet.h>
  12. #endif
  13. #include <string>
  14. #include <vector>
  15. #include "Common.h"
  16.  
  17.  
  18. #define CCAPI_PORT_20 1977
  19. #define CCAPI_PORT_25 1978
  20.  
  21. #define CCAPI_MAX_BYTE_REQUEST 0x10000
  22. #define CCAPI_DATA_BUFFER 0x15000
  23.  
  24. #define CCAPI_COMMAND_GETPROCESSLIST        0x04
  25. #define CCAPI_COMMAND_GETPROCESSNAME        0x05
  26. #define CCAPI_COMMAND_READPROCESSMEMORY     0x02
  27. #define CCAPI_COMMAND_WRITEPROCESSMEMORY    0x03
  28.  
  29. #define CCAPI_SIZE_GETPROCESSLIST           0x10
  30. #define CCAPI_SIZE_GETPROCESSNAME           0x14
  31. #define CCAPI_SIZE_READPROCESSMEMORY        0x20
  32. #define CCAPI_SIZE_WRITEPROCESSMEMORY       0x20
  33.  
  34. #define CCAPI_ERROR_NO_ERROR    0x00
  35. #define CCAPI_ERROR_NO_CONNECT  0x01
  36. #define CCAPI_ERROR_NO_ATTACH   0x02
  37. #define CCAPI_ERROR_CANCEL  0x03
  38. #define CCAPI_ERROR_FILE_FAIL   0x04
  39.  
  40. #define PS3_INT_SIZE    4
  41.  
  42.  
  43.  
  44. using namespace std;
  45.  
  46. #define MAX_CONNECTIONS 10
  47.  
  48. class ConnectionManager
  49. {
  50. public:
  51.     ConnectionManager() { connectionManager = this; }
  52.     ~ConnectionManager() {
  53.         killAllConnections();
  54.         connectionManager = 0;
  55.     }
  56.  
  57.     struct Connection {
  58.         int sock;
  59.         bool available;
  60.         Connection() { sock = 0; available = true; }
  61.     };
  62.    
  63.     bool requestConnection(int &sock, string ipAddress, int hostVersion);
  64.     void releaseConnection(int sock);
  65.     void killAllConnections();
  66.     static ConnectionManager *connectionManager;
  67.     static void startUp() {
  68. #if defined(_WIN32) || defined(WIN32)
  69.             WSADATA wsaData;
  70.             WSAStartup(0x0202, &wsaData);
  71. #endif
  72.     }
  73.  
  74. private:
  75.         Connection connection[MAX_CONNECTIONS];
  76. };
  77.  
  78. class CCAPI
  79. {
  80. public:
  81.     CCAPI(string ip);
  82.     ~CCAPI() {delete [] dataBuffer;}
  83.     static void startup() {
  84.         if (!initialized)
  85.         {
  86. #if defined(_WIN32) || defined(WIN32)
  87.             WSADATA wsaData;
  88.             WSAStartup(0x0202, &wsaData);
  89. #endif
  90.             initialized = true;
  91.         }
  92.     }
  93.     static unsigned char bitConv[];
  94.     static bool initialized;
  95.  
  96.     int connect(void);
  97.     int disconnect(void);
  98.     int receiveData(void);
  99.     int requestProcessIDList(void);
  100.     int requestProcessName(unsigned int processID);
  101.     int requestReadMemory(unsigned int processID, unsigned int offset, unsigned int length);
  102.     int requestWriteMemory(unsigned int processID, unsigned int offset, unsigned int length, char *data);
  103.     int attach(void);
  104.     int readMemory(unsigned int offset, unsigned int length);
  105.     int validateMemory(unsigned int offset);
  106.     int writeMemory(unsigned int offset, unsigned int length, char *data);
  107.  
  108.     char *getData(unsigned int &length) { length = getDataSize(dataBuffer)-16; return &dataBuffer[16]; }
  109.     bool insertData(unsigned int pos, char *data, unsigned int size);
  110.  
  111.     bool isConnected() { return connected; }
  112.     bool isAttached() { return attached; }
  113.     void setHostVersion(int ver) { hostVersion = ver; }
  114.  
  115.  
  116. private:
  117.     unsigned int _conv32(unsigned int val) {
  118.         //return BSWAP32(  (bitConv[((char*)&val)[0]] << 24) + (bitConv[((char*)&val)[1]] << 16) + (bitConv[((char*)&val)[2]] << 8) + (bitConv[((char*)&val)[3]] << 0) );
  119.         return (  (bitConv[((unsigned char*)&val)[0]] << 24) + (bitConv[((unsigned char*)&val)[1]] << 16) + (bitConv[((unsigned char*)&val)[2]] << 8) + (bitConv[((unsigned char*)&val)[3]] << 0) );
  120.     }
  121.     unsigned short _conv16(unsigned short val) {
  122.         //return BSWAP16(  (bitConv[((char*)val)[0]] << 8) + (bitConv[((char*)val)[1]] << 0) );
  123.         return (  (bitConv[((unsigned char*)&val)[0]] << 8) + (bitConv[((unsigned char*)&val)[1]] << 0) );
  124.     }
  125.     unsigned char _conv8(unsigned char val) {
  126.         return bitConv[(unsigned char)val];
  127.     }
  128.  
  129.     unsigned int getDataCommand(char *data) { return BSWAP32( ((unsigned int*)data)[1] ); }
  130.     unsigned int getDataSize(char *data) { return BSWAP32( ((unsigned int*)data)[0] ); }
  131.     unsigned int getDataID(char *data) { return BSWAP32( ((unsigned int*)data)[2] ); }
  132.     unsigned int getDataValidity(char *data) { return BSWAP32( ((unsigned int*)data)[3] ); }
  133.     int parseProcessIDs(char *data);
  134.     int parseProcessName(char *data);
  135.     int parseProcessMemory(char *data);
  136.     void constructHeader(char *buffer, unsigned int &buffersize, unsigned int size, unsigned int command, unsigned int third=1444, unsigned int fourth=1164476209);
  137.  
  138. private:
  139.     string ipAddress;
  140.     int sock;
  141.     struct sockaddr_in destination;
  142.     unsigned int attachedPID;
  143.     char *dataBuffer;
  144.     vector<unsigned int> processIDs;
  145.     string processName;
  146.     bool connected;
  147.     bool attached;
  148.     int hostVersion;
  149.  
  150. };
  151.  
  152. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement