المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Win32 Message Hooks and/or Legitimate Code Injection



C# Programming
11-10-2009, 10:01 PM
Background
I have an old program that I wrote a few years ago in C#. I no longer have the source code. I have a dialog box in the program that I want to add a button to. All the button will do is launch a program. I've used Resource Hacker to add the button, but how would I go about basically adding a listener to it?

There are two ways I can think to do this:

1. Intercept Win32 messages using a separate program and wait for the WM_COMMAND for that specific button to come up. The program with this is that I don't know enough about API calls to do this on my own in a reasonable amount of time (and I'm guessing I'd have to dive into some C++).

2. Inject code into the existing executable. I've seen examples of how to inject code at the starting point of an executable, but nothing that comes close to being a 'listener' for a button.

I'm thinking unless someone has an easy way of accomplishing number 2, intercepting the messages will be the way to go. So... How on earth would I accomplish this? Using Spy++, I have found the call that I would like to intercept:
004103C8 S WM_COMMAND wNotifyCode:BN_CLICKED wID:12345 hwndCtl:00450346 [wParam:00003039 lParam:00450346]
I've seen code samples for all kinds of hooks, but I can't seem to find one that will grab this.

The question:
Does anyone know of some code that demonstrates how to catch a WM_COMMAND from an external application? If not, how should I go about implementing this strategy?