Put original dex files in patched APK
Count the number of dex files and rename classes.dex correctly. Skip loading lspatch.so when currentActivityThread is null.
This commit is contained in:
parent
d8b08ca3b7
commit
89b71ebe0a
|
|
@ -2,6 +2,7 @@ package org.lsposed.lspatch.metaloader;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AppComponentFactory;
|
||||
import android.app.ActivityThread;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.IPackageManager;
|
||||
import android.os.Build;
|
||||
|
|
@ -34,6 +35,15 @@ public class LSPAppComponentFactoryStub extends AppComponentFactory {
|
|||
public static byte[] dex;
|
||||
|
||||
static {
|
||||
final boolean appZygote = ActivityThread.currentActivityThread() == null;
|
||||
if (appZygote) {
|
||||
Log.i(TAG, "Skip loading liblspatch.so for appZygote");
|
||||
} else {
|
||||
bootstrap();
|
||||
}
|
||||
}
|
||||
|
||||
private static void bootstrap() {
|
||||
try {
|
||||
archToLib.put("arm", "armeabi-v7a");
|
||||
archToLib.put("arm64", "arm64-v8a");
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class LSPatch {
|
||||
|
||||
|
|
@ -253,7 +254,11 @@ public class LSPatch {
|
|||
|
||||
logger.i("Adding metaloader dex...");
|
||||
try (var is = getClass().getClassLoader().getResourceAsStream(Constants.META_LOADER_DEX_ASSET_PATH)) {
|
||||
dstZFile.add("classes.dex", is);
|
||||
var dexCount = srcZFile.entries().stream().filter(entry -> {
|
||||
var name = entry.getCentralDirectoryHeader().getName();
|
||||
return name.startsWith("classes") && name.endsWith(".dex");
|
||||
}).collect(Collectors.toList()).size() + 1;
|
||||
dstZFile.add("classes" + dexCount + ".dex", is);
|
||||
} catch (Throwable e) {
|
||||
throw new PatchError("Error when adding dex", e);
|
||||
}
|
||||
|
|
@ -289,7 +294,6 @@ public class LSPatch {
|
|||
|
||||
for (StoredEntry entry : srcZFile.entries()) {
|
||||
String name = entry.getCentralDirectoryHeader().getName();
|
||||
if (name.startsWith("classes") && name.endsWith(".dex")) continue;
|
||||
if (dstZFile.get(name) != null) continue;
|
||||
if (name.equals("AndroidManifest.xml")) continue;
|
||||
if (name.startsWith("META-INF") && (name.endsWith(".SF") || name.endsWith(".MF") || name.endsWith(".RSA"))) continue;
|
||||
|
|
|
|||
Loading…
Reference in New Issue