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
27
votes
3 answers

LD_PRELOAD does not work as expected

Consider the following library which can be preloaded before any program execution: // g++ -std=c++11 -shared -fPIC preload.cpp -o preload.so // LD_PRELOAD=./preload.so #include struct Goodbye { Goodbye() {std::cout <<…
Martin
  • 9,089
  • 11
  • 52
  • 87
20
votes
1 answer

What is the exact equivalent to LD_PRELOAD on OSX?

I am using LD_PRELOAD to hook a library function, and in Linux it works perfectly. But I cannot figure out how to do the equivalent in OSX. The setup I have on Linux is as follows: The code is: #include #include #include…
horseyguy
  • 29,455
  • 20
  • 103
  • 145
19
votes
2 answers

link a static library to a shared library and hide exported symbols

I am having an annoying problem with the linker. I want to link some symbols from a shared library to a static library, but not export its symbols (ie, I cannot simply merge the libraries or link with --whole-archive). What I want is link (as in,…
Thibaut
  • 2,400
  • 1
  • 16
  • 28
14
votes
1 answer

Binding failure with objcopy --redefine-syms

Preconditions A third-party has provided a C++ executable fooapp that uses a shared object libfoo.so. The library also comes with a header foo.hpp so developers can build other applications: /* foo.hpp */ namespace foo { void bar(int a, int b); …
BrianTheLion
  • 2,618
  • 2
  • 29
  • 46
11
votes
5 answers

LD_PRELOAD with setuid binary

I am trying to use LD_PRELOAD to preload a library with an application that has setuid permissions. Tried LD_PRELOAD at first, and it seemed like it was being ignored with the setuid binary, though it was working when I tried it with others like ls,…
Mark Lobo
  • 331
  • 2
  • 3
  • 9
9
votes
1 answer

LD_PRELOAD does not loaded on systemd

I am trying to inject a SO into a process that starts using systemd init system (using LD_PRELOAD), but it does not loaded into the new process. I complied a basic SO (unrandom.c): int rand(){ return 42; //the most random number in the…
Or Smolnik
  • 91
  • 1
  • 5
9
votes
2 answers

Dynamically modify symbol table at runtime (in C)

Is it possible to dynamically modify symbol table at runtime in C (in elf format on Linux)? My eventual goal is the following: Inside certain function say foo, I want to override malloc function to my custom handler my_malloc. But outside foo, any…
Richard
  • 14,642
  • 18
  • 56
  • 77
9
votes
2 answers

hiding functions in C

I have application that has a function f1 void f1 () In addition, I have a library that I load using LD_PRELOAD. The library has several code files and several header file, and it compiled to .so file. On of the header files also uses a function…
dk7
  • 323
  • 3
  • 14
8
votes
3 answers

LD_PRELOAD doesn't affect dlopen() with RTLD_NOW

If I use a function from a shared library directly, i.e. by declaring it in my code and linking during compile time, LD_PRELOAD works fine. But if I use dlopen()/dlsym() instead LD_PRELOAD has no effect! The problem is that I want to debug a program…
sashoalm
  • 75,001
  • 122
  • 434
  • 781
7
votes
5 answers

Problems with LD_PRELOAD and calloc() interposition for certain executables

Relating to a previous question of mine I've successfully interposed malloc, but calloc seems to be more problematic. That is with certain hosts, calloc gets stuck in an infinite loop with a possible internal calloc call inside dlsym. However, a…
Justicle
  • 14,761
  • 17
  • 70
  • 94
7
votes
1 answer

LD_PRELOAD only working for malloc, not free

I'm trying to interpose malloc/free/calloc/realloc etc with some interposers via LD_PRELOAD. In my small test, only malloc seems to be interposed, even though free is detected (see output). I'd expect the output to contain a line "NANO: free(x)" -…
Justicle
  • 14,761
  • 17
  • 70
  • 94
7
votes
1 answer

ERROR: ld.so: object 'libproxychains.so.3' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored

When I type the command proxychains chromium on linux terminal it gives me this error: ERROR: ld.so: object 'libproxychains.so.3' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored. Opening in existing browser session.…
Tarlan Omrbkv
  • 73
  • 1
  • 6
7
votes
1 answer

why is library loaded via LD_PRELOAD operating before initialization?

In the following minimal example, a library loaded via LD_PRELOAD with functions to intercept fopen and openat is apparently operating before its initialization. (Linux is CentOS 7.3). Why?? library file comm.c: #define _GNU_SOURCE #include…
Mark Galeck
  • 6,155
  • 1
  • 28
  • 55
7
votes
1 answer

How to make static linked ELF file to load LD_PRELOAD .so

I have static linked binary (ELF file) it doesn't have dynamic segment, .dymsym sections and it doesn't perform LD_PRELOAD command and etc. How could i create fake dummy dynamic segment to activate dynamic loader and perform LD_PRELOAD command?
Kracken
  • 662
  • 1
  • 11
  • 27
7
votes
1 answer

How to check if a linux shared library has been preloaded using LD_PRELOAD

I'm familiar with using dlopen() to check if a shared library has been loaded into a process using a prior call to dlopen() without triggering a load if it isn't present, like so: void* lib = dlopen(lib_name, RTLD_NOLOAD); if (lib != NULL) { …
Timo Geusch
  • 24,095
  • 5
  • 52
  • 70
1
2 3
17 18