views:

4809

answers:

3

I just saw This Question and it made me wonder:

Can you use windows hooks or other methods to do code injection with c#? I've seen lots of things about code injection but all of them are done in C/C++. I don't know either of those languages and have a really hard time translating. Does anyone have any ideas on how to do this?

+3  A: 

Kevin, it is possible. You can create library with window hook proc using managed C++. All you need to do is to inject this hook into some application using standard WinAPI (SetWindowsHookEx etc.). Inside this hook you can call System::AppDomain::CurrentDomain->Load method to load your assembly into target application's AppDomain. Then you can call methods defined in your assembly using reflection. For example, Snoop uses this method.

aku
+4  A: 

Just came across a link that discusses this subject in detail so I wanted to post it back here: How To Inject a Managed .NET Assembly (DLL) Into Another Process

Ryan Farley
+2  A: 

Mike Stall has this sample, that uses CreateRemoteThread. It has the advantage of not requiring any C++.

Sam Saffron