fix: improve asset handling and error checks
This commit is contained in:
parent
b076eed005
commit
f03ad9a386
|
|
@ -2,6 +2,13 @@
|
||||||
public static byte[] dex;
|
public static byte[] dex;
|
||||||
<init>();
|
<init>();
|
||||||
}
|
}
|
||||||
|
-keep class * extends androidx.room.Entity {
|
||||||
|
<fields>;
|
||||||
|
}
|
||||||
|
-keep interface * extends androidx.room.Dao {
|
||||||
|
<methods>;
|
||||||
|
}
|
||||||
|
|
||||||
-dontwarn androidx.annotation.NonNull
|
-dontwarn androidx.annotation.NonNull
|
||||||
-dontwarn androidx.annotation.Nullable
|
-dontwarn androidx.annotation.Nullable
|
||||||
-dontwarn androidx.annotation.VisibleForTesting
|
-dontwarn androidx.annotation.VisibleForTesting
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,15 @@ public class LSPApplication {
|
||||||
return (android.os.Process.myUid() % PER_USER_RANGE) >= FIRST_APP_ZYGOTE_ISOLATED_UID;
|
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 {
|
public static void onLoad() throws RemoteException, IOException {
|
||||||
if (isIsolated()) {
|
if (isIsolated()) {
|
||||||
XLog.d(TAG, "Skip isolated process");
|
XLog.d(TAG, "Skip isolated process");
|
||||||
|
|
@ -87,7 +96,8 @@ public class LSPApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Initialize service client");
|
Log.d(TAG, "Initialize service client");
|
||||||
ILSPApplicationService service;
|
ILSPApplicationService service = null;
|
||||||
|
|
||||||
if (config.useManager) {
|
if (config.useManager) {
|
||||||
try {
|
try {
|
||||||
service = new RemoteApplicationService(context);
|
service = new RemoteApplicationService(context);
|
||||||
|
|
@ -106,7 +116,6 @@ public class LSPApplication {
|
||||||
Log.e(TAG, "Failed to connect to manager, fallback to fixed local service");
|
Log.e(TAG, "Failed to connect to manager, fallback to fixed local service");
|
||||||
service = new NeoLocalApplicationService(context);
|
service = new NeoLocalApplicationService(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
service = new IntegrApplicationService(context);
|
service = new IntegrApplicationService(context);
|
||||||
}
|
}
|
||||||
|
|
@ -114,6 +123,7 @@ public class LSPApplication {
|
||||||
disableProfile(context);
|
disableProfile(context);
|
||||||
Startup.initXposed(false, ActivityThread.currentProcessName(), context.getApplicationInfo().dataDir, service);
|
Startup.initXposed(false, ActivityThread.currentProcessName(), context.getApplicationInfo().dataDir, service);
|
||||||
Startup.bootstrapXposed();
|
Startup.bootstrapXposed();
|
||||||
|
|
||||||
// WARN: Since it uses `XResource`, the following class should not be initialized
|
// WARN: Since it uses `XResource`, the following class should not be initialized
|
||||||
// before forkPostCommon is invoke. Otherwise, you will get failure of XResources
|
// before forkPostCommon is invoke. Otherwise, you will get failure of XResources
|
||||||
|
|
||||||
|
|
@ -172,17 +182,17 @@ public class LSPApplication {
|
||||||
Path providerPath = null;
|
Path providerPath = null;
|
||||||
if (config.injectProvider) {
|
if (config.injectProvider) {
|
||||||
try (ZipFile sourceFile = new ZipFile(sourceFileaa)) {
|
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);
|
Files.deleteIfExists(providerPath);
|
||||||
try (InputStream is = baseClassLoader.getResourceAsStream(PROVIDER_DEX_ASSET_PATH)) {
|
try (InputStream is = baseClassLoader.getResourceAsStream(PROVIDER_DEX_ASSET_PATH)) {
|
||||||
Files.copy(is, providerPath);
|
Files.copy(is, providerPath);
|
||||||
}
|
}
|
||||||
|
if (providerPath != null) {
|
||||||
providerPath.toFile().setWritable(false);
|
providerPath.toFile().setWritable(false);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Failed to inject provider:" + Log.getStackTraceString(e));
|
Log.e(TAG, "Failed to inject provider:" + Log.getStackTraceString(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheApkPath.toFile().setWritable(false);
|
cacheApkPath.toFile().setWritable(false);
|
||||||
|
|
@ -191,9 +201,7 @@ public class LSPApplication {
|
||||||
mPackages.remove(appInfo.packageName);
|
mPackages.remove(appInfo.packageName);
|
||||||
appLoadedApk = activityThread.getPackageInfoNoCheck(appInfo, compatInfo);
|
appLoadedApk = activityThread.getPackageInfoNoCheck(appInfo, compatInfo);
|
||||||
|
|
||||||
|
if (config.injectProvider && providerPath != null) {
|
||||||
|
|
||||||
if (config.injectProvider){
|
|
||||||
ClassLoader loader = appLoadedApk.getClassLoader();
|
ClassLoader loader = appLoadedApk.getClassLoader();
|
||||||
Object dexPathList = XposedHelpers.getObjectField(loader, "pathList");
|
Object dexPathList = XposedHelpers.getObjectField(loader, "pathList");
|
||||||
Object dexElements = XposedHelpers.getObjectField(dexPathList, "dexElements");
|
Object dexElements = XposedHelpers.getObjectField(dexPathList, "dexElements");
|
||||||
|
|
@ -209,7 +217,6 @@ public class LSPApplication {
|
||||||
XposedHelpers.setObjectField(dexPathList, "dexElements", newElements);
|
XposedHelpers.setObjectField(dexPathList, "dexElements", newElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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());
|
||||||
|
|
|
||||||
|
|
@ -328,9 +328,12 @@ public class LSPatch {
|
||||||
if (!useManager) {
|
if (!useManager) {
|
||||||
logger.i("Adding loader dex...");
|
logger.i("Adding loader dex...");
|
||||||
try (var is = getClass().getClassLoader().getResourceAsStream(LOADER_DEX_ASSET_PATH)) {
|
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);
|
dstZFile.add(LOADER_DEX_ASSET_PATH, is);
|
||||||
} catch (Throwable e) {
|
} 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...");
|
logger.i("Adding native lib...");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue