ld-preload

Function interposition only working for malloc not free

橙三吉。 提交于 2019-12-07 23:29:34
问题 I've come across a small problem while monitoring malloc and free trough the use of function interposition. When performing the function interposition for just malloc, it works as exepcted. However, when trying to interpose free as well it ends up in a loop; i seems like free is recursivly invoked but i just dont know why. This is the code for the malloc and free functions. (mod_malloc_free.c) #define _GNU_SOURCE #include <stdio.h> #include <stdint.h> #include <dlfcn.h> void* malloc(size_t

Android 4.2 - LD_PRELOAD supported or not?

二次信任 提交于 2019-12-07 16:39:37
问题 I wonder if LD_PRELOAD is now supported with the newer Android-versions? At the time of 4.0 ICS it wasn't, and in the documentation (NDK docs/SYSTEM-ISSUES.html) there's still: No support for LD_LIBRARY_PATH, LD_PRELOAD, RTLD_LOCAL and many other options. But some days ago I have used LD_LIBRARY_PATH on my Android 4.2 Galaxy Nexus and it worked (!). Thanks in advance! 回答1: Generally speaking, LD_LIBRARY_PATH has worked on engineering builds (a.k.a. rooted devices) for quite a while. The

intercepting the openat() system call for GNU tar

一曲冷凌霜 提交于 2019-12-07 08:10:45
问题 I'm trying to intercept the openat() system call on Linux using a custom shared library that I can load via LD_PRELOAD . An example intercept-openat.c has this content: #define _GNU_SOURCE #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <dlfcn.h> int (*_original_openat)(int dirfd, const char *pathname, int flags, mode_t mode); void init(void) __attribute__((constructor)); int openat(int dirfd, const char *pathname, int flags, mode_t mode); void

Is it possible to make an arbitrary program ignore signals?

旧时模样 提交于 2019-12-06 13:33:55
问题 Specifically on Mac OS X, is it possible to make a program ignore SIGTERM via DYLD_INSERT_LIBRARIES, in a way which works for any or most programs? I tried compiling and inserting this: #include<stdio.h> #include<signal.h> #include<unistd.h> void sig_handler(int signo) { if (signo == SIGTERM) printf("received SIGTERM\n"); } int main(void) { signal(SIGTERM, sig_handler); return 0; } However, DYLD_INSERT_LIBRARIES=libignore.dylib sleep 60 was able to be kill -15'd without issue. 回答1: You can

Function interposition only working for malloc not free

為{幸葍}努か 提交于 2019-12-06 10:28:47
I've come across a small problem while monitoring malloc and free trough the use of function interposition. When performing the function interposition for just malloc, it works as exepcted. However, when trying to interpose free as well it ends up in a loop; i seems like free is recursivly invoked but i just dont know why. This is the code for the malloc and free functions. (mod_malloc_free.c) #define _GNU_SOURCE #include <stdio.h> #include <stdint.h> #include <dlfcn.h> void* malloc(size_t size) { static void* (*real_malloc)(size_t) = NULL; printf("%s\n", "inside shared malloc"); if(!real

Android 4.2 - LD_PRELOAD supported or not?

谁都会走 提交于 2019-12-06 02:30:27
I wonder if LD_PRELOAD is now supported with the newer Android-versions? At the time of 4.0 ICS it wasn't, and in the documentation (NDK docs/SYSTEM-ISSUES.html) there's still: No support for LD_LIBRARY_PATH, LD_PRELOAD, RTLD_LOCAL and many other options. But some days ago I have used LD_LIBRARY_PATH on my Android 4.2 Galaxy Nexus and it worked (!). Thanks in advance! Generally speaking, LD_LIBRARY_PATH has worked on engineering builds (a.k.a. rooted devices) for quite a while. The problem is that this does not help for production builds - not because the loader is changed, but because the

LD_PRELOAD can not intercept syscalls, but only libcalls?

时光总嘲笑我的痴心妄想 提交于 2019-12-06 00:07:10
My code works well with malloc , but not with mmap . The code is below: main.c #include <stdio.h> #include <stdlib.h> int main(){ int * p = (int*) malloc(sizeof(int)); printf("in main(): value p = %d\n", *p); free(p); } preload.c #define _GNU_SOURCE #include <time.h> #include <dlfcn.h> #include <stdio.h> #include <sys/types.h> void *(*orig_malloc)(size_t size); void *malloc(size_t size){ printf(" Hooked(preload)! malloc:size:%lu\n", size); return orig_malloc(size); } void * (*orig_mmap)(void *start, size_t length, int prot, int flags, int fd, off_t offset); void * mmap(void *start, size_t

intercepting the openat() system call for GNU tar

為{幸葍}努か 提交于 2019-12-05 09:42:41
I'm trying to intercept the openat() system call on Linux using a custom shared library that I can load via LD_PRELOAD . An example intercept-openat.c has this content: #define _GNU_SOURCE #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <dlfcn.h> int (*_original_openat)(int dirfd, const char *pathname, int flags, mode_t mode); void init(void) __attribute__((constructor)); int openat(int dirfd, const char *pathname, int flags, mode_t mode); void init(void) { _original_openat = (int (*)(int, const char *, int, mode_t)) dlsym(RTLD_NEXT, "openat"); }

Is it possible to make an arbitrary program ignore signals?

孤人 提交于 2019-12-04 19:45:48
Specifically on Mac OS X, is it possible to make a program ignore SIGTERM via DYLD_INSERT_LIBRARIES, in a way which works for any or most programs? I tried compiling and inserting this: #include<stdio.h> #include<signal.h> #include<unistd.h> void sig_handler(int signo) { if (signo == SIGTERM) printf("received SIGTERM\n"); } int main(void) { signal(SIGTERM, sig_handler); return 0; } However, DYLD_INSERT_LIBRARIES=libignore.dylib sleep 60 was able to be kill -15'd without issue. You can create an executable that sets the action for SIGTERM to SIG_IGN and then execvp() the program you would like

Problems with LD_PRELOAD and calloc() interposition for certain executables

风流意气都作罢 提交于 2019-12-03 08:04:50
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 basic test host does not exhibit this behaviour, but my system's "ls" command does. Here's my code: // build with: g++ -O2 -Wall -fPIC -ldl -o libnano.so -shared Main.cc #include <stdio.h> #include <dlfcn.h> bool gNanoUp = false;// global // Function types typedef void* (*MallocFn)(size_t size); typedef void* (*CallocFn)(size_t elements, size_t size)