Goasm and hooking the mouse routine in a Dll

Started by SIMO, January 04, 2009, 10:18:20 AM

Previous topic - Next topic

SIMO

Hi Folks,
I've just joined the forum and I'm using Goasm. I'm having trouble getting the starting address of a Dll to put in the [hInstance] of the API " SetWindowsHookExA".
I can use the API  GetModuleHandleA and it returns with a handle in eax but if I use any other value it returns zero which I take as the mouse routine is not hooked.
I'm using PeBrowseDbg as my debugger.

SIMO

donkey

A NULL return from GetModuleHandle would most likely indicate that the DLL is not loaded, there are a couple of ways to ensure that it is loaded:

- Load it explicitly using LoadLibrary
- Load it by reference by either calling a function or referencing a variable (ie invoke MyHook.dll:SetHook)

I prefer the second method, it causes the PE Loader to fail if the DLL is not found and a Windows error message to be displayed, the app will not run without the DLL being found. The reference in the second method does not have to actually execute, as long as it is resident in your code that's enough, you can put it right before the application entry and never execute it. I'm not sure how you are calling GetModuleHandle but the syntax is:

invoke GetModuleHandle, "MyHook.dll"
mov [hDLL],eax
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

SIMO

Hi Donkey,
Thank you for your advice. It worked fine. I also put "/entry main" in the GoLink command line and "main" in the Dll file and it also worked fine. The system got the entry point ok and I got the handle of the Dll.

Thanks
Simo