rovo89 / Xposed

The native part of the Xposed framework (mainly the modified app_process binary).
Other
7.41k stars 1.47k forks source link

Support .so libiary #242

Closed kaixuanluo closed 7 years ago

kaixuanluo commented 7 years ago

The description: I want handle change voice record data, It need use c++ .so libiary to hook the voice record method and hanle change the record byte[] data, But the .so only support load in current process, in Activity load is work, not support load in class witch implements IXposedHookLoadPackage, I need use the .so libiary in the xposed, what shoud i do.

17 09 25 1723_1

The hook code: final Class<?> audioRecordClazz = findClass("android.media.AudioRecord", lpparam.classLoader); The libiary load code: System.loadLibrary("soundtouch"); // System.load("/data/data/gg.xvoicechanger/files/libsoundtouch.so"); The log: Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/gg.xvoicechanger-1/base.apk"],nativeLibraryDirectories=[/system/lib, /vendor/lib]]] couldn't find "libsoundtouch.so" The system: Android 7.1.2, Xposed-v87

rovo89 commented 7 years ago

Is your .so file (and all its parent directories) world-readable? Your hook is executed in the context of the app you hooked. Usually, apps don't have access to other apps' data files.

kaixuanluo commented 7 years ago

Even .so file world-readable, in android 7.0 , also throw (is not accessible for the namespace "classloader-namespace" ) java.lang.UnsatisfiedLinkError: dlopen failed: library "/sdcard/XVoiceChanger/libsoundtouch.so" needed or dlopened by "/system/lib64/libnativeloader.so" is not accessible for the namespace "classloader-namespace"

rovo89 commented 7 years ago

Yep, that's a change they have introduced to limit access to non-public libraries: https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk

Anything on /data and /mnt/expand should be whitelisted though: https://android.googlesource.com/platform/system/core/+/nougat-release/libnativeloader/native_loader.cpp#43

But /sdcard is not whitelisted.

kaixuanluo commented 7 years ago

Add the .so name to whitelist ? I've write the .so name to /etc/public.libraries.txt, And copy the .so to /system/lib/ And /system/lib64(in 64 bit phone),

The phone(oneplus 3T ,64 bit, android 7.1.1) can't reboot, system error, phone can't work, can't get logs.

And the phone (xiaomi4 ,32bit, android 7.1.1) can load the .so. libiary.

rovo89 commented 7 years ago

Yeah, different devices might behave differently, e.g. because one might have dm-verity enabled (which ensures that no changes to /system were done). That could cause the reboot.

Anyway, I'm going to close this as it's not an Xposed issue. You'd have the same issue if you tried to load a foreign library from a normal app. As mentioned above, putting the .so file somewhere under /data should work, but then you need to take care that the file permissions are set correctly, i.e. they must be world-readable (maybe even executable) for the file and the directories above it.