Return correct app data dir from zygote params

This commit is contained in:
LoveSy 2023-01-01 22:40:44 +08:00 committed by LoveSy
parent ed3612570c
commit 7a5f7181a8
8 changed files with 25 additions and 15 deletions

View File

@ -33,6 +33,7 @@ import org.lsposed.lspd.hooker.CrashDumpHooker;
import org.lsposed.lspd.hooker.HandleSystemServerProcessHooker;
import org.lsposed.lspd.hooker.LoadedApkCtorHooker;
import org.lsposed.lspd.hooker.OpenDexFileHooker;
import org.lsposed.lspd.impl.LSPosedContext;
import org.lsposed.lspd.service.ILSPApplicationService;
import org.lsposed.lspd.util.Utils;
@ -74,11 +75,14 @@ public class Startup {
}
}
public static void initXposed(boolean isSystem, String processName, ILSPApplicationService service) {
public static void initXposed(boolean isSystem, String processName, String appDir, ILSPApplicationService service) {
// init logger
ApplicationServiceClient.Init(service, processName);
XposedBridge.initXResources();
XposedInit.startsSystemServer = isSystem;
LSPosedContext.isSystemServer = isSystem;
LSPosedContext.appDir = appDir;
LSPosedContext.processName = processName;
PrebuiltMethodsDeopter.deoptBootMethods(); // do it once for secondary zygote
}
}

View File

@ -56,8 +56,11 @@ import io.github.libxposed.XposedModuleInterface;
public class LSPosedContext extends XposedContext {
public static final String TAG = "LSPosedContext";
public static final int PER_USER_RANGE = 100000;
private static final String TAG = "LSPosedContext";
private static final int PER_USER_RANGE = 100000;
public static boolean isSystemServer;
public static String appDir;
public static String processName;
static final Set<XposedModule> modules = ConcurrentHashMap.newKeySet();
@ -274,7 +277,7 @@ public class LSPosedContext extends XposedContext {
@Override
public File getDataDir() {
throw new AbstractMethodError();
return new File(appDir);
}
@Override

View File

@ -1,5 +1,5 @@
-keepclasseswithmembers class org.lsposed.lspd.core.Main {
public static void forkCommon(boolean, java.lang.String, android.os.IBinder);
public static void forkCommon(boolean, java.lang.String, java.lang.String, android.os.IBinder);
}
-keepclasseswithmembers,includedescriptorclasses class * {
native <methods>;

View File

@ -29,8 +29,8 @@ import org.lsposed.lspd.BuildConfig;
public class Main {
public static void forkCommon(boolean isSystem, String niceName, IBinder binder) {
Startup.initXposed(isSystem, niceName, ILSPApplicationService.Stub.asInterface(binder));
public static void forkCommon(boolean isSystem, String niceName, String appDir, IBinder binder) {
Startup.initXposed(isSystem, niceName, appDir, ILSPApplicationService.Stub.asInterface(binder));
if ((niceName.equals(BuildConfig.MANAGER_INJECTED_PKG_NAME) || niceName.equals(BuildConfig.DEFAULT_MANAGER_PACKAGE_NAME))
&& ParasiticManagerHooker.start()) {
Utils.logI("Loaded manager, skipping next steps");

View File

@ -37,6 +37,7 @@ namespace lspd {
std::string magiskPath;
jstring nice_name = nullptr;
jstring app_dir = nullptr;
void onModuleLoaded() {
LOGI("onModuleLoaded: welcome to LSPosed!");
@ -58,6 +59,7 @@ namespace lspd {
jboolean *,
jboolean *) {
nice_name = *_nice_name;
app_dir = *_app_data_dir;
MagiskLoader::GetInstance()->OnNativeForkAndSpecializePre(env, *_uid, *gids,
nice_name,
*start_child_zygote,
@ -66,7 +68,7 @@ namespace lspd {
void nativeForkAndSpecializePost(JNIEnv *env, jclass, jint res) {
if (res == 0)
MagiskLoader::GetInstance()->OnNativeForkAndSpecializePost(env, nice_name);
MagiskLoader::GetInstance()->OnNativeForkAndSpecializePost(env, nice_name, app_dir);
}
void nativeForkSystemServerPre(JNIEnv *env, jclass, uid_t *, gid_t *,
@ -93,6 +95,7 @@ namespace lspd {
jboolean *,
jboolean *) {
nice_name = *_nice_name;
app_dir = *_app_data_dir;
MagiskLoader::GetInstance()->OnNativeForkAndSpecializePre(env, *_uid, *gids,
nice_name,
*start_child_zygote,
@ -100,7 +103,7 @@ namespace lspd {
}
void specializeAppProcessPost(JNIEnv *env, jclass) {
MagiskLoader::GetInstance()->OnNativeForkAndSpecializePost(env, nice_name);
MagiskLoader::GetInstance()->OnNativeForkAndSpecializePost(env, nice_name, app_dir);
}
}

View File

@ -316,7 +316,7 @@ namespace lspd {
}
void postAppSpecialize(const zygisk::AppSpecializeArgs *args) override {
MagiskLoader::GetInstance()->OnNativeForkAndSpecializePost(env_, args->nice_name);
MagiskLoader::GetInstance()->OnNativeForkAndSpecializePost(env_, args->nice_name, args->app_data_dir);
if (*allowUnload) api_->setOption(zygisk::DLCLOSE_MODULE_LIBRARY);
}

View File

@ -138,8 +138,8 @@ namespace lspd {
InitHooks(env);
SetupEntryClass(env);
FindAndCall(env, "forkCommon",
"(ZLjava/lang/String;Landroid/os/IBinder;)V",
JNI_TRUE, JNI_NewStringUTF(env, "android"), application_binder);
"(ZLjava/lang/String;Ljava/lang/String;Landroid/os/IBinder;)V",
JNI_TRUE, JNI_NewStringUTF(env, "android"), nullptr, application_binder);
GetArt(true);
} else {
LOGI("skipped system server");
@ -188,7 +188,7 @@ namespace lspd {
}
void
MagiskLoader::OnNativeForkAndSpecializePost(JNIEnv *env, jstring nice_name) {
MagiskLoader::OnNativeForkAndSpecializePost(JNIEnv *env, jstring nice_name, jstring app_dir) {
const JUTFString process_name(env, nice_name);
auto *instance = Service::instance();
auto binder = skip_ ? ScopedLocalRef<jobject>{env, nullptr}
@ -219,7 +219,7 @@ namespace lspd {
SetupEntryClass(env);
LOGD("Done prepare");
FindAndCall(env, "forkCommon",
"(ZLjava/lang/String;Landroid/os/IBinder;)V",
"(ZLjava/lang/String;Ljava/lang/String;Landroid/os/IBinder;)V",
JNI_FALSE, nice_name, binder);
LOGD("injected xposed into {}", process_name.get());
setAllowUnload(false);

View File

@ -39,7 +39,7 @@ namespace lspd {
void OnNativeForkAndSpecializePre(JNIEnv *env, jint uid, jintArray &gids, jstring nice_name,
jboolean is_child_zygote, jstring app_data_dir);
void OnNativeForkAndSpecializePost(JNIEnv *env, jstring nice_name);
void OnNativeForkAndSpecializePost(JNIEnv *env, jstring nice_name, jstring app_dir);
void OnNativeForkSystemServerPost(JNIEnv *env);