Hook to Windows Service

c++ / delphi package - dll injection and api hooking
Post Reply
Mazinger
Posts: 33
Joined: Wed Jan 26, 2005 6:26 am

Hook to Windows Service

Post by Mazinger »

Hi,

This is my first attempt to use madCodeHook and have this questions:

1. I have an application write in Delphi that is a Windows Service. From this app I want to inject a DLL to other running service, but only this. Is it posible with madCodeHook? How?

2. Is posible to create multiple IPC queues with CreateIPCQueue?

3. When I use the CreateIPCQueue/SendIPCMessage, the computer cracks! I think when SendIPCMessage is called from my hooked DLL the system restarts! What I'm doing wrong?

4. What is the best method to exchange a large number of messages from de Hooked DLL to my application (is a service)? IPC functions of madCodeHook? Sockets? Named Pipes?.

Thanks in advance for your help and congratulations to madshi, who is doing a very good job with these packages!!
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

1. Simply call InjectLibrary(otherServiceProcessHandle, 'your.dll').

2. Sure.

3. madCodeHook's IPC functions are currently not too fast. They're not meant to be stressed by thousands of messages per second. Maybe that's the reason why you're having problems? If not, what APIs are you hooking?

4. Anything that performs as good as possible. You should be aware that communication over process boundaries costs some time. So be careful that you don't slow down things too much by doing too much conversation.
Mazinger
Posts: 33
Joined: Wed Jan 26, 2005 6:26 am

Post by Mazinger »

Ok, but I have problems to inject my dll to the other service.

Please see my code:

PH:=OpenProcess(PROCESS_ALL_ACCESS, False, PID);
If PH>0 then
Begin
If Inject then
Begin
Result:=InjectLibrary(PH,FDLL);
End
Else
Begin
Result:=UninjectLibrary(PH,FDLL);
End;
CloseHandle(PH);
End;

PID is the PID of the other service process, and FDLL is a string with the name to the DLL I wish to Hook to PID.

When I run this code, the other service process dies.

Any idea?

Thanks
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Try it with an empty dll. Does the other process still die? Try it with some of the madCodeHook demo dlls.
Mazinger
Posts: 33
Joined: Wed Jan 26, 2005 6:26 am

Post by Mazinger »

Sorry, it's my fault. I hook a DLL that uses SendIPCMessage to communicate with my application.

When I use this function within a library injected to all system proceses (SYSTEM_PROCESS & ...) my computer crash. When I use this function within a library injected to a single process, the process dies.

I remove the SendIPCMessage function and now the process not dies and the library still gets injected.
Post Reply