diff --git a/stub/src/main/java/com/topjohnwu/magisk/ClassLoaders.java b/stub/src/main/java/com/topjohnwu/magisk/ClassLoaders.java index 95071a945..9e2c5da01 100644 --- a/stub/src/main/java/com/topjohnwu/magisk/ClassLoaders.java +++ b/stub/src/main/java/com/topjohnwu/magisk/ClassLoaders.java @@ -130,15 +130,12 @@ class StubClassLoader extends ClassLoader { class DelegateClassLoader extends ClassLoader { - // The active classloader - static ClassLoader cl = DelegateClassLoader.class.getClassLoader(); - DelegateClassLoader() { super(null); } @Override protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - return cl.loadClass(name); + return DynLoad.activeClassLoader.loadClass(name); } } diff --git a/stub/src/main/java/com/topjohnwu/magisk/DelegateComponentFactory.java b/stub/src/main/java/com/topjohnwu/magisk/DelegateComponentFactory.java index 2b99f9336..a6c78a384 100644 --- a/stub/src/main/java/com/topjohnwu/magisk/DelegateComponentFactory.java +++ b/stub/src/main/java/com/topjohnwu/magisk/DelegateComponentFactory.java @@ -37,7 +37,7 @@ public class DelegateComponentFactory extends AppComponentFactory { public Activity instantiateActivity(ClassLoader cl, String className, Intent intent) throws ClassNotFoundException, IllegalAccessException, InstantiationException { if (receiver != null) - return receiver.instantiateActivity(DelegateClassLoader.cl, className, intent); + return receiver.instantiateActivity(DynLoad.activeClassLoader, className, intent); return create(className, DownloadActivity.class); } @@ -45,7 +45,7 @@ public class DelegateComponentFactory extends AppComponentFactory { public BroadcastReceiver instantiateReceiver(ClassLoader cl, String className, Intent intent) throws ClassNotFoundException, IllegalAccessException, InstantiationException { if (receiver != null) - return receiver.instantiateReceiver(DelegateClassLoader.cl, className, intent); + return receiver.instantiateReceiver(DynLoad.activeClassLoader, className, intent); return create(className, DummyReceiver.class); } @@ -53,7 +53,7 @@ public class DelegateComponentFactory extends AppComponentFactory { public Service instantiateService(ClassLoader cl, String className, Intent intent) throws ClassNotFoundException, IllegalAccessException, InstantiationException { if (receiver != null) - return receiver.instantiateService(DelegateClassLoader.cl, className, intent); + return receiver.instantiateService(DynLoad.activeClassLoader, className, intent); return create(className, DummyService.class); } @@ -61,7 +61,7 @@ public class DelegateComponentFactory extends AppComponentFactory { public ContentProvider instantiateProvider(ClassLoader cl, String className) throws ClassNotFoundException, IllegalAccessException, InstantiationException { if (receiver != null) - return receiver.instantiateProvider(DelegateClassLoader.cl, className); + return receiver.instantiateProvider(DynLoad.activeClassLoader, className); return create(className, DummyProvider.class); } @@ -69,7 +69,7 @@ public class DelegateComponentFactory extends AppComponentFactory { throws IllegalAccessException, InstantiationException { try { // noinspection unchecked - return (T) DelegateClassLoader.cl.loadClass(name).newInstance(); + return (T) DynLoad.activeClassLoader.loadClass(name).newInstance(); } catch (ClassNotFoundException e) { return fallback.newInstance(); } diff --git a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java index d74cbff9d..15cb2e61c 100644 --- a/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java +++ b/stub/src/main/java/com/topjohnwu/magisk/DownloadActivity.java @@ -59,7 +59,7 @@ public class DownloadActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (DelegateClassLoader.cl instanceof AppClassLoader) { + if (DynLoad.activeClassLoader instanceof AppClassLoader) { // For some reason activity is created before Application.attach(), // relaunch the activity using the same intent finishAffinity(); diff --git a/stub/src/main/java/com/topjohnwu/magisk/DynLoad.java b/stub/src/main/java/com/topjohnwu/magisk/DynLoad.java index 3331a9a73..f33adbee4 100644 --- a/stub/src/main/java/com/topjohnwu/magisk/DynLoad.java +++ b/stub/src/main/java/com/topjohnwu/magisk/DynLoad.java @@ -28,6 +28,7 @@ import io.michaelrocks.paranoid.Obfuscate; public class DynLoad { static Object componentFactory; + static ClassLoader activeClassLoader = DynLoad.class.getClassLoader(); static StubApk.Data createApkData() { var data = new StubApk.Data(); @@ -150,7 +151,7 @@ public class DynLoad { delegate.receiver = (AppComponentFactory) factory; } - DelegateClassLoader.cl = cl; + activeClassLoader = cl; // Send real application to attachBaseContext attachContext(app, context); @@ -161,7 +162,7 @@ public class DynLoad { apk.delete(); } - DelegateClassLoader.cl = new StubClassLoader(info); + activeClassLoader = new StubClassLoader(info); return null; }