Jump to content
Tuts 4 You

injected DLL and exe communication


kolynet

Recommended Posts

hey! i have my 'detour drawtext hook' dll injected to a process with my custom injector. i would like to achieve IPC or WM_COPYDATA style data passing between them. i can send messages from my application to the dll, but cannot communicate back. im also not sure which should be the client or server. What would be the easiest and best way to get this task done?

 

thanks very much in advance:)

Link to comment

If u need a lightning fast 2 way ipc w/many reads/writes p/second, then I think semaphores w/shared memory is the best way, but this isn't the most straightforward.


 


For something more normal, plain old files work well


 


if u can spawn a proc as a child, then pipes are easy to work w/also.


 


sockets are an option, it doesnt matter which is the client/server


 


for WM_COPYDATA i think both processes need to be windows apps.


 


u can also use registry keys, probably many more options too


  • Like 1
Link to comment

My personal favorites and suggestions would be:


 - MMF's (Memory Mapped Files): http://msdn.microsoft.com/en-us/library/dd997372(v=vs.110).aspx


 - Sockets: For this I use zmq: http://zeromq.org/


 


From personal experience in a very heavy work load, I would not recommend mail slots or named pipes. They are very very poor performance wise and did not handle high-load situations well. Named pipes were the worst I personally tested under heavy 10k-100k+ packet testing loads where the pipe would corrupt and just ultimately die. 


 


I wrote a custom protocol with MMFs that worked flawlessly and had no issues at all in high-load situations. So I tend to stick to them most of the time. I was recently in the last year introduced to zmq which does great as well and will more than likely be what I use for now on with IPC. 


  • Like 1
Link to comment

zmq looks pretty awesome, thanks for the info. 


 


I personally use MMFs as well.  How I do mine is I have 2 MMFs: one for incoming messages, and another for outgoing.  I use semaphores for signaling, and I use a lock-free system with InterlockedCompareExchange to solve buffer contention.  Because mine is threaded I need to consider thread safety.  So I have a Uint pointer to the beginning of my MMFs. This value tells whether it's safe to use.  0 = free for write access, 1 = in use, 2 = free for read access.  Use atomic operation (the interlocked operation i mentioned before) for accessing it and you don't need any other kind of lock. 


 


My protocol is like this: Byte (message type), Uint (message length), followed by the message.  It's bi-directional, incredibly high bandwidth, and basically zero latency....it has to be measured in microseconds.  I've used this technique for a C++ self injecting DLL and a C# client app that processes a lot of data.


Edited by electroglyph
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...