Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.5 KiB

  1. //wthook.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <windows.h>
  6. #include <wintab.h>
  7. BOOL (WINAPI * Record)(BOOL,HMGR);
  8. BOOL (WINAPI * Playback)(BOOL,HMGR);
  9. long (WINAPI * get_num_pkts_recorded)(void);
  10. long (WINAPI * get_num_pkts_played)(void);
  11. void (WINAPI * display_record)(void);
  12. void (WINAPI * reset)(void);
  13. LRESULT WINAPI WndProc(HWND h, UINT msg, WPARAM w, LPARAM l) {
  14. return DefWindowProc(h, msg, w, l);
  15. }
  16. //WinMain
  17. int WINAPI WinMain(
  18. HINSTANCE hInstance, // handle to current instance
  19. HINSTANCE hPrevInstance, // handle to previous instance
  20. LPSTR lpCmdLine, // pointer to command line
  21. int nCmdShow // show state of window
  22. )
  23. {
  24. WNDCLASS wc = {0};
  25. HINSTANCE hModule;
  26. HMGR hMgr;
  27. LPCSTR szClass = "WTHookClass";
  28. HWND hWnd;
  29. /* Load the functions from our dll */
  30. hModule = LoadLibrary( "wthkdll.dll" );
  31. if( !hModule ) {
  32. MessageBox( 0, "LoadLibrary on 'wthkdll' failed.", "wthook", MB_OK );
  33. return -1;
  34. }
  35. (FARPROC)Record = GetProcAddress( hModule, "Record" );
  36. (FARPROC)Playback = GetProcAddress( hModule, "Playback" );
  37. (FARPROC)get_num_pkts_recorded = GetProcAddress( hModule, "get_num_pkts_recorded" );
  38. (FARPROC)get_num_pkts_played = GetProcAddress( hModule, "get_num_pkts_played" );
  39. (FARPROC)display_record = GetProcAddress( hModule, "display_record" );
  40. (FARPROC)reset = GetProcAddress( hModule, "reset" );
  41. if( !Record || !Playback || !get_num_pkts_recorded || !get_num_pkts_played || !display_record || !reset ) {
  42. MessageBox( 0, "GetProcAddress on 'wthkdll' failed.", "wthook", MB_OK );
  43. return -1;
  44. }
  45. /* Open a window and get a manager handle */
  46. wc.lpfnWndProc = WndProc;
  47. wc.hInstance = hInstance;
  48. wc.lpszClassName = szClass;
  49. if (RegisterClass(&wc)) {
  50. hWnd = CreateWindow(szClass, "WTHookWnd", 0,
  51. 0, 0, 0, 0,
  52. 0, 0, hInstance, NULL);
  53. }
  54. hMgr = WTMgrOpen(hWnd, WT_DEFBASE);
  55. reset(); /* Reset wthkdll */
  56. /* Record some packets */
  57. if (Record(TRUE,hMgr)) {
  58. long recsize;
  59. char buf[128];
  60. MessageBox(0, "Hook installed. Recording Packets. Hit ok to end hook.", "WTHook", MB_OK);
  61. recsize = get_num_pkts_recorded();
  62. Record(FALSE,hMgr);
  63. sprintf( buf, "Recorded %li packets.", recsize );
  64. MessageBox( 0, buf, "WTHook", MB_OK );
  65. }
  66. /* Display the packet data */
  67. display_record();
  68. /* Clean up */
  69. WTMgrClose(hMgr);
  70. DestroyWindow(hWnd);
  71. UnregisterClass(szClass, hInstance);
  72. reset(); /* Reset wthkdll */
  73. FreeLibrary( hModule );
  74. return 0;
  75. }