Questions tagged [ld-preload]

LD_PRELOAD is a list of additional ELF shared objects that should be loaded first.

LD_PRELOAD is a list of additional ELF shared objects that should be loaded first.

For more information, visit this website

http://man7.org/linux/man-pages/man8/ld.so.8.html

265 questions
5
votes
1 answer

Setting the LD_PRELOAD environment variable for commands run without typing the full path

I'm playing around with LD_PRELOAD and have produced a library that simply wraps puts() in a function that converts the string to be printed to uppercase before printing. I then export the LD_PRELOAD variable as so $ export…
eltommo
  • 346
  • 3
  • 15
4
votes
2 answers

Is it possible for an LD_PRELOAD to only affect the main executable?

The Actual Problem I have an executable that by default uses EGL and SDL 1.2 to handle graphics and user input respectively. Using LD_PRELOAD, I have replaced both with GLFW. This works normally unless the user has installed the Wayland version of…
4
votes
3 answers

Conflicting types compiling a LD_PRELOAD wrapper

I tried to use LD_PRELOAD to hook sprintf function , so I will print to file the result of buffer: #define _GNU_SOURCE #include #include int sprintf (char * src , const char * format , char* argp) { int…
MicrosoctCprog
  • 460
  • 1
  • 3
  • 23
4
votes
1 answer

Why does LD_PRELOAD work with syscalls? ​

The idea of LD_PRELOAD is to load a shared library before the original shared library, for example I can compile mylib.so to load it before libc.so, so when process wants to use printf it searches in the so that loaded one by one and finds it in…
yfr24493AzzrggAcom
  • 159
  • 1
  • 2
  • 13
4
votes
1 answer

Can LD_PRELOAD be used to load different versions of glibc?

Cast of characters big-old-app is linked to an old version of glibc, say glibc-2.12. I cannot do anything to change this. cute-new-addon.o is linked to a newer version, glibc-2.23. This glibc-2.23 is in a nonstandard path (because I don't have…
Kit
  • 30,365
  • 39
  • 105
  • 149
4
votes
1 answer

LD_PRELOAD in docker

When I run docker as following: docker run -it -e LD_PRELOAD=/bin/xyz.so bash env It runs as expected, and the output…
BezBran
  • 161
  • 1
  • 8
4
votes
4 answers

LD_PRELOAD can not intercept syscalls, but only libcalls?

My code works well with malloc, but not with mmap. The code is below: main.c #include #include int main(){ int * p = (int*) malloc(sizeof(int)); printf("in main(): value p = %d\n", *p); free(p); } preload.c #define…
Richard
  • 14,642
  • 18
  • 56
  • 77
4
votes
2 answers

Will a C compiled .so work with a C++ application?

If I want to dynamically link a shared library (.so) for a C++ application (which was built with g++) using LD_PRELOAD, does it matter if the .so is generated from a C source file (using gcc) or a C++ source file (using g++)? And why or why not?…
Naly Gneh
  • 63
  • 3
4
votes
2 answers

Why is LD_PRELOAD usage discouraged?

I came across this piece of advice on the Google's tcmalloc documentation page. You can use TCMalloc in applications you didn't compile yourself, by using LD_PRELOAD: $ LD_PRELOAD="/usr/lib/libtcmalloc.so" LD_PRELOAD is tricky, and we don't…
Sam
  • 19,708
  • 4
  • 59
  • 82
4
votes
1 answer

How can I override C functions (like with LD_PRELOAD) at runtime?

I have some Python code that uses a library that implements virtual file systems. For the drivers for those virtual file systems to work a bunch of C functions (like readdir(), opendir(), fseek()) need to be overridden/replaced - with the…
false_azure
  • 1,333
  • 4
  • 25
  • 46
4
votes
1 answer

How can I inject a background thread to an application with LD_PRELOAD?

I know that LD_PRELOAD can be used to intercept calls to functions in shared libraries (if the app is not statically linked). However, I do not know how it can be used to add additional features or background threads to applications. For example, I…
feeling_lonely
  • 6,665
  • 4
  • 27
  • 53
4
votes
2 answers

How to defeat framework injections?

Is anyone hardening their code in an attempt to detect injections? For example, if someone is trying to intercept a username/password via NSUrlConnection, they could use LD_PRELOAD/DYLD_LIBRARY_PATH, provide exports for my calls into…
jww
  • 97,681
  • 90
  • 411
  • 885
3
votes
1 answer

How to preload library with ld_preload to wine(windows game)?

I want to learn how to preload and hook functions in wine running windows apps. I'm trying to preload a library with ld_preload to wine(windows game(32-bit)) on Arch Linux (64-bit but I think I installed 32-bit support). I get the error wrong ELF…
JustOneMan
  • 231
  • 1
  • 9
  • 34
3
votes
3 answers

How to set LD_PRELOAD in systemd

I want to hook some functions in libssl with LD_PRELOAD in systemd. In systemd file I put ExecStart=/etc/myscript.sh and in /etc/myscript.sh I put #!/bin/sh LD_PRELOAD=/lib/inject_libssl.so /bin/run When I look at /proc/RUN_PID/maps I can see that…
Kokomelom
  • 143
  • 1
  • 10
3
votes
1 answer

How to get command line arguments inside LD_PRELOAD library

I would like to get argv from an LD_PRELOAD library, for instance, let us assume we call LD_PRELOAD=/path/to/my/fopen ./program input Inside my custom fopen I would like to get "input", hence the argv[1] of my program (also the argv[2] and so…
Maray97
  • 140
  • 1
  • 11
1 2
3
17 18