Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <winsock2.h>
- /* C Standard includes */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdint.h>
- //#include <winsock2.h>
- //#pragma comment(lib,"ws2_32.lib")
- char *szServer="46.51.176.123";
- int nPort=2050;
- SOCKET Socket;
- #define WM_SOCKET 104
- char szHistory[10000];
- char output[1024*1024]; //1mb
- HANDLE myConsoleHandle;
- const int fail_packet=0;
- const int useportal_packet=3;//--USEPORTAL = 3;
- const int ping_packet=6;
- const int global_notification_packet=9;
- const int tradedone_packet=12;//--TRADEDONE:int = 12;
- const int shoot_packet=13;
- const int hello_packet=17;
- const int tradeaccepted_packet=18;//--TRADEACCEPTED = 18;
- const int requesttrade_packet=21;//--REQUESTTRADE = 21;
- const int tradechanged_packet=23;//--TRADECHANGED = 23;
- const int text_packet=25;// --TEXT
- const int update_packet=26;
- const int create_suc_packet=31;
- const int create_packet=36;
- const int reconnect_packet=39;//--RECONNECT = 39;
- const int play_sound_packet=44;//
- const int load_packet=45;//
- const int accountlist_packet=46;//
- const int teleport_packet=49;//--TELEPORT = 49;
- const int goto_packet=52;//
- const int show_effect_packet=56;//
- const int mapinfo_packet=60;//
- const int traderequest_packet=61;// --TRADEREQUESTED = 61;
- const int new_tick_packet=62;//-- NEW_TICK = 62
- const int notification_packet=63;// --NOTIFICATION
- const int tradestart_packet=67;//--TRADESTART = 67;
- const int playertext_packet=69;//--PLAYERTEXT = 69;
- const int allyshoot_packet=74;// --ALLYSHOOT
- const int clientstat_packet=75;//--CLIENTSTAT = 75;
- const int invitedtoguild_packet=77;//--INVITEDTOGUILD = 77;
- struct hello_packet
- {
- char *buildversion;
- int gameid;
- char *guild;
- char *password;
- char *secert;
- int keytime;
- int jxlength;
- byte jxbytes;
- int jdlength;
- byte jdbytes;
- char pk;
- char tq;
- char h;
- char platforum;
- char unknow;
- };
- struct rc4_ctx
- {
- uint8_t state[256];
- uint32_t i;
- uint32_t j;
- };
- void rc4_init(uint8_t * key, uint32_t keylen, struct rc4_ctx *ctx);
- void rc4_combine(struct rc4_ctx *ctx, uint8_t *input, uint32_t len, uint8_t *output);
- /* initial implementation by
- * Peter White <[email protected]>
- */
- /* Swap array elements i=State[i] and b=State[j]. */
- static void swap(uint8_t *i, uint8_t *j)
- {
- uint8_t temp;
- temp = *i;
- *i = *j;
- *j = temp;
- }
- /* Key scheduling algorithm. Swap array elements based on the key. */
- void rc4_init(uint8_t *key, uint32_t keylen, struct rc4_ctx *ctx)
- {
- uint32_t i, j;
- memset(ctx, 0, sizeof(struct rc4_ctx));
- /* initialize context */
- for (i = 0; i < 256; i++)
- ctx->state[i] = i;
- for (i = j = 0; i < 256; i++) {
- j = (j + ctx->state[i] + key[i % keylen]) % 256;
- swap(&ctx->state[i], &ctx->state[j]);
- }
- }
- /* Combine the stream generated by the rc4 with some input */
- void rc4_combine(struct rc4_ctx *ctx, uint8_t *input, uint32_t len, uint8_t *output)
- {
- uint32_t i = ctx->i;
- uint32_t j = ctx->j;
- uint32_t m;
- uint8_t si, sj;
- /* The RC4 algorithm */
- for (m = 0; m < len; m++) {
- i = (i + 1) & 0xff;
- si = ctx->state[i];
- j = (j + si) & 0xff;
- sj = ctx->state[j];
- /* swap(&state[i], &state[j]); */
- ctx->state[i] = sj;
- ctx->state[j] = si;
- /* Xor the key stream value into the input */
- *output++ = *input++ ^ (ctx->state[(si + sj) & 0xff]);
- }
- /* Output new S-box indices */
- ctx->i = i;
- ctx->j = j;
- }
- void write_string(char* str)
- {
- AllocConsole();
- myConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
- //write_string("pop");
- DWORD cCharsWritten;
- char* str2 = TEXT(str);
- WriteConsole(myConsoleHandle, str2, strlen(str2), &cCharsWritten, NULL);
- };
- LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
- int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd)
- {
- WNDCLASSEX wClass;
- ZeroMemory(&wClass,sizeof(WNDCLASSEX));
- wClass.cbClsExtra=NULL;
- wClass.cbSize=sizeof(WNDCLASSEX);
- wClass.cbWndExtra=NULL;
- wClass.hbrBackground=(HBRUSH)COLOR_WINDOW;
- wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
- wClass.hIcon=NULL;
- wClass.hIconSm=NULL;
- wClass.hInstance=hInst;
- wClass.lpfnWndProc=(WNDPROC)WinProc;
- wClass.lpszClassName="Window Class";
- wClass.lpszMenuName=NULL;
- wClass.style=CS_HREDRAW|CS_VREDRAW;
- if(!RegisterClassEx(&wClass))
- {
- int nResult=GetLastError();
- MessageBox(NULL,
- "Window class creation failed\r\nError code:",
- "Window Class Failed",
- MB_ICONERROR);
- }
- HWND hWnd=CreateWindowEx(NULL,
- "Window Class",
- "Windows Async Client",
- WS_OVERLAPPEDWINDOW,
- 200,
- 200,
- 640,
- 480,
- NULL,
- NULL,
- hInst,
- NULL);
- if(!hWnd)
- {
- int nResult=GetLastError();
- MessageBox(NULL,
- "Window creation failed\r\nError code:",
- "Window Creation Failed",
- MB_ICONERROR);
- }
- //char* command = malloc(100);
- //int charsRead = 0;
- //ReadConsole(myConsoleHandle, command, 100, &cCharsRead, NULL);
- ShowWindow(hWnd,nShowCmd);
- MSG msg;
- ZeroMemory(&msg,sizeof(MSG));
- while(GetMessage(&msg,NULL,0,0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
- LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
- {
- switch(msg)
- {
- case WM_CREATE:
- {
- ZeroMemory(szHistory,sizeof(szHistory));
- // Set up Winsock
- WSADATA WsaDat;
- int nResult=WSAStartup(MAKEWORD(2,2),&WsaDat);
- if(nResult!=0)
- {
- MessageBox(hWnd,
- "Winsock initialization failed",
- "Critical Error",
- MB_ICONERROR);
- SendMessage(hWnd,WM_DESTROY,NULL,NULL);
- break;
- }
- Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
- if(Socket==INVALID_SOCKET)
- {
- MessageBox(hWnd,
- "Socket creation failed",
- "Critical Error",
- MB_ICONERROR);
- SendMessage(hWnd,WM_DESTROY,NULL,NULL);
- break;
- }
- nResult=WSAAsyncSelect(Socket,hWnd,WM_SOCKET,( FD_CONNECT|FD_CLOSE|FD_READ));
- if(nResult)
- {
- MessageBox(hWnd,
- "WSAAsyncSelect failed",
- "Critical Error",
- MB_ICONERROR);
- SendMessage(hWnd,WM_DESTROY,NULL,NULL);
- break;
- }
- // Resolve IP address for hostname
- struct hostent *host;
- if((host=gethostbyname(szServer))==NULL)
- {
- MessageBox(hWnd,
- "Unable to resolve host name",
- "Critical Error",
- MB_ICONERROR);
- SendMessage(hWnd,WM_DESTROY,NULL,NULL);
- break;
- }
- // Set up our socket address structure
- SOCKADDR_IN SockAddr;
- SockAddr.sin_port=htons(nPort);
- SockAddr.sin_family=AF_INET;
- SockAddr.sin_addr.s_addr=*((unsigned long*)host->h_addr);
- connect(Socket,(LPSOCKADDR)(&SockAddr),sizeof(SockAddr));
- write_string("socket creation done\n");
- }
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- write_string("normal\n");
- break;
- }
- break;
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- shutdown(Socket,SD_BOTH);
- closesocket(Socket);
- WSACleanup();
- return 0;
- }
- break;
- case WM_SOCKET:
- {
- if(WSAGETSELECTERROR(lParam))
- {
- MessageBox(hWnd,
- "Connection to server failed",
- "Error",
- MB_OK|MB_ICONERROR);
- SendMessage(hWnd,WM_DESTROY,NULL,NULL);
- break;
- }
- switch(WSAGETSELECTEVENT(lParam))
- {
- case FD_CONNECT:
- {
- write_string("connection open\n");
- };
- break;
- case FD_READ:
- {
- write_string("FD READ\n");
- char szIncoming[1024];
- ZeroMemory(szIncoming,sizeof(szIncoming));
- int inDataLength=recv(Socket,
- (char*)szIncoming,
- sizeof(szIncoming)/sizeof(szIncoming[0]),
- 0);
- strncat(szHistory,szIncoming,inDataLength);
- strcat(szHistory,"\r\n");
- }
- break;
- case FD_CLOSE:
- {
- write_string("connection closed\n");
- MessageBox(hWnd,
- "Server closed connection",
- "Connection closed!",
- MB_ICONINFORMATION|MB_OK);
- closesocket(Socket);
- SendMessage(hWnd,WM_DESTROY,NULL,NULL);
- }
- break;
- }
- }
- }
- return DefWindowProc(hWnd,msg,wParam,lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment