Start process with SetWindowsHookEx

c++ / delphi package - dll injection and api hooking
Post Reply
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Start process with SetWindowsHookEx

Post by nildo »

Hello Mathias!
Is there a way to start a process with a single SetWindowsHookEx DLL kind, injected?

Like the CreateProcessEx, but with not a MadCodeHook DLL. Thank you!
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I'm sorry but I don't understand what you mean... :confused:
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

FOr example:

I have a DLL witch has a Windows Hook to catch WH_GETMESSAGE (just for example). And this hook is instaled by SetWindowsHookEX. Is there a way to start a new process, that will get started with my hook installed?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Ehm, just call CreateProcess? I'm still not sure what you mean...
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

Erm, lemme try to explain...

My program has a menu: "INJECT INTO PROCESS ->", that will inject my DLL into an openned process. BUt this DLL is a single HW_GETMESSAGE hook. So I inject it using SetWindowsHookEx. Right?

But I wish to have a manu like: "INJECT INTO NEW PROCESS..." and the user will choose the EXE that he would like to start, and this process will open with my hook alread installed, like if the first line of the program is to load my HOok. :confused:

Understand?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Well, you can start the process by using CreateProcess, then call WaitForInputIdle, then call SetWindowsHookEx. I guess that should work. But why don't you simply use madCodeHook? :o
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

WaitForInputIdle -> If this process is a console application or does not have a message queue, WaitForInputIdle returns immediately. (by MSDN)

Is there a way to do for all kind of applications?

I can not use "in this case" MadCodeHook for injection, its a KeyBoardHook, and I have to keep compatibilities with some other codes. Thats because I need iimediatly, but I will port them to MadCodeHook as I will have a time
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

SetWindowsHookEx works only on GUI processes, I believe. I'm not sure whether it works with console only processes. And it definately doesn't work with "all kind of applications".
nildo
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am
Contact:

Post by nildo »

Thank you!!! :D
Post Reply