Hi all ! I'm a beginner in MASM and I having a problem with it.
I'm trying to write a program which hook keyboard messages. The program contains two file: an executable file and a hook DLL.
Functions in the DLL:
; ---------------------------------------------------------------------------------------
;-------------------------- hook procedure ----------------------------------------
; ---------------------------------------------------------------------------------------
hookProc proc nCode :DWORD, wParam :DWORD, lParam :DWORD
; Send Message to Spy Window
invoke SendMessage, hShareWind, WH_ACTIVE, wParam, lParam
invoke CallNextHookEx, 0, nCode, wParam, lParam
return eax
ret
hookProc endp
; -------------------------------------------------------------------------------
; -------------------- Share handle win -----------------------------------
; -------------------------------------------------------------------------------
sharehWind proc hWind :DWORD
m2m hShareWind, hWind ; Copy hWind to DLL's global variable
ret
sharehWind endp
; -------------------------------------------------------------------------
And in the executable file, I do:
invoke sharehWind, hWin ; Copy hWin to DLL's global variable
In the executable file, I call sharehWind function to store handle Win [hWin] of the spy Window.
When a hook even occur, Windows OS call hookProc fuction. In this function, I SEND PARAMETERS TO THE SPY WINDOW TO PROCCES
WITH THE HANDLE OF IT BUT IT IS NOT SUCCESS WITH OTHER PROCCESES, because data in the DLL is not the same with two different procceses.
(http://i593.photobucket.com/albums/tt11/boydtbk/DLL.png)
And I know a code in C++ can do it:
#pragma data_seg(".adshared")
HWND hShareWind = NULL;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.adshared,RWS")
But I don't know how to do it with MASM. Can everybody show me what I can to do?
P/S: Sorry about bad at English because it is not my mother language.
Compliments, that is a fantastic start for this forum :U
Quote from: boydtbk on May 30, 2010, 10:54:41 AM... /SECTION:.adshared,RWS ...
That is the linker option you need ... you must only change the section name or place your variables in an section with the corresponding alias.
Alternatively you can create an segment with the attribute
shared, so that the linker option is not needed.
Tell us why you are writing a key logger. If we are not satisfied with the answer, we close the topic. I will delete any other answers until we are satisfied with the original poster's answer.
Sorry about misunderstanding!
I'm not writting a keylogger! I just have written this program because this is an exercise which my teacher gave me. I'm a student, and I'm learning about Windows message & hooking. I must complete it in a few next days. Can you help me ?
I don't understand what qWord write, can you give a exam about it ?
Methode 1:
for sharing the .data section, just place /SECTION:.data,S in the linkers command line (or /SECTION:.bss,S for .data?).
Method 2:
for this one you may need to download a newer venison of masm:
mySharedData SEGMENT read write shared ALIAS(".shared")
SharedDoword dd ?
mySharedData ENDS
OK, we will allow it for the moment but make sure it does not turn into a keylogger question.