Easyhook is a powerful open source library from http://easyhook.codeplex.com/.
Compile EasyHook as static library
To link with EasyHook statically, first open the Properties popup, change the Configuration Type to "Static library (.lib)"
Then, remove the "EASYHOOK_EXPORTS" preprocesser definition as below.
Find DllMain
, rename it to "EasyHookDllMain
"
Open easyhook.h, line 51, find the following code.
#ifdef EASYHOOK_EXPORTS
#define EASYHOOK_API __declspec(dllexport) __stdcall
#define DRIVER_SHARED_API(type, decl) EXTERN_C type EASYHOOK_API decl
#else
#ifndef DRIVER
#define EASYHOOK_API __declspec(dllimport) __stdcall
#define DRIVER_SHARED_API(type, decl) EXTERN_C type EASYHOOK_API decl
#else
#define EASYHOOK_API __stdcall
#define DRIVER_SHARED_API(type, decl) typedef type EASYHOOK_API PROC_##decl; EXTERN_C type EASYHOOK_API decl
#endif
#endif
Replace them with
#define EASYHOOK_API __stdcall
#define DRIVER_SHARED_API(type, decl) typedef type EASYHOOK_API PROC_##decl; EXTERN_C type EASYHOOK_API decl
And now you can compile the library.
Use the static library
Open the project which will use the generated static library above.
Call EasyHookDllMain
in your DllMain
.
EASYHOOK_BOOL_EXPORT EasyHookDllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
);
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
EasyHookDllMain( hModule, ul_reason_for_call, lpReserved);
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
Link the libraries.
#pragma comment( lib, "EasyHook32.lib") // or EasyHook64.lib, depending on your project
#pragma comment( lib, "Aux_ulib.lib")
#pragma comment( lib, "psapi.lib")
Now try to compile your project, if you get some complication error like
error LNK2026: module unsafe for SAFESEH image
You can try to switch the SAFESEH to NO as bellow