I have an application that reads data from the commport and paints it in a docked childwindow. My issue is to capture the data either from the commport directly or capture it from the window. The commport is occupied and not accessable.

Therefore I am trying to hook. With Mousehook I have succeded to capture text from editcontrols but not the text from the desired childwindow.

Now I have written a prog which monitors messages (WH_CALLWNDPROC) but in vain. I would appreciate help to solve my problem. Is hooking the right way?

I attach my prog. To explain ".if .hwnd==000302B2h". First I start the app and capture the childwindow handle separately. Then hooking with the prog.

Posted on 2002-11-19 15:39:43 by minor28
Posted on 2002-11-20 00:20:00 by Four-F
Hi Four-F

Getting the content of a foreign edit-control is no problem. The problem is getting the content of a window. In this case the foreign app is a Delphi-app with text in a TPanel childwindow.
Posted on 2002-11-20 01:27:24 by minor28
In this case the foreign app is a Delphi-app with text in a TPanel childwindow.
I've downloaded WinSpy by James Brown
WinSpy++ Version 1.5

Then i've run some dilphy app, found TPanel and WinSpy was able to fetch text from it.
Then i've tryed some other spies with success.
So i guess it's not big problem.
I don't know how it does it, but source code is available.

Posted on 2002-11-20 03:37:11 by Four-F
I have tried WinSpy++ and I have captured TPanel window title text but not text in the TPanel client area. I have also studied the WinSpy source without finding a solution.
Posted on 2002-11-20 05:38:59 by minor28
May be your TPanel has some child window. TStaticText or something.
To find it try this. Run WinSpy, press More button. You'll see whole tree of windows.
Try manually enumerate windows. Press Flash button for each window to see which window it is.
I'm sure that there is another window above your TPanel.

If there is no such window, the only way for programm display text above TPanel i can see is painting it.
In such case, IMHO, you can't find universal method to retrieve that text.
Posted on 2002-11-21 04:15:46 by Four-F
I have already done what you say. The hierarchy of the windows is as follows:

T_Form --> TMemo
............--> TPanel
............--> TPanel --> TPanel
.............................--> TPanel --> TMaskEdit: I can capture text in this control.
.............................--> TPanel: This is my window.
.............................--> Tpanel

My window has no childwindow or controls. As I can see it, the text must be painted in the client area. The text in my window is selectet parts of a streaming text from the commport. The streaming text is parsed and certain parts are shown i my TPanel window. The window text is updated every 2 seconds.

Does this mean that I can't capture the text.
Posted on 2002-11-21 08:22:56 by minor28
It may be the case that some windowis not child of your TPanel,
but simply is sitting over TPanel and recieves text.
If no such window exists, this does not mean that you can't capture the text.
It means it will be not so easy.
You have to find, with the help of d**assembler & d**ugger, the place where the text is parsed and painded over TPanel. And fetch it. It's not easy and will be working only with that particular programm.
Sorry, but i can't see any other useable solution.
Posted on 2002-11-21 09:00:58 by Four-F
My intention is to use the prog only to this particulary programme. I need the data for further calculations. As a less sophisticated way I have tested a hardware solution with a splitter at the commport to the USB-port. In that way I can read the streaming text. But I will keep trying to get a software solution. Thank you for your help.
Posted on 2002-11-21 13:24:30 by minor28
I did what you said and found "BeginPaint", "DrawText" and "EndPaint" for that particulary TPanel window. But I don't know how to capture the text. I can read the window handle and I have the pointer to the string address but how do I read the text?
Posted on 2002-11-22 03:15:32 by minor28
...I have the pointer to the string address...
Go to http://www.anticracking.sk/EliCZ/export.htm,
and download from there ApiHooks 5.6 package.
It lets you inject your code in remote process.
Write dll and inject it with the help of ah to remote process.
Your dll will create thread and timer or waitable timer in remote process.
Thread will wait on timer.
When time is up your thread is waked up and fetch text using pointer.
Then you simply send retrieved text to your monitor application.
If string address is static, so no more problems.
If it's changed every time application start you have to do more work.
You have to find it using signature or ... There are many possibilities here.
I'm sure you'll find the method.
Posted on 2002-11-22 08:07:52 by Four-F
Hi again

I have downloaded the ApiHooks 5.6 and read the text carefully. But I can't get the hang of it so I have looked for other methods. So far I have "injected" a messagebox to the target code. Once inside the target process I think there is no invincible obstacle to get the data that the target process reads from the commport. I think my solution is not so sophisticated so I would be greatfull for any comments. This is my steps.

1) My programm creats a handle (CreateFile) to the target process.
2) Allocates memory and reads the target file to the memory as a backup
3) Create a filemapping with a buffer to contain both the target code and my "injected" code.
4) "Inject" my code (a simple messagebox) to the last data section of the target PE structure and changes among others the address of entry point.
5) Running the target process by CreateProcess. First my messagebox is opened then the target process starts.
6) Terminate the target process by TerminateProcess
7) Delete the target file from disk
8) Create a new target file on disk
9) Write to the new target file from the allocated memory. Thus I have a target file identical to the original.

A Second way that I now have started to examine, is the possibility to get hold of the real address of the running target. My hope is to catch the API ReadFile buffer from my program and in this way retrieve the data from the commport.

A third way is to put the file in an allocated memory buffer. "Inject" my code and then run the target process from the buffer. I have found a PE loader on the web coded in C++. I have not yet studied the loader. My C++ knowledge is almost zero level.

Any commets would be fine. Regards
Posted on 2003-01-08 16:35:32 by minor28
This is what I use to read from a "used" serial port
http://www.fifo.se/#AVSNFLL222 it works very well but it is expensive
Posted on 2003-01-09 00:04:09 by WinCC