Advertisement
captmicro

Untitled

Apr 25th, 2010
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. #include "main.h"
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.     if (argc != 2) { return 1; }
  6.     int port = atoi(argv[1]);
  7.  
  8.     WSADATA wsaData; SOCKET sock;
  9.     wsaData = WSAStartup(MAKEWORD(2,2), &wsaData);
  10.     sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  11.     if (sock == INVALID_SOCKET) { WSACleanup(); return 1; }
  12.     sockaddr_in service;
  13.     service.sin_family = AF_INET;
  14.     service.sin_addr.s_addr = inet_addr("127.0.0.1");
  15.     service.sin_port = htons(port);
  16.     if (bind(sock, (SOCKADDR)&service, sizeof(service)) == SOCKET_ERROR)
  17.     {
  18.         closesocket(sock);
  19.         return 1;
  20.     }
  21.     if (listen(sock, 1) == SOCKET_ERROR) { return 1; }
  22.     SOCKET acceptSock;
  23.  
  24.     int bytesSent; int bytesRecv = SOCKET_ERROR;
  25.     char sendbuff[1] = "0"; char recvbuff[9] = "";
  26.     while (1)
  27.     {
  28.         acceptSock = SOCKET_ERROR;
  29.         while (acceptSock == SOCKET_ERROR)
  30.         {
  31.             acceptSock = accept(sock, NULL, NULL);
  32.         }
  33.         bytesRecv = recv(acceptSock, recvbuff, 9, 0);
  34.         if (bytesRecv != SOCKET_ERROR)
  35.         {
  36.             DWORD targs[3];
  37.             targs[0] = atoi(recvbuff[0]);
  38.             char tempbuff[4];
  39.             tempbuff[0] = recvbuff[1];
  40.             tempbuff[1] = recvbuff[2];
  41.             tempbuff[2] = recvbuff[3];
  42.             tempbuff[3] = recvbuff[4];
  43.             targs[1] = atoi(tempbuff);
  44.             tempbuff[0] = recvbuff[5];
  45.             tempbuff[1] = recvbuff[6];
  46.             tempbuff[2] = recvbuff[7];
  47.             tempbuff[3] = recvbuff[8];
  48.             targs[2] = atoi(tempbuff);
  49.             doAct(targs);
  50.         }
  51.     }
  52.  
  53.     return 0;
  54. }
  55.  
  56. int doAct(DWORD args[])
  57. {
  58.     if (args[0] == -1 || args[1] == -1 || args[2] == -1) { return 0; }
  59.     if (args[0] == ACT_KEYBOARD_PRESS && args[1] != -1 && args[2] != -1)
  60.     {
  61.         keybd_event(args[1], NULL, 0, NULL);
  62.         Sleep(args[2]);
  63.         keybd_event(args[1], NULL, KEYEVENTF_KEYUP, NULL);
  64.         return 1;
  65.     }
  66.     else if (args[0] == ACT_KEYBOARD_DOWN && args[1] != -1)
  67.     {
  68.         keybd_event(args[1], NULL, 0, NULL);
  69.         return 1;
  70.     }
  71.     else if (args[0] == ACT_KEYBOARD_UP && args[1] != -1)
  72.     {
  73.         keybd_event(args[1], NULL, KEYEVENTF_KEYUP, NULL);
  74.         return 1;
  75.     }
  76.     else if (args[0] == ACT_MOUSE_CLICK && args[1] != -1 && args[2] != -1)
  77.     {
  78.         switch(args[1])
  79.         {
  80.             case 1:
  81.                 mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
  82.                 Sleep(args[2]);
  83.                 mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
  84.                 break;
  85.             case 2:
  86.                 mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
  87.                 Sleep(args[2]);
  88.                 mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
  89.                 break;
  90.             case 3:
  91.                 mouse_event(MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0);
  92.                 Sleep(args[2]);
  93.                 mouse_event(MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0);
  94.                 break;
  95.         }
  96.         return 1;
  97.     }
  98.     else if (args[0] == ACT_MOUSE_MOVE && args[1] != -1 && args[2] != -1)
  99.     {
  100.         SetCursorPos(args[1], args[2]);
  101.         return 1;
  102.     }
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement