The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
July 31, 2021, 09:30:09 PM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Campus
| | |-+  [Help] DLL Data Segment with MASM
« previous next »
Pages: [1] Print
Author Topic: [Help] DLL Data Segment with MASM  (Read 5920 times)
boydtbk
Guest


Email
[Help] DLL Data Segment with MASM
« on: May 30, 2010, 10:54:41 AM »

   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:
Code:
; ---------------------------------------------------------------------------------------
;-------------------------- 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: 
Code:
  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.

And I know a code in C++ can do it:
Code:
#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.

* SpyHook.zip (5.22 KB - downloaded 301 times.)
Logged
jj2007
Member
*****
Gender: Male
Posts: 6011



Re: [Help] DLL Data Segment with MASM
« Reply #1 on: May 30, 2010, 12:06:00 PM »

Compliments, that is a fantastic start for this forum ThumbsUp
Logged

qWord
Member
*****
Posts: 1425



Re: [Help] DLL Data Segment with MASM
« Reply #2 on: May 30, 2010, 01:34:55 PM »

... /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.
Logged

FPU in a trice: SmplMath
It's that simple!
hutch--
Administrator
Member
*****
Posts: 12013


Mnemonic Driven API Grinder


Re: [Help] DLL Data Segment with MASM
« Reply #3 on: May 30, 2010, 01:51:32 PM »

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.
Logged

Regards,



Download site for MASM32
http://www.masm32.com
boydtbk
Guest


Email
Re: [Help] DLL Data Segment with MASM
« Reply #4 on: May 30, 2010, 02:34:06 PM »

   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 ?
Logged
qWord
Member
*****
Posts: 1425



Re: [Help] DLL Data Segment with MASM
« Reply #5 on: May 30, 2010, 03:07:05 PM »

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:
Code:
mySharedData SEGMENT read write shared ALIAS(".shared")
    SharedDoword dd ?   
mySharedData ENDS
Logged

FPU in a trice: SmplMath
It's that simple!
hutch--
Administrator
Member
*****
Posts: 12013


Mnemonic Driven API Grinder


Re: [Help] DLL Data Segment with MASM
« Reply #6 on: May 30, 2010, 03:22:04 PM »

OK, we will allow it for the moment but make sure it does not turn into a keylogger question.
Logged

Regards,



Download site for MASM32
http://www.masm32.com
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!