Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dllmain.h : Defines the entry point for the DLL application.
- #pragma once
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <Windows.h>
- using namespace std;
- HINSTANCE currentProcessHandle;
- HOOKPROC hkprcSysMsg;
- HHOOK hookID;
- BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
- {
- //std::ofstream outfile("test.txt");
- switch (ul_reason_for_call)
- {
- case DLL_PROCESS_ATTACH:
- currentProcessHandle = hModule;
- break;
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
- LRESULT CALLBACK HookProcedure(int nCode, WPARAM wparam, LPARAM lparam)
- {
- std::ofstream outfile("test.txt");
- if (nCode >= 0)
- {
- switch (nCode)
- {
- case HCBT_CREATEWND:
- outfile << L"Created!~";
- cout << "Created!~" << endl;
- break;
- case HCBT_DESTROYWND:
- outfile << L"Destroied!~";
- cout << "Destroied!~" << endl;
- break;
- default:
- cout << "sth else" << endl;
- break;
- }
- }
- else
- {
- return CallNextHookEx(hookID, nCode, wparam, lparam);
- }
- outfile.close();
- }
- __declspec(dllimport) void InstallHook();
- __declspec(dllimport) void UnistallHook();
- ################################################################################################
- //dllmain.cpp
- #pragma once
- #include "dllmain.h"
- void InstallHook()
- {
- hookID = SetWindowsHookEx(WH_CBT, HookProcedure, currentProcessHandle, 0);
- }
- void UnistallHook()
- {
- UnhookWindowsHookEx(hookID);
- }
- ###########################################################################
- // Hook Executer.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "..\Dll\dllmain.cpp"
- #include <iostream>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- int num = -1;
- cout << "1.Install Hook"<<endl
- << "2.Unistall Hook"<<endl
- << "0.Exit";
- do{
- cin >> num;
- if (num ==1)
- {
- InstallHook();
- }
- else
- {
- UnistallHook();
- }
- getchar();
- system("cls");
- cout << "1.Install Hook" << endl
- << "2.Unistall Hook" << endl
- << "0.Exit";
- } while (num != 0 && num < 3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement