views:

38

answers:

2

I would like, if for no other reason that an academic exercise, to be able to read text written to a form on a Windows Application. The program appears to be written in non-.NET, but in .NET terms, I think you would describe the program as having a Form with a Label and I would like to read the text from that label.

I believe I can see that text being written to the screen with the User32!TextOut (and in other areas User32!DrawString) function. However, it would be nice if I didn't have to hook that function to get the information I'm looking for, but instead if I could just read it from the form directly.

So, given a handle to a Window, is it possible to read the text that has been written to that window with functions like TextOut and DrawString using some similar API or other clever means?

Or am I going about this the wrong way? Should I just hook the function and look for the text in every call and pray?

Thanks!

A: 

If the text is stored in the standard way on the control you can use SendMessage

Win32.SendMessage(controlHandle, Win32.WM_GETTEXTLENGTH, 0, null);

If the control was written with security in mind, the text is almost certainly not stored in a format that can be queried through the Windows API.

I used to use a program called Snadboy Revelation to grab forgotten passwords out of programs (that were just displaying as *). Revelation uses the same technique. However, most modern software hides the text of password and similar fields so this is not of as much use these days.

UPDATE:

Found source code for a Windows Spy app.

Eric J.
This sounds brilliant! I'll give it a shot! :) And just to be sure: I would be able to do this from another application by using `DuplicateHandle` or similar on the controlHandle, right?
omghai2u
@omghai2u: You can do this with another process' window handles. Added a link to source code for a Windows Spy app that will have an implementation.
Eric J.
A: 

Is there a way to hook the TextOut or DrawString methods, to intercept the call?

Jeremy