Fix null classloader

This commit is contained in:
Nullptr 2022-03-04 13:28:48 +08:00
parent bfd4fb12d0
commit 5a16a34cd8
2 changed files with 12 additions and 4 deletions

View File

@ -182,7 +182,16 @@ public class LSPApplication extends ApplicationServiceClient {
}
Log.i(TAG, "hooked app initialized: " + appLoadedApk);
return (Context) XposedHelpers.callStaticMethod(Class.forName("android.app.ContextImpl"), "createAppContext", activityThread, stubLoadedApk);
var context = (Context) XposedHelpers.callStaticMethod(Class.forName("android.app.ContextImpl"), "createAppContext", activityThread, stubLoadedApk);
if (config.appComponentFactory != null) {
try {
context.getClassLoader().loadClass(config.appComponentFactory);
} catch (ClassNotFoundException e) { // This will happen on some strange shells like 360
Log.w(TAG, "Original AppComponentFactory not found: " + config.appComponentFactory);
appInfo.appComponentFactory = null;
}
}
return context;
} catch (Throwable e) {
Log.e(TAG, "createLoadedApk", e);
return null;

View File

@ -223,8 +223,7 @@ public class LSPatch {
var pair = ManifestParser.parseManifestFile(is);
if (pair == null)
throw new PatchError("Failed to parse AndroidManifest.xml");
appComponentFactory = pair.appComponentFactory == null ? "" : pair.appComponentFactory;
appComponentFactory = pair.appComponentFactory;
logger.d("original appComponentFactory class: " + appComponentFactory);
}