diff --git a/meta-loader/proguard-rules.pro b/meta-loader/proguard-rules.pro index 70d4e8e..5a2a631 100644 --- a/meta-loader/proguard-rules.pro +++ b/meta-loader/proguard-rules.pro @@ -2,6 +2,13 @@ public static byte[] dex; (); } +-keep class * extends androidx.room.Entity { + ; +} +-keep interface * extends androidx.room.Dao { + ; +} + -dontwarn androidx.annotation.NonNull -dontwarn androidx.annotation.Nullable -dontwarn androidx.annotation.VisibleForTesting diff --git a/patch-loader/src/main/java/org/lsposed/lspatch/loader/LSPApplication.java b/patch-loader/src/main/java/org/lsposed/lspatch/loader/LSPApplication.java index e499603..1c1a285 100644 --- a/patch-loader/src/main/java/org/lsposed/lspatch/loader/LSPApplication.java +++ b/patch-loader/src/main/java/org/lsposed/lspatch/loader/LSPApplication.java @@ -74,6 +74,15 @@ public class LSPApplication { return (android.os.Process.myUid() % PER_USER_RANGE) >= FIRST_APP_ZYGOTE_ISOLATED_UID; } + private static boolean hasEmbeddedModules(Context context) { + try { + String[] list = context.getAssets().list("lspatch/modules"); + return list != null && list.length > 0; + } catch (IOException e) { + return false; + } + } + public static void onLoad() throws RemoteException, IOException { if (isIsolated()) { XLog.d(TAG, "Skip isolated process"); @@ -87,7 +96,8 @@ public class LSPApplication { } Log.d(TAG, "Initialize service client"); - ILSPApplicationService service; + ILSPApplicationService service = null; + if (config.useManager) { try { service = new RemoteApplicationService(context); @@ -106,7 +116,6 @@ public class LSPApplication { Log.e(TAG, "Failed to connect to manager, fallback to fixed local service"); service = new NeoLocalApplicationService(context); } - } else { service = new IntegrApplicationService(context); } @@ -114,11 +123,12 @@ public class LSPApplication { disableProfile(context); Startup.initXposed(false, ActivityThread.currentProcessName(), context.getApplicationInfo().dataDir, service); Startup.bootstrapXposed(); + // WARN: Since it uses `XResource`, the following class should not be initialized // before forkPostCommon is invoke. Otherwise, you will get failure of XResources - if (config.outputLog){ - XposedBridge.setLogPrinter(new XposedLogPrinter(0,"NPatch")); + if (config.outputLog) { + XposedBridge.setLogPrinter(new XposedLogPrinter(0, "NPatch")); } Log.i(TAG, "Load modules"); LSPLoader.initModules(appLoadedApk); @@ -170,19 +180,19 @@ public class LSPApplication { } } Path providerPath = null; - if (config.injectProvider){ + if (config.injectProvider) { try (ZipFile sourceFile = new ZipFile(sourceFileaa)) { - - providerPath = Paths.get(appInfo.dataDir, "cache/npatch/origin/p_" + sourceFile.getEntry(ORIGINAL_APK_ASSET_PATH).getCrc()+".dex"); + providerPath = Paths.get(appInfo.dataDir, "cache/npatch/origin/p_" + sourceFile.getEntry(ORIGINAL_APK_ASSET_PATH).getCrc() + ".dex"); Files.deleteIfExists(providerPath); try (InputStream is = baseClassLoader.getResourceAsStream(PROVIDER_DEX_ASSET_PATH)) { Files.copy(is, providerPath); } - providerPath.toFile().setWritable(false); - }catch (Exception e){ + if (providerPath != null) { + providerPath.toFile().setWritable(false); + } + } catch (Exception e) { Log.e(TAG, "Failed to inject provider:" + Log.getStackTraceString(e)); } - } cacheApkPath.toFile().setWritable(false); @@ -191,9 +201,7 @@ public class LSPApplication { mPackages.remove(appInfo.packageName); appLoadedApk = activityThread.getPackageInfoNoCheck(appInfo, compatInfo); - - - if (config.injectProvider){ + if (config.injectProvider && providerPath != null) { ClassLoader loader = appLoadedApk.getClassLoader(); Object dexPathList = XposedHelpers.getObjectField(loader, "pathList"); Object dexElements = XposedHelpers.getObjectField(dexPathList, "dexElements"); @@ -202,14 +210,13 @@ public class LSPApplication { System.arraycopy(dexElements, 0, newElements, 0, length); DexFile dexFile = new DexFile(providerPath.toString()); - Object element = XposedHelpers.newInstance(XposedHelpers.findClass("dalvik.system.DexPathList$Element",loader), new Class[]{ + Object element = XposedHelpers.newInstance(XposedHelpers.findClass("dalvik.system.DexPathList$Element", loader), new Class[]{ DexFile.class - },dexFile); + }, dexFile); Array.set(newElements, length, element); XposedHelpers.setObjectField(dexPathList, "dexElements", newElements); } - XposedHelpers.setObjectField(mBoundApplication, "info", appLoadedApk); var activityClientRecordClass = XposedHelpers.findClass("android.app.ActivityThread$ActivityClientRecord", ActivityThread.class.getClassLoader()); @@ -242,7 +249,7 @@ public class LSPApplication { appInfo.appComponentFactory = null; } } - Log.i(TAG,"createLoadedApkWithContext cost: " + (System.currentTimeMillis() - timeStart) + "ms"); + Log.i(TAG, "createLoadedApkWithContext cost: " + (System.currentTimeMillis() - timeStart) + "ms"); SigBypass.replaceApplication(appInfo.packageName, appInfo.sourceDir, appInfo.publicSourceDir); return context; diff --git a/patch/src/main/java/org/lsposed/patch/LSPatch.java b/patch/src/main/java/org/lsposed/patch/LSPatch.java index 9979d86..bf59ed1 100644 --- a/patch/src/main/java/org/lsposed/patch/LSPatch.java +++ b/patch/src/main/java/org/lsposed/patch/LSPatch.java @@ -328,9 +328,12 @@ public class LSPatch { if (!useManager) { logger.i("Adding loader dex..."); try (var is = getClass().getClassLoader().getResourceAsStream(LOADER_DEX_ASSET_PATH)) { + if (is == null) { + throw new PatchError("Fatal: Could not find " + LOADER_DEX_ASSET_PATH + " in the patcher resources!"); + } dstZFile.add(LOADER_DEX_ASSET_PATH, is); } catch (Throwable e) { - throw new PatchError("Error when adding assets", e); + throw new PatchError("Error when adding loader.dex", e); } logger.i("Adding native lib...");