Guest User

Untitled

a guest
May 26th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.06 KB | None | 0 0
  1. #include <windows.h>
  2. #include <winsock2.h>
  3. /* C Standard includes */
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdint.h>
  8. //#include <winsock2.h>
  9. //#pragma comment(lib,"ws2_32.lib")
  10.  
  11. char *szServer="46.51.176.123";
  12. int nPort=2050;
  13. SOCKET Socket;
  14. #define WM_SOCKET 104
  15. char szHistory[10000];
  16.  
  17. char output[1024*1024]; //1mb
  18.  
  19.  
  20. HANDLE myConsoleHandle;
  21.  
  22. const int fail_packet=0;
  23. const int useportal_packet=3;//--USEPORTAL = 3;
  24. const int ping_packet=6;
  25. const int global_notification_packet=9;
  26. const int tradedone_packet=12;//--TRADEDONE:int = 12;
  27. const int shoot_packet=13;
  28. const int hello_packet=17;
  29. const int tradeaccepted_packet=18;//--TRADEACCEPTED = 18;
  30. const int requesttrade_packet=21;//--REQUESTTRADE = 21;
  31. const int tradechanged_packet=23;//--TRADECHANGED = 23;
  32. const int text_packet=25;// --TEXT
  33. const int update_packet=26;
  34. const int create_suc_packet=31;
  35. const int create_packet=36;
  36. const int reconnect_packet=39;//--RECONNECT = 39;
  37. const int play_sound_packet=44;//
  38. const int load_packet=45;//
  39. const int accountlist_packet=46;//
  40. const int teleport_packet=49;//--TELEPORT = 49;
  41. const int goto_packet=52;//
  42. const int show_effect_packet=56;//
  43. const int mapinfo_packet=60;//
  44. const int traderequest_packet=61;// --TRADEREQUESTED = 61;
  45. const int new_tick_packet=62;//-- NEW_TICK = 62
  46. const int notification_packet=63;// --NOTIFICATION
  47. const int tradestart_packet=67;//--TRADESTART = 67;
  48. const int playertext_packet=69;//--PLAYERTEXT = 69;
  49. const int allyshoot_packet=74;// --ALLYSHOOT
  50. const int clientstat_packet=75;//--CLIENTSTAT = 75;
  51. const int invitedtoguild_packet=77;//--INVITEDTOGUILD = 77;
  52.  
  53.  
  54. struct hello_packet
  55. {
  56. char *buildversion;
  57. int gameid;
  58. char *guild;
  59. char *password;
  60. char *secert;
  61. int keytime;
  62.  
  63. int jxlength;
  64. byte jxbytes;
  65.  
  66. int jdlength;
  67. byte jdbytes;
  68.  
  69. char pk;
  70. char tq;
  71. char h;
  72. char platforum;
  73. char unknow;
  74. };
  75.  
  76.  
  77.  
  78. struct rc4_ctx
  79. {
  80. uint8_t state[256];
  81. uint32_t i;
  82. uint32_t j;
  83. };
  84.  
  85. void rc4_init(uint8_t * key, uint32_t keylen, struct rc4_ctx *ctx);
  86. void rc4_combine(struct rc4_ctx *ctx, uint8_t *input, uint32_t len, uint8_t *output);
  87.  
  88. /* initial implementation by
  89. * Peter White <[email protected]>
  90. */
  91.  
  92.  
  93. /* Swap array elements i=State[i] and b=State[j]. */
  94. static void swap(uint8_t *i, uint8_t *j)
  95. {
  96. uint8_t temp;
  97.  
  98. temp = *i;
  99. *i = *j;
  100. *j = temp;
  101. }
  102.  
  103. /* Key scheduling algorithm. Swap array elements based on the key. */
  104. void rc4_init(uint8_t *key, uint32_t keylen, struct rc4_ctx *ctx)
  105. {
  106. uint32_t i, j;
  107. memset(ctx, 0, sizeof(struct rc4_ctx));
  108.  
  109. /* initialize context */
  110. for (i = 0; i < 256; i++)
  111. ctx->state[i] = i;
  112. for (i = j = 0; i < 256; i++) {
  113. j = (j + ctx->state[i] + key[i % keylen]) % 256;
  114. swap(&ctx->state[i], &ctx->state[j]);
  115. }
  116. }
  117.  
  118. /* Combine the stream generated by the rc4 with some input */
  119. void rc4_combine(struct rc4_ctx *ctx, uint8_t *input, uint32_t len, uint8_t *output)
  120. {
  121. uint32_t i = ctx->i;
  122. uint32_t j = ctx->j;
  123. uint32_t m;
  124. uint8_t si, sj;
  125.  
  126. /* The RC4 algorithm */
  127. for (m = 0; m < len; m++) {
  128. i = (i + 1) & 0xff;
  129. si = ctx->state[i];
  130. j = (j + si) & 0xff;
  131. sj = ctx->state[j];
  132. /* swap(&state[i], &state[j]); */
  133. ctx->state[i] = sj;
  134. ctx->state[j] = si;
  135. /* Xor the key stream value into the input */
  136. *output++ = *input++ ^ (ctx->state[(si + sj) & 0xff]);
  137. }
  138.  
  139. /* Output new S-box indices */
  140. ctx->i = i;
  141. ctx->j = j;
  142. }
  143.  
  144. void write_string(char* str)
  145. {
  146. AllocConsole();
  147. myConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
  148. //write_string("pop");
  149. DWORD cCharsWritten;
  150. char* str2 = TEXT(str);
  151. WriteConsole(myConsoleHandle, str2, strlen(str2), &cCharsWritten, NULL);
  152. };
  153.  
  154.  
  155. LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
  156.  
  157. int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd)
  158. {
  159. WNDCLASSEX wClass;
  160. ZeroMemory(&wClass,sizeof(WNDCLASSEX));
  161. wClass.cbClsExtra=NULL;
  162. wClass.cbSize=sizeof(WNDCLASSEX);
  163. wClass.cbWndExtra=NULL;
  164. wClass.hbrBackground=(HBRUSH)COLOR_WINDOW;
  165. wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
  166. wClass.hIcon=NULL;
  167. wClass.hIconSm=NULL;
  168. wClass.hInstance=hInst;
  169. wClass.lpfnWndProc=(WNDPROC)WinProc;
  170. wClass.lpszClassName="Window Class";
  171. wClass.lpszMenuName=NULL;
  172. wClass.style=CS_HREDRAW|CS_VREDRAW;
  173.  
  174. if(!RegisterClassEx(&wClass))
  175. {
  176. int nResult=GetLastError();
  177. MessageBox(NULL,
  178. "Window class creation failed\r\nError code:",
  179. "Window Class Failed",
  180. MB_ICONERROR);
  181. }
  182.  
  183. HWND hWnd=CreateWindowEx(NULL,
  184. "Window Class",
  185. "Windows Async Client",
  186. WS_OVERLAPPEDWINDOW,
  187. 200,
  188. 200,
  189. 640,
  190. 480,
  191. NULL,
  192. NULL,
  193. hInst,
  194. NULL);
  195.  
  196. if(!hWnd)
  197. {
  198. int nResult=GetLastError();
  199.  
  200. MessageBox(NULL,
  201. "Window creation failed\r\nError code:",
  202. "Window Creation Failed",
  203. MB_ICONERROR);
  204. }
  205.  
  206.  
  207. //char* command = malloc(100);
  208. //int charsRead = 0;
  209. //ReadConsole(myConsoleHandle, command, 100, &cCharsRead, NULL);
  210.  
  211. ShowWindow(hWnd,nShowCmd);
  212.  
  213. MSG msg;
  214. ZeroMemory(&msg,sizeof(MSG));
  215.  
  216. while(GetMessage(&msg,NULL,0,0))
  217. {
  218. TranslateMessage(&msg);
  219. DispatchMessage(&msg);
  220. }
  221.  
  222. return 0;
  223. }
  224.  
  225. LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
  226. {
  227. switch(msg)
  228. {
  229. case WM_CREATE:
  230. {
  231. ZeroMemory(szHistory,sizeof(szHistory));
  232.  
  233. // Set up Winsock
  234. WSADATA WsaDat;
  235. int nResult=WSAStartup(MAKEWORD(2,2),&WsaDat);
  236. if(nResult!=0)
  237. {
  238. MessageBox(hWnd,
  239. "Winsock initialization failed",
  240. "Critical Error",
  241. MB_ICONERROR);
  242. SendMessage(hWnd,WM_DESTROY,NULL,NULL);
  243. break;
  244. }
  245.  
  246. Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  247. if(Socket==INVALID_SOCKET)
  248. {
  249. MessageBox(hWnd,
  250. "Socket creation failed",
  251. "Critical Error",
  252. MB_ICONERROR);
  253. SendMessage(hWnd,WM_DESTROY,NULL,NULL);
  254. break;
  255. }
  256.  
  257. nResult=WSAAsyncSelect(Socket,hWnd,WM_SOCKET,( FD_CONNECT|FD_CLOSE|FD_READ));
  258. if(nResult)
  259. {
  260. MessageBox(hWnd,
  261. "WSAAsyncSelect failed",
  262. "Critical Error",
  263. MB_ICONERROR);
  264. SendMessage(hWnd,WM_DESTROY,NULL,NULL);
  265. break;
  266. }
  267.  
  268. // Resolve IP address for hostname
  269. struct hostent *host;
  270. if((host=gethostbyname(szServer))==NULL)
  271. {
  272. MessageBox(hWnd,
  273. "Unable to resolve host name",
  274. "Critical Error",
  275. MB_ICONERROR);
  276. SendMessage(hWnd,WM_DESTROY,NULL,NULL);
  277. break;
  278. }
  279.  
  280. // Set up our socket address structure
  281. SOCKADDR_IN SockAddr;
  282. SockAddr.sin_port=htons(nPort);
  283. SockAddr.sin_family=AF_INET;
  284. SockAddr.sin_addr.s_addr=*((unsigned long*)host->h_addr);
  285.  
  286. connect(Socket,(LPSOCKADDR)(&SockAddr),sizeof(SockAddr));
  287. write_string("socket creation done\n");
  288.  
  289. }
  290. break;
  291.  
  292. case WM_COMMAND:
  293.  
  294. switch(LOWORD(wParam))
  295. {
  296. write_string("normal\n");
  297. break;
  298. }
  299. break;
  300.  
  301. case WM_DESTROY:
  302. {
  303. PostQuitMessage(0);
  304. shutdown(Socket,SD_BOTH);
  305. closesocket(Socket);
  306. WSACleanup();
  307. return 0;
  308. }
  309. break;
  310.  
  311. case WM_SOCKET:
  312. {
  313.  
  314. if(WSAGETSELECTERROR(lParam))
  315. {
  316. MessageBox(hWnd,
  317. "Connection to server failed",
  318. "Error",
  319. MB_OK|MB_ICONERROR);
  320. SendMessage(hWnd,WM_DESTROY,NULL,NULL);
  321. break;
  322. }
  323. switch(WSAGETSELECTEVENT(lParam))
  324. {
  325. case FD_CONNECT:
  326. {
  327. write_string("connection open\n");
  328. };
  329. break;
  330. case FD_READ:
  331. {
  332. write_string("FD READ\n");
  333. char szIncoming[1024];
  334. ZeroMemory(szIncoming,sizeof(szIncoming));
  335.  
  336. int inDataLength=recv(Socket,
  337. (char*)szIncoming,
  338. sizeof(szIncoming)/sizeof(szIncoming[0]),
  339. 0);
  340.  
  341.  
  342.  
  343. strncat(szHistory,szIncoming,inDataLength);
  344. strcat(szHistory,"\r\n");
  345.  
  346. }
  347. break;
  348.  
  349. case FD_CLOSE:
  350. {
  351. write_string("connection closed\n");
  352. MessageBox(hWnd,
  353. "Server closed connection",
  354. "Connection closed!",
  355. MB_ICONINFORMATION|MB_OK);
  356. closesocket(Socket);
  357. SendMessage(hWnd,WM_DESTROY,NULL,NULL);
  358. }
  359. break;
  360. }
  361. }
  362. }
  363.  
  364. return DefWindowProc(hWnd,msg,wParam,lParam);
  365. }
Advertisement
Add Comment
Please, Sign In to add comment