tags:

views:

127

answers:

2

I am trying to hook the ExtTextOut and DrawTextExt GDI method calls of another application.

I know that I need to Use GetProcAddress to find the address of those methods in gdi32.dll, and overwrite the address in the process I want to hook with the address of my function. Then in my function I do what I need, then call the original function.

I want to make this hook functionality available to .net applications, and apparently this is do-able by creating an 'intermediate' unmanaged dll that does the hooking, and is capable of firing a event on the .net side, so that the new function can bet written in the managed environment. I'm just not sure how to implement this. Does anyone have any code samples or links to information?

A: 

How I Built a Working Poker Bot has samples of injecting code and hooking gdi events.

Yuriy Faktorovich
+2  A: 

I would recommend Microsoft's Detours (C++ x86 only) or EasyHook (C++ & C#, x86/x64).

http://easyhook.codeplex.com/

I've used it before, works pretty well. You have to pass a function or address and where you want it redirected to, and you can have all calls (for all processes or a specific one) sent into your function. The tutorials cover most of the basics, but I can edit code into this answer if you'd like.

A bit of trivia is that it also works the other way. Pass a pointer to your function and you can redirect calls into external code. Makes for some interesting integration with old apps or closed-source ones.

peachykeen
FWIW the pro version of Detours supports ia/x64
Alex K.
EasyHook sounds better for me, as it's fully functional (can do 64bit) for free... Is there some sort of tutorial available to walk through getting a small sample running? I saw nothing in the documentation section.
Jeremy
It's hidden over on the downloads page: http://easyhook.codeplex.com/releases/view/24401Managed API docs, Tutorial and Introduction. Not the greatest tutorials, but they should be enough to get you started. :)
peachykeen