This commit is contained in:
LoveSy 2021-08-15 11:32:20 +08:00 committed by GitHub
parent b40d686313
commit 02b7b59ac7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 7 deletions

View File

@ -22,6 +22,8 @@ package org.lsposed.lspd.service;
import static org.lsposed.lspd.service.PackageService.MATCH_ALL_FLAGS;
import static org.lsposed.lspd.service.PackageService.PER_USER_RANGE;
import static org.lsposed.lspd.service.ServiceManager.TAG;
import static org.lsposed.lspd.service.ServiceManager.existsInGlobalNamespace;
import static org.lsposed.lspd.service.ServiceManager.toGlobalNamespace;
import android.content.ContentValues;
import android.content.pm.ApplicationInfo;
@ -453,7 +455,7 @@ public class ConfigManager {
Set<String> obsoleteModules = new HashSet<>();
// packageName, apkPath
Map<String, String> obsoletePaths = new HashMap<>();
cachedModule.values().removeIf(m -> m.apkPath == null || !new File(m.apkPath).exists());
cachedModule.values().removeIf(m -> m.apkPath == null || !existsInGlobalNamespace(m.apkPath));
while (cursor.moveToNext()) {
String packageName = cursor.getString(pkgNameIdx);
String apkPath = cursor.getString(apkPathIdx);
@ -479,7 +481,7 @@ public class ConfigManager {
continue;
}
var path = apkPath;
if (path == null || !new File(path).exists()) {
if (path == null || !existsInGlobalNamespace(path)) {
path = getModuleApkPath(pkgInfo.applicationInfo);
if (path == null) obsoleteModules.add(packageName);
else obsoletePaths.put(packageName, path);
@ -629,7 +631,7 @@ public class ConfigManager {
var preLoadedDexes = new ArrayList<SharedMemory>();
var moduleClassNames = new ArrayList<String>(1);
var moduleLibraryNames = new ArrayList<String>(1);
try (var apkFile = new ZipFile(path)) {
try (var apkFile = new ZipFile(toGlobalNamespace(path))) {
readDexes(apkFile, preLoadedDexes);
readName(apkFile, "assets/xposed_init", moduleClassNames);
readName(apkFile, "assets/native_init", moduleLibraryNames);
@ -688,12 +690,13 @@ public class ConfigManager {
apks = Arrays.copyOf(info.splitSourceDirs, info.splitSourceDirs.length + 1);
apks[info.splitSourceDirs.length] = info.sourceDir;
} else apks = new String[]{info.sourceDir};
var apkPath = Arrays.stream(apks).parallel().filter(apk -> {
var apkPath = Arrays.stream(apks).parallel()
.filter(apk -> {
if (apk == null) {
Log.w(TAG, info.packageName + " has null apk path???");
return false;
}
try (var zip = new ZipFile(apk)) {
try (var zip = new ZipFile(toGlobalNamespace(apk))) {
return zip.getEntry("assets/xposed_init") != null;
} catch (IOException e) {
return false;

View File

@ -21,6 +21,7 @@ package org.lsposed.lspd.service;
import static android.content.pm.ServiceInfo.FLAG_ISOLATED_PROCESS;
import static org.lsposed.lspd.service.ServiceManager.TAG;
import static org.lsposed.lspd.service.ServiceManager.existsInGlobalNamespace;
import android.content.IIntentReceiver;
import android.content.IIntentSender;
@ -213,7 +214,7 @@ public class PackageService {
}
}
if (pkgInfo == null || pkgInfo.applicationInfo == null || (!pkgInfo.packageName.equals("android") && (pkgInfo.applicationInfo.sourceDir == null || !new File(pkgInfo.applicationInfo.sourceDir).exists() || !isPackageAvailable(packageName, userId, true))))
if (pkgInfo == null || pkgInfo.applicationInfo == null || (!pkgInfo.packageName.equals("android") && (pkgInfo.applicationInfo.sourceDir == null || !existsInGlobalNamespace(pkgInfo.applicationInfo.sourceDir) || !isPackageAvailable(packageName, userId, true))))
return null;
return pkgInfo;
}

View File

@ -25,13 +25,13 @@ import android.os.IBinder;
import android.os.IServiceManager;
import android.os.Looper;
import android.os.Process;
import android.system.Os;
import android.util.Log;
import com.android.internal.os.BinderInternal;
import org.lsposed.lspd.BuildConfig;
import java.io.File;
import java.util.concurrent.ConcurrentHashMap;
import hidden.HiddenApiBridge;
@ -43,6 +43,7 @@ public class ServiceManager {
private static LSPManagerService managerService = null;
private static LSPSystemServerService systemServerService = null;
public static final String TAG = "LSPosedService";
private static final File globalNamespace = new File("/proc/1/root");
private static void waitSystemService(String name) {
while (android.os.ServiceManager.getService(name) == null) {
@ -146,4 +147,21 @@ public class ServiceManager {
return systemServerService.systemServerRequested();
}
public static File toGlobalNamespace(File file) {
return new File(globalNamespace, file.getAbsolutePath());
}
public static File toGlobalNamespace(String path) {
if (path == null) return null;
if (path.startsWith("/")) return new File(globalNamespace, path);
else return toGlobalNamespace(new File(path));
}
public static boolean existsInGlobalNamespace(File file) {
return toGlobalNamespace(file).exists();
}
public static boolean existsInGlobalNamespace(String path) {
return toGlobalNamespace(path).exists();
}
}