ld-preload

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

拥有回忆 提交于 2019-12-01 07:36:17
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? How could i create fake dummy dynamic segment to activate dynamic loader and perform LD_PRELOAD command? You can't. Even if you could, getting LD_PRELOAD to preload something would still be useless: usually you want to interpose some symbols in your LD_PRELOAD ed library, but that requires these symbols to be unresolved in the main binary, or at least

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

风格不统一 提交于 2019-12-01 05:14:56
问题 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? 回答1: How could i create fake dummy dynamic segment to activate dynamic loader and perform LD_PRELOAD command? You can't. Even if you could, getting LD_PRELOAD to preload something would still be useless: usually you want to interpose some symbols in

What is the exact equivalent to LD_PRELOAD on OSX?

和自甴很熟 提交于 2019-11-30 17:51:20
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 <stdio.h> #include <dlfcn.h> #include <stdlib.h> #include <unistd.h> #include <ruby.h> void rb_raise(unsigned long exc, const char *fmt, ...) { static void (*libruby_rb_raise) (unsigned long exc, const char *fmt, ...) = NULL; void * handle; char * error; if (!libruby_rb_raise) { handle = dlopen("/path/to/libruby.so", RTLD_LAZY); if (!handle) { fputs(dlerror(), stderr); exit(1); } libruby_rb

What is the exact equivalent to LD_PRELOAD on OSX?

泪湿孤枕 提交于 2019-11-30 01:18:11
问题 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 <stdio.h> #include <dlfcn.h> #include <stdlib.h> #include <unistd.h> #include <ruby.h> void rb_raise(unsigned long exc, const char *fmt, ...) { static void (*libruby_rb_raise) (unsigned long exc, const char *fmt, ...) = NULL; void * handle; char * error; if (!libruby_rb_raise) { handle =

LD_PRELOAD does not work as expected

被刻印的时光 ゝ 提交于 2019-11-29 11:25:17
问题 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 <command> #include <iostream> struct Goodbye { Goodbye() {std::cout << "Hello\n";} ~Goodbye() {std::cout << "Goodbye!\n";} } goodbye; The problem is that, while the constructor of the global variable goodbye is always called, the destructor is not called for some programs, like ls : $ LD_PRELOAD=./preload.so ls Hello For some

LD_PRELOAD with setuid binary

馋奶兔 提交于 2019-11-29 06:47:33
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 , dir etc. From the documentation of LD_PRELOAD: LD_PRELOAD A whitespace-separated list of additional, user-specified, ELF shared libraries to be loaded before all others. This can be used to selectively override functions in other shared libraries. For set- user-ID/set-group-ID ELF binaries, only libraries in the standard search directories that

LD_PRELOAD only working for malloc, not free

瘦欲@ 提交于 2019-11-29 04:39:27
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)" - but this line is missing. Given // compile with: gcc test.cc #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { void* p = malloc(123); printf("HOST p=%p\n", p); free(p); } And // compile with: g++ -O2 -Wall -fPIC -ldl -o libnano.so -shared main.cc #include <stdio.h> #include <dlfcn.h> typedef void *(*MallocFunc)(size_t size);

LD_PRELOADing malloc and free

随声附和 提交于 2019-11-28 11:11:45
问题 I wrote my own malloc and free and compiled them in a shared library. I LD_PRELOAD that library with my program. In this way would my program always use my custom malloc and free or are there cases where it is not so. I've heard that gcc has built in malloc and free too. Is it possible that the glibc that came with my gcc is using the builtin malloc and free . Secondly, I notice that when I run my program, I'm seeing the free function call more often than the malloc/calloc calls (98 to 16). I

LD_PRELOAD with setuid binary

本秂侑毒 提交于 2019-11-28 00:09:11
问题 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 , dir etc. From the documentation of LD_PRELOAD: LD_PRELOAD A whitespace-separated list of additional, user-specified, ELF shared libraries to be loaded before all others. This can be used to selectively override functions in other shared libraries

LD_PRELOAD only working for malloc, not free

爱⌒轻易说出口 提交于 2019-11-27 22:26:15
问题 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)" - but this line is missing. Given // compile with: gcc test.cc #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { void* p = malloc(123); printf("HOST p=%p\n", p); free(p); } And // compile with: g++ -O2 -Wall -fPIC -ldl -o