Schlurmann

Hello,
I've been trying to send Commands like BM_CLICK or WM_LBUTTONDOWN or whatever to any applications. It worked pretty well when I could figure out the Class of a Button or Edit or somethign else, but now I got a window whose elements I can't get by using Spy++. I tried to filter all messages, but mouse clicks/movements always are 0x00FF -> unknown messages with wParam 0 and lParam is some kind of hex string. So now I'm searching for a way to simulate Buttons Clicks inside the app. Is there one


Re: Visual C++ General Sending Commands to any Process

Bruno van Dooren

I am not that familiar with raw windows command messages, but inserting a thread in a process is not that hard.

Have a look at CreateRemoteThread.

You could also combine that with a windows hook via SetWindowsHookEx.

Insert a thread in the process and then install a WM low level message hook. That way you can see what is going on.

And if you have a thread in the process you can also let it send command messages to its own process, but I don't know the APIs for that by heart.





Re: Visual C++ General Sending Commands to any Process

einaros

Is emulation through SendInput out of the question Or rather, do you need to interact with controls not currently mouse / keyboard focused




Re: Visual C++ General Sending Commands to any Process

Schlurmann

Well, I read about the SendInput possibility, but I didn't try it, yet. I actually don't want to use the mouse, I just want to simulate a buttonclick. But it's actually not a button, theres just the main window I can locate with spy++. All other elements seem to be images that react on clicks or something. The "button" also is in another extra dialoge which also seems to be just an image. But I found out that 0x00FF is WM_INPUT, so every mouse click / movement is a WM_INPUT command and I have lParam, too. Can I work with that



Re: Visual C++ General Sending Commands to any Process

einaros

It's been too long since I last poked around with the specifics of click handling, but I believe you'd get a long way by sending a WM_LBUTTONDOWN followed by a WM_LBUTTONUP, at least with "normal windows".

With the ovnerdrawn / handled windows you speak of, raw input may very well be used to handle varying forms of keyboard and mouse notifications. My best suggestions would be for you to snoop on whatever WM_INPUT messages arrive when you press certain key or mouse combos, then re-send those messages programatically.






Re: Visual C++ General Sending Commands to any Process

Schlurmann



That's what I get when moving the mouse or clicking or whatever.

How could I send those to the mainwindow




Re: Visual C++ General Sending Commands to any Process

einaros

Did you have a look at http://msdn2.microsoft.com/en-us/library/ms645536.aspx I read through it all, but there are a few examples there which may be of help. For what it's worth, the lParam is probably a pointer to a structure containing information about the input event.




Re: Visual C++ General Sending Commands to any Process

Schlurmann

Well, that all seems pretty complicated. I'm just a beginner in C++ and the WinAPI and all those convoluted structures seem to be a little bit too heavy for me at the moment. So would there be an easier way




Re: Visual C++ General Sending Commands to any Process

einaros

Schlurmann wrote:
Well, that all seems pretty complicated. I'm just a beginner in C++ and the WinAPI and all those convoluted structures seem to be a little bit to heavy for me at the moment. So would there be an easier way

A complex problem in software development usually requires a complex solution. Remote-controlling applications which are built like that -- a task tightly coupled with reverse engineering -- is no exception.

Which application are you targetting, and what's the goal of it all Is there some exposed SDK or API you could use instead to achieve what you want






Re: Visual C++ General Sending Commands to any Process

Shakje

The way I've done it in an app is to hook the window you want to get messages from, store them and send them back. This means you intercept the messages before they hit the window so you should be getting the right info (plus you can store the whole message and just send it back at it). I can't post the code, but it's pretty complex.




Re: Visual C++ General Sending Commands to any Process

Schlurmann

I already tried hooking WH_CALLWNDPROC but it didn't work, because I never hooked anything before, heres what I tried:

LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBox (NULL, "bla", "bla", MB_OK);
if (nCode == HC_ACTION)
{
if (wParam>0)
{

}
}
return CallNextHookEx (hROHook, nCode, wParam, lParam);
}


That was the unfinished Procedure. Thats how I tried to set it:

HWND hwnd = FindWindow (NULL, WndName);
GetWindowThreadProcessId(hwnd, &ID);
hROHook = SetWindowsHookEx(WH_CALLWNDPROC , CallWndProc, NULL, ID);

EDIT: Thats the whole Code:

#include <windows.h>
#include "roh.h"
#include <stdio.h>
#include <string.h>

LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam);
DWORD ID;
HHOOK hROHook;
HOOKPROC hROHookProc;


int WINAPI WinMain (HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArgument,int nFunsterStil)
{

HWND hwnd = FindWindow (NULL, "NiktoutRO Chaos 2007-06-06");
GetWindowThreadProcessId(hwnd, &ID);
hROHook = SetWindowsHookEx(WH_CALLWNDPROC , CallWndProc, NULL, ID);


return 0;
}

LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
MessageBox (NULL, "bla", "bla", MB_OK);
if (nCode == HC_ACTION)
{
if (wParam>0)
{

}
}
return CallNextHookEx (hROHook, nCode, wParam, lParam);
}