Thread: DebugActiveProcess() and hooking

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    DebugActiveProcess() and hooking

    I'm trying to hook into another process to increase functionality (no malintent here), and I've come up with the following code:

    Code:
    hFind=FindWindow("myWindowClass",NULL);
    GetWindowThreadProcessId(hFind,&dwProcID);
    		if (!DebugActiveProcess(dwProcID))
    			exit(1);
    
    		hChildFind=FindWindowEx(hFind,NULL,"EDIT",NULL);
    		GetWindowText(hChildFind,chName,255);
    DebugActiveProcess() returns non-zero, so I must have the hook. However, I still can't retrieve the edit control text, ie, I still don't have full access to the other process's windows. Is this the right approach?

    EDIT: Another problem: the target process exits when the debugger process does. I searched, but can't find out how to detach the hook. Any ideas?
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    You only use DebugActiveProcess if you want to do assembler level modification and analysis, you don't need to use it (and shouldn't use it) for simple modification of edit controls.

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Sorry Elixia, but it simply won't work! I can't access any child windows of any other processes using these techniques. There must some way, other than .dll hooking.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    I got it to work. It seems GetWindowText() is a bit of a doozy, and doesn't always send the message. I sent WM_GETTEXT explicitly and it works fine.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    That'll be because GetWindowText only works on the current process.

    As specified in the developer network CD, and on Microsoft's website:

    "This function cannot retrieve the text of an edit control in another application."

    "This behavior is by design. It allows applications to call GetWindowText without hanging if the process that owns the target window is hung"

Popular pages Recent additions subscribe to a feed