1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
/* open file */
FILE *file;
fopen_s(&file, "C:\\temp\\hook_dllInjection.txt", "a+");
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
fprintf(file, "DLL attach function called.\n");
break;
case DLL_THREAD_ATTACH:
fprintf(file, "DLL thread attach function called.\n");
break;
case DLL_THREAD_DETACH:
fprintf(file, "DLL thread detach function called.\n");
break;
case DLL_PROCESS_DETACH:
fprintf(file, "DLL detach function called.\n");
break;
}
/* close file */
fclose(file);
return TRUE;
}
// http://stackoverflow.com/questions/4352449/pointer-to-a-callback-in-a-dll
//extern "C" __declspec(dllexport) LRESULT CALLBACK meconnect(int code, WPARAM wParam, LPARAM lParam) {
extern "C" __declspec(dllexport) int meconnect(int code, WPARAM wParam, LPARAM lParam) {
FILE *file;
//fopen_s(&file, "C:\\temp\\hook_function.txt", "a+");
//fprintf(file, "Function keyboard_hook called \n");
//fclose(file);
LPCWPSTRUCT pt_stMessage = (LPCWPSTRUCT)lParam;
if (code >= 0 )
{
if (pt_stMessage->message == 0x579 && pt_stMessage->wParam == 3)
{
fopen_s(&file, "C:\\temp\\hook_function.txt", "a+");
fprintf(file, "Function hook called avec code=0x%x msg=0x%x wParam=0x%x\n", code, pt_stMessage->message, pt_stMessage->wParam);
//fprintf(file, "Function keyboard_hook called \n");
fclose(file);
}
}
return(CallNextHookEx(NULL, code, wParam, lParam));
} |
Partager