views:

645

answers:

2

I have an executable module created by third party. I would like to "inject" my code (kind of watchdog running in separate thread) into this process.

So far there are two possible ways - one is to run my code as executable and dynamically load a proess on top of it (seems to be very hard and tricky) or to make my code a shared object, load it via LD_PRELOAD and initialize from some static variable constructor.

Are there more convenient ways to do this ? My OS are Linux x86 and Solaris-SPARC.

Update: If possible, I'd like not to patch the process, but load my code dynamicaly.

+3  A: 

Sounds like you're looking for InjectSo. There's a Powerpoint presentation that explains how it works. I haven't gotten around to trying it out yet.

Rob Kennedy
Yes, their test worked for me. Thanks !
Dmitry Khalatov
Dmitry, on what specific system were you able to get it to work? I haven't been able to yet, with a wide array of old and new systems.
Dan Fego
A: 

Rob Kennedy told you about InjectSo - that's probably what you need.

Beware that the introduction of a thread into a non-threaded process would be fraught with synchronization issues. The problems are less serious if the application is already threaded, but even so, the application may object to a thread that it doesn't know about.

Jonathan Leffler