Fix modules missing after update loader for integrated mode

This commit is contained in:
Nullptr 2022-11-13 22:43:39 +08:00
parent 010aa7a270
commit 2ace2660b4
No known key found for this signature in database
7 changed files with 24 additions and 8 deletions

View File

@ -210,8 +210,8 @@ private fun PatchOptionsBody(modifier: Modifier, onAddEmbed: () -> Unit) {
selected = !viewModel.useManager,
onClick = { viewModel.useManager = false },
icon = Icons.Outlined.WorkOutline,
title = stringResource(R.string.patch_portable),
desc = stringResource(R.string.patch_portable_desc),
title = stringResource(R.string.patch_integrated),
desc = stringResource(R.string.patch_integrated_desc),
extraContent = {
TextButton(
onClick = onAddEmbed,

View File

@ -158,7 +158,7 @@ fun AppManageBody(
text = buildAnnotatedString {
val (text, color) =
if (it.second.useManager) stringResource(R.string.patch_local) to MaterialTheme.colorScheme.secondary
else stringResource(R.string.patch_portable) to MaterialTheme.colorScheme.tertiary
else stringResource(R.string.patch_integrated) to MaterialTheme.colorScheme.tertiary
append(AnnotatedString(text, SpanStyle(color = color)))
append(" ")
if (isRolling) append(stringResource(R.string.manage_rolling))

View File

@ -89,7 +89,7 @@ class AppManageViewModel : ViewModel() {
LSPPackageManager.cleanTmpApkDir()
val apkPaths = listOf(appInfo.app.sourceDir) + (appInfo.app.splitSourceDirs ?: emptyArray())
val patchPaths = mutableListOf<String>()
val embeddedModulePaths = if (config.useManager) emptyList<String>() else null
val embeddedModulePaths = mutableListOf<String>()
for (apk in apkPaths) {
ZipFile(apk).use { zip ->
var entry = zip.getEntry(Constants.ORIGINAL_APK_ASSET_PATH)
@ -104,6 +104,19 @@ class AppManageViewModel : ViewModel() {
}
}
}
ZipFile(appInfo.app.sourceDir).use { zip ->
zip.entries().iterator().forEach { entry ->
if (entry.name.startsWith(Constants.EMBEDDED_MODULES_ASSET_PATH)) {
val dst = lspApp.tmpApkDir.resolve(entry.name.substringAfterLast('/'))
embeddedModulePaths.add(dst.absolutePath)
zip.getInputStream(entry).use { input ->
dst.outputStream().use { output ->
input.copyTo(output)
}
}
}
}
}
Patcher.patch(logger, Patcher.Options(config, patchPaths, embeddedModulePaths))
val (status, message) = LSPPackageManager.install()
if (status != PackageInstaller.STATUS_SUCCESS) throw RuntimeException(message)

View File

@ -53,8 +53,8 @@
<string name="patch_mode">Patch Mode</string>
<string name="patch_local">Local</string>
<string name="patch_local_desc">Patch an app without modules embedded.\nThe patched app need the manager running in background, and Xposed scope can be changed dynamically without re-patch.\nLocal patched apps can only run on the local device.</string>
<string name="patch_portable">Portable</string>
<string name="patch_portable_desc">Patch an app with modules embedded.\nThe patched app can run without the manager, but cannot be managed dynamically.\nPortable patched apps can be used on devices that do not have LSPatch Manager installed.</string>
<string name="patch_integrated">Integrated</string>
<string name="patch_integrated_desc">Patch an app with modules embedded.\nThe patched app can run without the manager, but cannot be managed dynamically.\nIntegrated patched apps can be used on devices that do not have LSPatch Manager installed.</string>
<string name="patch_embed_modules">Embed modules</string>
<string name="patch_debuggable">Debuggable</string>
<string name="patch_sigbypass">Signature bypass</string>

View File

@ -8,6 +8,7 @@ import android.os.ParcelFileDescriptor;
import android.util.Log;
import org.lsposed.lspatch.loader.util.FileUtils;
import org.lsposed.lspatch.share.Constants;
import org.lsposed.lspatch.util.ModuleLoader;
import org.lsposed.lspd.models.Module;
import org.lsposed.lspd.service.ILSPApplicationService;
@ -33,7 +34,7 @@ public class LocalApplicationService extends ILSPApplicationService.Stub {
String modulePath = context.getCacheDir() + "/lspatch/" + packageName + "/";
String cacheApkPath;
try (ZipFile sourceFile = new ZipFile(context.getPackageResourcePath())) {
cacheApkPath = modulePath + sourceFile.getEntry("assets/lspatch/modules/" + name).getCrc() + ".apk";
cacheApkPath = modulePath + sourceFile.getEntry(Constants.EMBEDDED_MODULES_ASSET_PATH + name).getCrc() + ".apk";
}
if (!Files.exists(Paths.get(cacheApkPath))) {

View File

@ -1,6 +1,7 @@
package org.lsposed.patch;
import static org.lsposed.lspatch.share.Constants.CONFIG_ASSET_PATH;
import static org.lsposed.lspatch.share.Constants.EMBEDDED_MODULES_ASSET_PATH;
import static org.lsposed.lspatch.share.Constants.LOADER_DEX_ASSET_PATH;
import static org.lsposed.lspatch.share.Constants.ORIGINAL_APK_ASSET_PATH;
import static org.lsposed.lspatch.share.Constants.PROXY_APP_COMPONENT_FACTORY;
@ -306,7 +307,7 @@ public class LSPatch {
var manifest = Objects.requireNonNull(ManifestParser.parseManifestFile(xmlIs));
var packageName = manifest.packageName;
logger.i(" - " + packageName);
zFile.add("assets/lspatch/modules/" + packageName + ".apk", fileIs);
zFile.add(EMBEDDED_MODULES_ASSET_PATH + packageName + ".apk", fileIs);
} catch (NullPointerException | IOException e) {
logger.e(module + " does not exist or is not a valid apk file.");
}

View File

@ -6,6 +6,7 @@ public class Constants {
final static public String LOADER_DEX_ASSET_PATH = "assets/lspatch/loader.dex";
final static public String META_LOADER_DEX_ASSET_PATH = "assets/lspatch/metaloader.dex";
final static public String ORIGINAL_APK_ASSET_PATH = "assets/lspatch/origin.apk";
final static public String EMBEDDED_MODULES_ASSET_PATH = "assets/lspatch/modules/";
final static public String PATCH_FILE_SUFFIX = "-lspatched.apk";
final static public String PROXY_APP_COMPONENT_FACTORY = "org.lsposed.lspatch.metaloader.LSPAppComponentFactoryStub";