Fix native lib not found

This commit is contained in:
Nullptr 2021-07-18 15:25:06 +08:00
parent 8cbf468d59
commit da34877db8
2 changed files with 8 additions and 10 deletions

View File

@ -38,9 +38,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.ArrayList;
@ -49,7 +47,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import dalvik.system.PathClassLoader;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

View File

@ -34,19 +34,18 @@ public class LSPAppComponentFactoryStub extends AppComponentFactory {
/**
* Instantiate original AppComponentFactory<br/>
* This method will be called at <b>instantiateClassLoader</b> by <b>createOrUpdateClassLoaderLocked</b>
*
* @param cl PathClassLoader(originalApk)
**/
private void initOriginalAppComponentFactory(ClassLoader cl, ApplicationInfo aInfo) {
private void initOriginalAppComponentFactory(ApplicationInfo aInfo) {
final String cacheApkPath = aInfo.dataDir + "/cache/origin_apk.bin";
final String originalAppComponentFactoryClass = FileUtils.readTextFromInputStream(cl.getResourceAsStream(ORIGINAL_APP_COMPONENT_FACTORY_ASSET_PATH));
final String originalAppComponentFactoryClass =
FileUtils.readTextFromInputStream(baseClassLoader.getResourceAsStream(ORIGINAL_APP_COMPONENT_FACTORY_ASSET_PATH));
try {
try (InputStream inputStream = cl.getResourceAsStream(ORIGINAL_APK_ASSET_PATH)) {
try (InputStream inputStream = baseClassLoader.getResourceAsStream(ORIGINAL_APK_ASSET_PATH)) {
Files.copy(inputStream, Paths.get(cacheApkPath));
} catch (FileAlreadyExistsException ignored) {
}
appClassLoader = new PathClassLoader(cacheApkPath, cl.getParent());
appClassLoader = new PathClassLoader(cacheApkPath, aInfo.nativeLibraryDir, baseClassLoader.getParent());
if (originalAppComponentFactoryClass == null || originalAppComponentFactoryClass.isEmpty())
originalAppComponentFactory = new AppComponentFactory();
else
@ -60,7 +59,9 @@ public class LSPAppComponentFactoryStub extends AppComponentFactory {
@Override
public ClassLoader instantiateClassLoader(ClassLoader cl, ApplicationInfo aInfo) {
baseClassLoader = cl;
initOriginalAppComponentFactory(cl, aInfo);
initOriginalAppComponentFactory(aInfo);
Log.d(TAG, "baseClassLoader is " + baseClassLoader);
Log.d(TAG, "appClassLoader is " + appClassLoader);
return originalAppComponentFactory.instantiateClassLoader(appClassLoader, aInfo);
}