Remove global mode option and ensure bootstrap hooks installed for all zygotes
This commit is contained in:
parent
f417209b81
commit
aed3318ee3
|
|
@ -18,14 +18,10 @@ import static com.elderdrivers.riru.xposed.util.FileUtils.getDataPathPrefix;
|
|||
@SuppressLint("DefaultLocale")
|
||||
public class Main implements KeepAll {
|
||||
|
||||
private static String sForkAndSpecializePramsStr = "";
|
||||
private static String sForkSystemServerPramsStr = "";
|
||||
public static String sAppDataDir = "";
|
||||
public static String sAppProcessName = "";
|
||||
/**
|
||||
* Whether do bootstrap hooking only once
|
||||
*/
|
||||
private static boolean sIsGlobalMode = false;
|
||||
private static String sForkAndSpecializePramsStr = "";
|
||||
private static String sForkSystemServerPramsStr = "";
|
||||
/**
|
||||
* When set to true, install bootstrap hooks and loadModules
|
||||
* for each process when it starts.
|
||||
|
|
@ -47,8 +43,7 @@ public class Main implements KeepAll {
|
|||
int[][] rlimits, int mountExternal, String seInfo,
|
||||
String niceName, int[] fdsToClose, int[] fdsToIgnore,
|
||||
boolean startChildZygote, String instructionSet,
|
||||
String appDataDir, boolean isGlobalMode,
|
||||
boolean isDynamicModules) {
|
||||
String appDataDir, boolean isDynamicModules) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
sForkAndSpecializePramsStr = String.format(
|
||||
"Zygote#forkAndSpecialize(%d, %d, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s)",
|
||||
|
|
@ -57,13 +52,10 @@ public class Main implements KeepAll {
|
|||
Arrays.toString(fdsToIgnore), startChildZygote, instructionSet, appDataDir);
|
||||
}
|
||||
sAppDataDir = appDataDir;
|
||||
sIsGlobalMode = isGlobalMode;
|
||||
sIsDynamicModules = isDynamicModules;
|
||||
Router.prepare(false);
|
||||
if (isGlobalMode) {
|
||||
// do bootstrap hooking only once in zygote process
|
||||
Router.onProcessForked(false);
|
||||
}
|
||||
// install bootstrap hooks for secondary zygote
|
||||
Router.installBootstrapHooks(false);
|
||||
if (!isDynamicModules) {
|
||||
// load modules only once in zygote process
|
||||
Router.loadModulesSafely();
|
||||
|
|
@ -75,11 +67,6 @@ public class Main implements KeepAll {
|
|||
Utils.logD(sForkAndSpecializePramsStr + " = " + Process.myPid());
|
||||
Router.onEnterChildProcess();
|
||||
DynamicBridge.onForkPost();
|
||||
// in app process
|
||||
if (!sIsGlobalMode) {
|
||||
// do bootstrap hooking separately for each app process
|
||||
Router.onProcessForked(false);
|
||||
}
|
||||
if (sIsDynamicModules) {
|
||||
// load modules for each app process on its forked
|
||||
Router.loadModulesSafely();
|
||||
|
|
@ -98,7 +85,10 @@ public class Main implements KeepAll {
|
|||
permittedCapabilities, effectiveCapabilities);
|
||||
}
|
||||
sAppDataDir = getDataPathPrefix() + "android";
|
||||
// system_server process doesn't need sIsGlobalMode and sIsDynamicModules
|
||||
sIsDynamicModules = false;
|
||||
// install bootstrap hooks for main zygote as early as possible
|
||||
// in case we miss some processes
|
||||
Router.installBootstrapHooks(true);
|
||||
}
|
||||
|
||||
public static void forkSystemServerPost(int pid) {
|
||||
|
|
@ -107,7 +97,6 @@ public class Main implements KeepAll {
|
|||
// in system_server process
|
||||
Router.onEnterChildProcess();
|
||||
Router.prepare(true);
|
||||
Router.onProcessForked(true);
|
||||
Router.loadModulesSafely();
|
||||
} else {
|
||||
// in zygote process, res is child zygote pid
|
||||
|
|
|
|||
|
|
@ -12,11 +12,14 @@ import de.robv.android.xposed.XposedInit;
|
|||
|
||||
public class Router {
|
||||
|
||||
public volatile static boolean forkCompleted = false;
|
||||
|
||||
public static void prepare(boolean isSystem) {
|
||||
// this flag is needed when loadModules
|
||||
XposedInit.startsSystemServer = isSystem;
|
||||
}
|
||||
public static void onProcessForked(boolean isSystem) {
|
||||
|
||||
public static void installBootstrapHooks(boolean isSystem) {
|
||||
// Initialize the Xposed framework
|
||||
try {
|
||||
XposedInit.initForZygote(isSystem);
|
||||
|
|
@ -58,8 +61,6 @@ public class Router {
|
|||
SysInnerHookInfo.class.getName());
|
||||
}
|
||||
|
||||
public volatile static boolean forkCompleted = false;
|
||||
|
||||
public static void onEnterChildProcess() {
|
||||
forkCompleted = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,13 +20,11 @@
|
|||
#define DYNAMIC_MODULES "/data/misc/riru/modules/edxposed/dynamicmodules"
|
||||
|
||||
static char package_name[256];
|
||||
static bool global_mode = false;
|
||||
static bool dynamic_modules = false;
|
||||
static bool inited = false;
|
||||
|
||||
void initOnce() {
|
||||
if (!inited) {
|
||||
global_mode = access(GLOBAL_MODE, F_OK) == 0;
|
||||
dynamic_modules = access(DYNAMIC_MODULES, F_OK) == 0;
|
||||
inited = true;
|
||||
}
|
||||
|
|
@ -34,9 +32,6 @@ void initOnce() {
|
|||
|
||||
// default is true
|
||||
int is_app_need_hook(JNIEnv *env, jstring appDataDir) {
|
||||
if (is_global_mode()) {
|
||||
return 1;
|
||||
}
|
||||
if (!appDataDir) {
|
||||
LOGW("appDataDir is null");
|
||||
return 1;
|
||||
|
|
@ -76,11 +71,6 @@ int is_app_need_hook(JNIEnv *env, jstring appDataDir) {
|
|||
}
|
||||
}
|
||||
|
||||
bool is_global_mode() {
|
||||
initOnce();
|
||||
return global_mode;
|
||||
}
|
||||
|
||||
bool is_dynamic_modules() {
|
||||
initOnce();
|
||||
return dynamic_modules;
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
int is_app_need_hook(JNIEnv *env, jstring appDataDir);
|
||||
|
||||
bool is_global_mode();
|
||||
|
||||
bool is_dynamic_modules();
|
||||
|
||||
#endif //EDXPOSED_CONFIG_MANAGER_H
|
||||
|
|
|
|||
|
|
@ -86,10 +86,10 @@ void onNativeForkAndSpecializePre(JNIEnv *env, jclass clazz,
|
|||
}
|
||||
prepareJavaEnv(env);
|
||||
findAndCall(env, "forkAndSpecializePre",
|
||||
"(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;ZZ)V",
|
||||
"(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;Z)V",
|
||||
uid, gid, gids, runtime_flags, rlimits,
|
||||
_mount_external, se_info, se_name, fdsToClose, fdsToIgnore,
|
||||
is_child_zygote, instructionSet, appDataDir, is_global_mode(), is_dynamic_modules());
|
||||
is_child_zygote, instructionSet, appDataDir, is_dynamic_modules());
|
||||
}
|
||||
|
||||
int onNativeForkAndSpecializePost(JNIEnv *env, jclass clazz, jint res) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue