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 environment for your app is secured.
Although the offical NDK-r9d documentation still says the same, but it turns out that LD_PRELOAD does work on rooted devices. Run
adb shell
setprop wrap.com.xyz.yourapp LD_PRELOAD=/path/to/your/library.so
stop
start
after pushing the library to the device. I tried it successfully on ANDROID-19 emulator to provide alternate definition of a function.
Check out this link - http://cedricvb.be/post/intercepting-android-native-library-calls/
来源:https://stackoverflow.com/questions/14426191/android-4-2-ld-preload-supported-or-not