Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "windows.h"
  3.  
  4. #define MYMENU_EXIT (WM_APP + 101)
  5. #define MYMENU_MESSAGEBOX (WM_APP + 102)
  6.  
  7. HINSTANCE inj_hModule; //Injected Modules Handle
  8. HWND prnt_hWnd; //Parent Window Handle
  9.  
  10. //WndProc for the new window
  11. LRESULT CALLBACK DLLWindowProc(HWND, UINT, WPARAM, LPARAM);
  12.  
  13. //Register our windows Class
  14. BOOL RegisterDLLWindowClass(wchar_t szClassName[])
  15. {
  16. WNDCLASSEX wc;
  17. wc.hInstance = inj_hModule;
  18. wc.lpszClassName = (LPCWSTR)L"InjectedDLLWindowClass";
  19. wc.lpszClassName = (LPCWSTR)szClassName;
  20. wc.lpfnWndProc = DLLWindowProc;
  21. wc.style = CS_DBLCLKS;
  22. wc.cbSize = sizeof(WNDCLASSEX);
  23. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  24. wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  25. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  26. wc.lpszMenuName = NULL;
  27. wc.cbClsExtra = 0;
  28. wc.cbWndExtra = 0;
  29. wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
  30. if (!RegisterClassEx(&wc))
  31. return 0;
  32. }
  33. //Creating our windows Menu
  34. HMENU CreateDLLWindowMenu()
  35. {
  36. HMENU hMenu;
  37. hMenu = CreateMenu();
  38. HMENU hMenuPopup;
  39. if (hMenu == NULL)
  40. return FALSE;
  41. hMenuPopup = CreatePopupMenu();
  42. AppendMenu(hMenuPopup, MF_STRING, MYMENU_EXIT, TEXT("Exit"));
  43. AppendMenu(hMenu, MF_POPUP, (UINT_PTR)hMenuPopup, TEXT("File"));
  44.  
  45. hMenuPopup = CreatePopupMenu();
  46. AppendMenu(hMenuPopup, MF_STRING, MYMENU_MESSAGEBOX, TEXT("MessageBox"));
  47. AppendMenu(hMenu, MF_POPUP, (UINT_PTR)hMenuPopup, TEXT("Test"));
  48. return hMenu;
  49. }
  50.  
  51. //The new thread
  52. DWORD WINAPI ThreadProc(LPVOID lpParam)
  53. {
  54. MSG messages;
  55. wchar_t *pString = reinterpret_cast<wchar_t * > (lpParam);
  56. HMENU hMenu = CreateDLLWindowMenu();
  57. RegisterDLLWindowClass(L"InjectedDLLWindowClass");
  58. prnt_hWnd = FindWindow(L"Window Injected Into ClassName", L"Window Injected Into Caption");
  59. HWND hwnd = CreateWindowEx(0, L"InjectedDLLWindowClass", pString, WS_EX_PALETTEWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, prnt_hWnd, hMenu, inj_hModule, NULL);
  60. ShowWindow(hwnd, SW_SHOWNORMAL);
  61. while (GetMessage(&messages, NULL, 0, 0))
  62. {
  63. TranslateMessage(&messages);
  64. DispatchMessage(&messages);
  65. }
  66. return 1;
  67. }
  68. //Our new windows proc
  69. LRESULT CALLBACK DLLWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  70. {
  71. switch (message)
  72. {
  73. case WM_COMMAND:
  74. switch (wParam)
  75. {
  76. case MYMENU_EXIT:
  77. SendMessage(hwnd, WM_CLOSE, 0, 0);
  78. break;
  79. case MYMENU_MESSAGEBOX:
  80. MessageBox(hwnd, L"Test", L"MessageBox", MB_OK);
  81. break;
  82. }
  83. break;
  84. case WM_DESTROY:
  85. PostQuitMessage(0);
  86. break;
  87. default:
  88. return DefWindowProc(hwnd, message, wParam, lParam);
  89. }
  90. return 0;
  91. }
  92.  
  93. BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  94. {
  95. if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
  96. inj_hModule = hModule;
  97. CreateThread(0, NULL, ThreadProc, (LPVOID)L"Window Title", NULL, NULL);
  98. }
  99. return TRUE;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement