fix loader's loader

This commit is contained in:
327135569 2021-04-24 14:45:41 +08:00
parent ab1a213161
commit bc84cd5add
7 changed files with 27 additions and 20 deletions

View File

@ -38,8 +38,8 @@ android {
dependsOn("assemble$buildType") dependsOn("assemble$buildType")
def dexFilePath = "$buildDir/intermediates/dex/${variantLowered}/mergeDex${buildType}/classes.dex" def dexFilePath = "$buildDir/intermediates/dex/${variantLowered}/mergeDex${buildType}/classes.dex"
from dexFilePath from dexFilePath
rename "(.*).dex", "classes-${version_name}.dex" rename "(.*).dex", "lsploader.dex"
into "$rootProject.projectDir/out/list-dex" into "$rootProject.projectDir/out/list-assets"
} }
task "copySo$buildType"(type: Copy) { task "copySo$buildType"(type: Copy) {

View File

@ -3,6 +3,7 @@ package org.lsposed.lspatch.loader;
import static android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE; import static android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE;
import static org.lsposed.lspatch.loader.LSPLoader.initAndLoadModules; import static org.lsposed.lspatch.loader.LSPLoader.initAndLoadModules;
import android.annotation.SuppressLint;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
@ -30,6 +31,7 @@ import de.robv.android.xposed.XposedInit;
/** /**
* Created by Windysha * Created by Windysha
*/ */
@SuppressLint("UnsafeDynamicallyLoadedCode")
public class LSPApplication extends Application { public class LSPApplication extends Application {
private static final String ORIGINAL_APPLICATION_NAME_ASSET_PATH = "original_application_name.ini"; private static final String ORIGINAL_APPLICATION_NAME_ASSET_PATH = "original_application_name.ini";
private static final String ORIGINAL_SIGNATURE_ASSET_PATH = "original_signature_info.ini"; private static final String ORIGINAL_SIGNATURE_ASSET_PATH = "original_signature_info.ini";
@ -62,15 +64,15 @@ public class LSPApplication extends Application {
XLog.d(TAG, "skip isolated process"); XLog.d(TAG, "skip isolated process");
} }
else { else {
System.loadLibrary("lspd");
YahfaHooker.init();
XposedInit.startsSystemServer = false;
context = XpatchUtils.createAppContext(); context = XpatchUtils.createAppContext();
if (context == null) { if (context == null) {
XLog.e(TAG, "create context err"); XLog.e(TAG, "create context err");
} }
else { else {
System.load(context.getApplicationInfo().nativeLibraryDir + "/liblspd.so");
YahfaHooker.init();
XposedInit.startsSystemServer = false;
originalApplicationName = FileUtils.readTextFromAssets(context, ORIGINAL_APPLICATION_NAME_ASSET_PATH); originalApplicationName = FileUtils.readTextFromAssets(context, ORIGINAL_APPLICATION_NAME_ASSET_PATH);
originalSignature = FileUtils.readTextFromAssets(context, ORIGINAL_SIGNATURE_ASSET_PATH); originalSignature = FileUtils.readTextFromAssets(context, ORIGINAL_SIGNATURE_ASSET_PATH);

View File

@ -68,7 +68,7 @@ public class LSPLoader {
ClassLoader mcl = new DelegateLastClassLoader(moduleApkPath, nativePath.toString(), initLoader); ClassLoader mcl = new DelegateLastClassLoader(moduleApkPath, nativePath.toString(), initLoader);
try { try {
if (mcl.loadClass(XposedBridge.class.getName()).getClassLoader() != appClassLoader) { if (mcl.loadClass(XposedBridge.class.getName()).getClassLoader() != initLoader) {
Log.e(TAG, "Cannot load module:"); Log.e(TAG, "Cannot load module:");
Log.e(TAG, "The Xposed API classes are compiled into the module's APK."); Log.e(TAG, "The Xposed API classes are compiled into the module's APK.");
Log.e(TAG, "This may cause strange issues and must be fixed by the module developer."); Log.e(TAG, "This may cause strange issues and must be fixed by the module developer.");

View File

@ -11,6 +11,7 @@ android {
versionName "1.0" versionName "1.0"
consumerProguardFiles "consumer-rules.pro" consumerProguardFiles "consumer-rules.pro"
multiDexEnabled false
} }
buildTypes { buildTypes {
@ -39,14 +40,7 @@ android {
into "$rootProject.projectDir/out/list-dex" into "$rootProject.projectDir/out/list-dex"
} }
task "copySo$buildType"(type: Copy) {
dependsOn("assemble$buildType")
from "$buildDir/intermediates/merged_native_libs/${variantLowered}/out/lib"
into "$rootProject.projectDir/out/list-so"
}
task "copy$buildType"() { task "copy$buildType"() {
dependsOn("copySo$buildType")
dependsOn("copyDex$buildType") dependsOn("copyDex$buildType")
doLast { doLast {

View File

@ -14,8 +14,8 @@ import java.nio.ByteBuffer;
import dalvik.system.InMemoryDexClassLoader; import dalvik.system.InMemoryDexClassLoader;
public class LSPApplicationSub extends Application { public class LSPApplicationStub extends Application {
final static String TAG = LSPApplicationSub.class.getSimpleName(); final static String TAG = LSPApplicationStub.class.getSimpleName();
static Object realLSPApplication = null; static Object realLSPApplication = null;
@ -37,8 +37,18 @@ public class LSPApplicationSub extends Application {
buffer.write(data, 0, nRead); buffer.write(data, 0, nRead);
} }
InMemoryDexClassLoader inMemoryDexClassLoader = new InMemoryDexClassLoader(ByteBuffer.wrap(buffer.toByteArray()), LSPApplicationSub.class.getClassLoader()); buffer.flush();
Class<?> lspa = inMemoryDexClassLoader.loadClass("org.lsposed.lspatch.appstub.LSPApplication"); buffer.close();
// loader can load it's own so from app native library dir
String libraryDir = context.getApplicationInfo().nativeLibraryDir;
Log.d(TAG, "LSPApplicationStub cl: " + LSPApplicationStub.class.getClassLoader());
Log.d(TAG, "NativePath : " + libraryDir);
InMemoryDexClassLoader loaderClassLoader = new InMemoryDexClassLoader(ByteBuffer.wrap(buffer.toByteArray()),
LSPApplicationStub.class.getClassLoader());
Class<?> lspa = loaderClassLoader.loadClass("org.lsposed.lspatch.loader.LSPApplication");
realLSPApplication = lspa.newInstance(); realLSPApplication = lspa.newInstance();
} }
catch (Exception e) { catch (Exception e) {
@ -53,7 +63,7 @@ public class LSPApplicationSub extends Application {
if (realLSPApplication != null) { if (realLSPApplication != null) {
try { try {
realLSPApplication.getClass().getMethod("attachBaseContext", Context.class).invoke(realLSPApplication, base); realLSPApplication.getClass().getDeclaredMethod("attachBaseContext", Context.class).invoke(realLSPApplication, base);
} }
catch (Exception e) { catch (Exception e) {
throw new IllegalStateException("wtf", e); throw new IllegalStateException("wtf", e);

View File

@ -54,6 +54,7 @@ task clean(type: Delete) {
tasks.register("build$variant") { tasks.register("build$variant") {
description("Build LSPatch with $variant") description("Build LSPatch with $variant")
dependsOn tasks.getByPath(":app:copy$variant") dependsOn tasks.getByPath(":app:copy$variant")
dependsOn tasks.getByPath(":appstub:copy$variant")
dependsOn tasks.getByPath(":patch:build") dependsOn tasks.getByPath(":patch:build")
} }
} }

View File

@ -36,7 +36,7 @@ public class LSPatch extends BaseCommand {
private boolean forceOverwrite = false; private boolean forceOverwrite = false;
@Opt(opt = "p", longOpt = "proxyname", description = "Special proxy app name with full dot path", argName = "name") @Opt(opt = "p", longOpt = "proxyname", description = "Special proxy app name with full dot path", argName = "name")
private String proxyName = "org.lsposed.lspatch.loader.LSPApplication"; private String proxyName = "org.lsposed.lspatch.appstub.LSPApplicationStub";
@Opt(opt = "d", longOpt = "debuggable", description = "Set 1 to make the app debuggable = true, " + @Opt(opt = "d", longOpt = "debuggable", description = "Set 1 to make the app debuggable = true, " +
"set 0 to make the app debuggable = false", argName = "0 or 1") "set 0 to make the app debuggable = false", argName = "0 or 1")