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

@ -165,7 +165,7 @@ public class LSPApplication extends ApplicationServiceClient {
XposedHelpers.setObjectField(mBoundApplication, "info", appLoadedApk); XposedHelpers.setObjectField(mBoundApplication, "info", appLoadedApk);
var activityClientRecordClass = XposedHelpers.findClass("android.app.ActivityThread$ActivityClientRecord", ActivityThread.class.getClassLoader()); var activityClientRecordClass = XposedHelpers.findClass("android.app.ActivityThread$ActivityClientRecord", ActivityThread.class.getClassLoader());
var fixActivityClientRecord = (BiConsumer<Object, Object>)(k, v) -> { var fixActivityClientRecord = (BiConsumer<Object, Object>) (k, v) -> {
if (activityClientRecordClass.isInstance(v)) { if (activityClientRecordClass.isInstance(v)) {
var pkgInfo = XposedHelpers.getObjectField(v, "packageInfo"); var pkgInfo = XposedHelpers.getObjectField(v, "packageInfo");
if (pkgInfo == stubLoadedApk) { if (pkgInfo == stubLoadedApk) {
@ -182,7 +182,16 @@ public class LSPApplication extends ApplicationServiceClient {
} }
Log.i(TAG, "hooked app initialized: " + appLoadedApk); 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) { } catch (Throwable e) {
Log.e(TAG, "createLoadedApk", e); Log.e(TAG, "createLoadedApk", e);
return null; return null;

View File

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