Query: Keyboard Hooks!
C / C++ / MFC
1
Posts
1
Posters
0
Views
1
Watching
-
Hello, I have an application which hooks up the keyboard of a given process by injecting a DLL into the process. Now in that DLL, I have a (shared) char buffer which stores each keystroke. I am trying to get the buffer from my application, which is failing! Is there anything I am missing here? :~ : Here's how my code goes:
... #pragma data_seg(".WBA") char g_chBuffer[0x101]; #pragma data_seg() #pragma comment(linker, "/section:.WBA,rws") ... BOOL _declspec(dllexport) __stdcall GetAppBuffer(char *chfBufferOut) { if(chfBufferOut == NULL) { return FALSE; } char *pchBuffer = g_chBuffer; // Here somehow, g_chBuffer is EMPTY! :(( while((*chfBufferOut++ = *pchBuffer++) != 0); return TRUE; } ... LRESULT _declspec(dllexport) CALLBACK GetKeyboardMsgs(int nCode, WPARAM wParam, LPARAM lParam) { ... static char *pchBuffer = g_chBuffer; ... ToAscii(wParam, nScan, chKeyState, &wTemp, 0); *pchBuffer++ = char(wTemp); // The buffer is fine here ... }
In my application code, where I am calling the function
GetAppBuffer()
:...MyFunction() { ... static BOOL (__stdcall *fpGetAppBuffer)(char *) = NULL; if(m_hmodDLL != NULL) { memset(chBuffer, STRING_TERMINATOR, 0x101); fpGetAppBuffer = (BOOL (__stdcall *)(char *)) GetProcAddress(m_hmodDLL, "GetAppBuffer"); } ... char chBuffer[0x101]; memset(chBuffer, 0, 0x101); fpGetAppBuffer(chBuffer); // It gets an empty chBuffer back! :( .... }
Please reply with any of your comments/suggestions. Is there anything wrong, that I am doing here? Please write back even if you feel the question/code is not clear/insufficient. Thanks! Rgds, Nirav * Don't wish it was easier, wish you were better! *