currently I'm working on some application plugin written in C++ - on windows I'm injecting dll into process, capturing interfaces and doing my work - but my question is - how can I do something similar on linux? I would prefer doing it without editing executable - code injection to running process.
Asked
Active
Viewed 1,840 times
0
-
Have you looked at dlopen & company? – sfjac Jun 03 '15 at 20:37
-
@sfjac what do you mean by that? If I'm not wrong it's used to load dynamic library into current process, but I want to inject library A into process B which is running – mlgpro Jun 03 '15 at 20:41
1 Answers
1
If you can control the startup of the process, simply use LD_PRELOAD
to force-load a library alongside the executable, possibly shadowing symbols from other libraries (that are linked into the binary):
LD_PRELOAD=/path/to/libfoo.so myapplication
Following is a real-world use-case for adding a v4l2-support layer to v4l1-only applications, by intercepting ioctl
:
LD_PRELOAD=/usr/local/lib/libv4l/v4l1compat.so camorama
To inject symbols into already running processes, checkout out this answer.

umläute
- 28,885
- 9
- 68
- 122
-
and if you want runtime attachement, use something liek explained here: http://stackoverflow.com/questions/27137527/overload-symbols-of-running-process-ld-preload-attachement – milianw Jun 03 '15 at 21:23
-
@milianw, yes i just noticed that (answer!) as well and have already added that to my answer... – umläute Jun 03 '15 at 21:24
-
-
@milianw, that's because i added it (@ 21:25) while you were typing (@ 21:23) :-) – umläute Jun 07 '15 at 21:08