From 2c343728037b282a10fac45ab073b44b713526b1 Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Tue, 13 Jul 2021 13:53:27 +0800 Subject: [PATCH] [core] Fix module load on Android 10 (#811) --- .../util/InMemoryDelegateLastClassLoader.java | 32 ++++++++++++++++--- .../java/hidden/ByteBufferDexClassLoader.java | 4 +++ .../dalvik/system/BaseDexClassLoader.java | 4 +++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/lsposed/lspd/util/InMemoryDelegateLastClassLoader.java b/core/src/main/java/org/lsposed/lspd/util/InMemoryDelegateLastClassLoader.java index 996e0232..f7a2dde7 100644 --- a/core/src/main/java/org/lsposed/lspd/util/InMemoryDelegateLastClassLoader.java +++ b/core/src/main/java/org/lsposed/lspd/util/InMemoryDelegateLastClassLoader.java @@ -2,11 +2,14 @@ package org.lsposed.lspd.util; import static de.robv.android.xposed.XposedBridge.TAG; +import android.os.Build; import android.system.ErrnoException; import android.system.Os; import android.system.OsConstants; import android.util.Log; +import androidx.annotation.RequiresApi; + import java.io.File; import java.io.IOException; import java.net.URL; @@ -26,7 +29,7 @@ import hidden.ByteBufferDexClassLoader; public final class InMemoryDelegateLastClassLoader extends ByteBufferDexClassLoader { private static final String zipSeparator = "!/"; private final String apk; - private final List nativeLibraryDirs; + private final List nativeLibraryDirs = new ArrayList<>(); private static List splitPaths(String searchPath) { var result = new ArrayList(); @@ -38,12 +41,24 @@ public final class InMemoryDelegateLastClassLoader extends ByteBufferDexClassLoa } private InMemoryDelegateLastClassLoader(ByteBuffer[] dexBuffers, - String librarySearchPath, ClassLoader parent, String apk) { super(dexBuffers, parent); this.apk = apk; - nativeLibraryDirs = new ArrayList<>(splitPaths(librarySearchPath)); + } + + @RequiresApi(Build.VERSION_CODES.Q) + private InMemoryDelegateLastClassLoader(ByteBuffer[] dexBuffers, + String librarySearchPath, + ClassLoader parent, + String apk) { + super(dexBuffers, librarySearchPath, parent); + initNativeLibraryDirs(librarySearchPath); + this.apk = apk; + } + + private void initNativeLibraryDirs(String librarySearchPath) { + nativeLibraryDirs.addAll(splitPaths(librarySearchPath)); nativeLibraryDirs.addAll(splitPaths(System.getProperty("java.library.path"))); } @@ -157,7 +172,14 @@ public final class InMemoryDelegateLastClassLoader extends ByteBufferDexClassLoa Log.e(TAG, "Can not open " + apk, e); } var dexBuffers = new ByteBuffer[byteBuffers.size()]; - return new InMemoryDelegateLastClassLoader(byteBuffers.toArray(dexBuffers), - librarySearchPath, parent, apk.getAbsolutePath()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + return new InMemoryDelegateLastClassLoader(byteBuffers.toArray(dexBuffers), + librarySearchPath, parent, apk.getAbsolutePath()); + } else { + var cl = new InMemoryDelegateLastClassLoader(byteBuffers.toArray(dexBuffers), + parent, apk.getAbsolutePath()); + cl.initNativeLibraryDirs(librarySearchPath); + return cl; + } } } diff --git a/hiddenapi-bridge/src/main/java/hidden/ByteBufferDexClassLoader.java b/hiddenapi-bridge/src/main/java/hidden/ByteBufferDexClassLoader.java index 70328f18..e9c86146 100644 --- a/hiddenapi-bridge/src/main/java/hidden/ByteBufferDexClassLoader.java +++ b/hiddenapi-bridge/src/main/java/hidden/ByteBufferDexClassLoader.java @@ -8,4 +8,8 @@ public class ByteBufferDexClassLoader extends BaseDexClassLoader { public ByteBufferDexClassLoader(ByteBuffer[] dexFiles, ClassLoader parent) { super(dexFiles, parent); } + + public ByteBufferDexClassLoader(ByteBuffer[] dexFiles, String librarySearchPath, ClassLoader parent) { + super(dexFiles, librarySearchPath, parent); + } } diff --git a/hiddenapi-stubs/src/main/java/dalvik/system/BaseDexClassLoader.java b/hiddenapi-stubs/src/main/java/dalvik/system/BaseDexClassLoader.java index 959aba41..129cd920 100644 --- a/hiddenapi-stubs/src/main/java/dalvik/system/BaseDexClassLoader.java +++ b/hiddenapi-stubs/src/main/java/dalvik/system/BaseDexClassLoader.java @@ -19,6 +19,10 @@ public class BaseDexClassLoader extends ClassLoader { throw new RuntimeException("Stub!"); } + public BaseDexClassLoader(ByteBuffer[] dexFiles, String librarySearchPath, ClassLoader parent) { + throw new RuntimeException("Stub!"); + } + protected Class findClass(String name) throws ClassNotFoundException { throw new RuntimeException("Stub!"); }