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")
|
@SuppressLint("DefaultLocale")
|
||||||
public class Main implements KeepAll {
|
public class Main implements KeepAll {
|
||||||
|
|
||||||
private static String sForkAndSpecializePramsStr = "";
|
|
||||||
private static String sForkSystemServerPramsStr = "";
|
|
||||||
public static String sAppDataDir = "";
|
public static String sAppDataDir = "";
|
||||||
public static String sAppProcessName = "";
|
public static String sAppProcessName = "";
|
||||||
/**
|
private static String sForkAndSpecializePramsStr = "";
|
||||||
* Whether do bootstrap hooking only once
|
private static String sForkSystemServerPramsStr = "";
|
||||||
*/
|
|
||||||
private static boolean sIsGlobalMode = false;
|
|
||||||
/**
|
/**
|
||||||
* When set to true, install bootstrap hooks and loadModules
|
* When set to true, install bootstrap hooks and loadModules
|
||||||
* for each process when it starts.
|
* for each process when it starts.
|
||||||
|
|
@ -47,8 +43,7 @@ public class Main implements KeepAll {
|
||||||
int[][] rlimits, int mountExternal, String seInfo,
|
int[][] rlimits, int mountExternal, String seInfo,
|
||||||
String niceName, int[] fdsToClose, int[] fdsToIgnore,
|
String niceName, int[] fdsToClose, int[] fdsToIgnore,
|
||||||
boolean startChildZygote, String instructionSet,
|
boolean startChildZygote, String instructionSet,
|
||||||
String appDataDir, boolean isGlobalMode,
|
String appDataDir, boolean isDynamicModules) {
|
||||||
boolean isDynamicModules) {
|
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
sForkAndSpecializePramsStr = String.format(
|
sForkAndSpecializePramsStr = String.format(
|
||||||
"Zygote#forkAndSpecialize(%d, %d, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s)",
|
"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);
|
Arrays.toString(fdsToIgnore), startChildZygote, instructionSet, appDataDir);
|
||||||
}
|
}
|
||||||
sAppDataDir = appDataDir;
|
sAppDataDir = appDataDir;
|
||||||
sIsGlobalMode = isGlobalMode;
|
|
||||||
sIsDynamicModules = isDynamicModules;
|
sIsDynamicModules = isDynamicModules;
|
||||||
Router.prepare(false);
|
Router.prepare(false);
|
||||||
if (isGlobalMode) {
|
// install bootstrap hooks for secondary zygote
|
||||||
// do bootstrap hooking only once in zygote process
|
Router.installBootstrapHooks(false);
|
||||||
Router.onProcessForked(false);
|
|
||||||
}
|
|
||||||
if (!isDynamicModules) {
|
if (!isDynamicModules) {
|
||||||
// load modules only once in zygote process
|
// load modules only once in zygote process
|
||||||
Router.loadModulesSafely();
|
Router.loadModulesSafely();
|
||||||
|
|
@ -75,11 +67,6 @@ public class Main implements KeepAll {
|
||||||
Utils.logD(sForkAndSpecializePramsStr + " = " + Process.myPid());
|
Utils.logD(sForkAndSpecializePramsStr + " = " + Process.myPid());
|
||||||
Router.onEnterChildProcess();
|
Router.onEnterChildProcess();
|
||||||
DynamicBridge.onForkPost();
|
DynamicBridge.onForkPost();
|
||||||
// in app process
|
|
||||||
if (!sIsGlobalMode) {
|
|
||||||
// do bootstrap hooking separately for each app process
|
|
||||||
Router.onProcessForked(false);
|
|
||||||
}
|
|
||||||
if (sIsDynamicModules) {
|
if (sIsDynamicModules) {
|
||||||
// load modules for each app process on its forked
|
// load modules for each app process on its forked
|
||||||
Router.loadModulesSafely();
|
Router.loadModulesSafely();
|
||||||
|
|
@ -98,7 +85,10 @@ public class Main implements KeepAll {
|
||||||
permittedCapabilities, effectiveCapabilities);
|
permittedCapabilities, effectiveCapabilities);
|
||||||
}
|
}
|
||||||
sAppDataDir = getDataPathPrefix() + "android";
|
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) {
|
public static void forkSystemServerPost(int pid) {
|
||||||
|
|
@ -107,7 +97,6 @@ public class Main implements KeepAll {
|
||||||
// in system_server process
|
// in system_server process
|
||||||
Router.onEnterChildProcess();
|
Router.onEnterChildProcess();
|
||||||
Router.prepare(true);
|
Router.prepare(true);
|
||||||
Router.onProcessForked(true);
|
|
||||||
Router.loadModulesSafely();
|
Router.loadModulesSafely();
|
||||||
} else {
|
} else {
|
||||||
// in zygote process, res is child zygote pid
|
// in zygote process, res is child zygote pid
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,14 @@ import de.robv.android.xposed.XposedInit;
|
||||||
|
|
||||||
public class Router {
|
public class Router {
|
||||||
|
|
||||||
|
public volatile static boolean forkCompleted = false;
|
||||||
|
|
||||||
public static void prepare(boolean isSystem) {
|
public static void prepare(boolean isSystem) {
|
||||||
// this flag is needed when loadModules
|
// this flag is needed when loadModules
|
||||||
XposedInit.startsSystemServer = isSystem;
|
XposedInit.startsSystemServer = isSystem;
|
||||||
}
|
}
|
||||||
public static void onProcessForked(boolean isSystem) {
|
|
||||||
|
public static void installBootstrapHooks(boolean isSystem) {
|
||||||
// Initialize the Xposed framework
|
// Initialize the Xposed framework
|
||||||
try {
|
try {
|
||||||
XposedInit.initForZygote(isSystem);
|
XposedInit.initForZygote(isSystem);
|
||||||
|
|
@ -58,8 +61,6 @@ public class Router {
|
||||||
SysInnerHookInfo.class.getName());
|
SysInnerHookInfo.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public volatile static boolean forkCompleted = false;
|
|
||||||
|
|
||||||
public static void onEnterChildProcess() {
|
public static void onEnterChildProcess() {
|
||||||
forkCompleted = true;
|
forkCompleted = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,11 @@
|
||||||
#define DYNAMIC_MODULES "/data/misc/riru/modules/edxposed/dynamicmodules"
|
#define DYNAMIC_MODULES "/data/misc/riru/modules/edxposed/dynamicmodules"
|
||||||
|
|
||||||
static char package_name[256];
|
static char package_name[256];
|
||||||
static bool global_mode = false;
|
|
||||||
static bool dynamic_modules = false;
|
static bool dynamic_modules = false;
|
||||||
static bool inited = false;
|
static bool inited = false;
|
||||||
|
|
||||||
void initOnce() {
|
void initOnce() {
|
||||||
if (!inited) {
|
if (!inited) {
|
||||||
global_mode = access(GLOBAL_MODE, F_OK) == 0;
|
|
||||||
dynamic_modules = access(DYNAMIC_MODULES, F_OK) == 0;
|
dynamic_modules = access(DYNAMIC_MODULES, F_OK) == 0;
|
||||||
inited = true;
|
inited = true;
|
||||||
}
|
}
|
||||||
|
|
@ -34,9 +32,6 @@ void initOnce() {
|
||||||
|
|
||||||
// default is true
|
// default is true
|
||||||
int is_app_need_hook(JNIEnv *env, jstring appDataDir) {
|
int is_app_need_hook(JNIEnv *env, jstring appDataDir) {
|
||||||
if (is_global_mode()) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!appDataDir) {
|
if (!appDataDir) {
|
||||||
LOGW("appDataDir is null");
|
LOGW("appDataDir is null");
|
||||||
return 1;
|
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() {
|
bool is_dynamic_modules() {
|
||||||
initOnce();
|
initOnce();
|
||||||
return dynamic_modules;
|
return dynamic_modules;
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@
|
||||||
|
|
||||||
int is_app_need_hook(JNIEnv *env, jstring appDataDir);
|
int is_app_need_hook(JNIEnv *env, jstring appDataDir);
|
||||||
|
|
||||||
bool is_global_mode();
|
|
||||||
|
|
||||||
bool is_dynamic_modules();
|
bool is_dynamic_modules();
|
||||||
|
|
||||||
#endif //EDXPOSED_CONFIG_MANAGER_H
|
#endif //EDXPOSED_CONFIG_MANAGER_H
|
||||||
|
|
|
||||||
|
|
@ -86,10 +86,10 @@ void onNativeForkAndSpecializePre(JNIEnv *env, jclass clazz,
|
||||||
}
|
}
|
||||||
prepareJavaEnv(env);
|
prepareJavaEnv(env);
|
||||||
findAndCall(env, "forkAndSpecializePre",
|
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,
|
uid, gid, gids, runtime_flags, rlimits,
|
||||||
_mount_external, se_info, se_name, fdsToClose, fdsToIgnore,
|
_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) {
|
int onNativeForkAndSpecializePost(JNIEnv *env, jclass clazz, jint res) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue