Skip to content

Commit

Permalink
Add a debugging switch to enable instant modules loading
Browse files Browse the repository at this point in the history
  • Loading branch information
solohsu committed Jan 29, 2019
1 parent a362c98 commit a0d7137
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 20 deletions.
30 changes: 21 additions & 9 deletions Bridge/src/main/java/com/elderdrivers/riru/xposed/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
@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;
/**
* When set to true, install bootstrap hooks and loadModules
* for each process when it starts.
* This means you can deactivate or activate every module
* for the process you restart without rebooting.
*/
private static final boolean DYNAMIC_LOAD_MODULES = false;
// private static String sForkAndSpecializePramsStr = "";
// private static String sForkSystemServerPramsStr = "";
public static String sAppDataDir = "";
public static String sAppProcessName = "";
private static boolean sIsGlobalMode = false;
private static boolean sIsDynamicModules = false;

static {
init(Build.VERSION.SDK_INT);
Expand All @@ -41,26 +44,34 @@ public static void forkAndSpecializePre(int uid, int gid, int[] gids, int debugF
int[][] rlimits, int mountExternal, String seInfo,
String niceName, int[] fdsToClose, int[] fdsToIgnore,
boolean startChildZygote, String instructionSet,
String appDataDir, boolean isGlobalMode) {
String appDataDir, boolean isGlobalMode,
boolean isDynamicModules) {
// sForkAndSpecializePramsStr = String.format(
// "Zygote#forkAndSpecialize(%d, %d, %s, %d, %s, %d, %s, %s, %s, %s, %s, %s, %s)",
// uid, gid, Arrays.toString(gids), debugFlags, Arrays.toString(rlimits),
// mountExternal, seInfo, niceName, Arrays.toString(fdsToClose),
// Arrays.toString(fdsToIgnore), startChildZygote, instructionSet, appDataDir);
sAppDataDir = appDataDir;
sIsGlobalMode = isGlobalMode;
if (!DYNAMIC_LOAD_MODULES && isGlobalMode) {
sIsDynamicModules = isDynamicModules;
if (isGlobalMode) {
Router.onProcessForked(false);
}
if (!sIsDynamicModules) {
Router.loadModulesSafely();
}
}

public static void forkAndSpecializePost(int pid, String appDataDir) {
// Utils.logD(sForkAndSpecializePramsStr + " = " + pid);
if (pid == 0) {
// in app process
if (DYNAMIC_LOAD_MODULES || !sIsGlobalMode) {
if (!sIsGlobalMode) {
Router.onProcessForked(false);
}
if (sIsDynamicModules) {
Router.loadModulesSafely();
}
} else {
// in zygote process, res is child zygote pid
// don't print log here, see https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66
Expand All @@ -80,6 +91,7 @@ public static void forkSystemServerPost(int pid) {
if (pid == 0) {
// in system_server process
Router.onProcessForked(true);
Router.loadModulesSafely();
} else {
// in zygote process, res is child zygote pid
// don't print log here, see https://github.com/RikkaApps/Riru/blob/77adfd6a4a6a81bfd20569c910bc4854f2f84f5e/riru-core/jni/main/jni_native_method.cpp#L55-L66
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ public static void onProcessForked(boolean isSystem) {
// Initialize the Xposed framework and modules
try {
XposedInit.initForZygote(isSystem);
// FIXME some coredomain app can't reading modules.list
XposedInit.loadModules();
} catch (Throwable t) {
Utils.logE("Errors during Xposed initialization", t);
XposedBridge.disableHooks = true;
}
}

public static void loadModulesSafely() {
try {
// FIXME some coredomain app can't reading modules.list
XposedInit.loadModules();
} catch (Exception exception) {
Utils.logE("error loading module list", exception);
}
}

public static void startBootstrapHook(boolean isSystem) {
Utils.logD("startBootstrapHook starts: isSystem = " + isSystem);
ClassLoader classLoader = XposedBridge.BOOTCLASSLOADER;
Expand Down
2 changes: 1 addition & 1 deletion Core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apply plugin: 'com.android.library'
version "v0.2.9.6_beta"
version "v0.2.9.7_beta"
extensions["module_name"] = "EdXposed"
android {
compileSdkVersion 28
Expand Down
10 changes: 9 additions & 1 deletion Core/jni/main/inject/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
#define WHITE_LIST_PATH "/data/misc/riru/modules/edxposed/whitelist/"
#define USE_WHITE_LIST "/data/misc/riru/modules/edxposed/usewhitelist"
#define GLOBAL_MODE "/data/misc/riru/modules/edxposed/forceglobal"
#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;
}
}
Expand Down Expand Up @@ -69,7 +72,12 @@ int is_app_need_hook(JNIEnv *env, jstring appDataDir) {
}
}

int is_global_mode() {
bool is_global_mode() {
initOnce();
return global_mode;
}

bool is_dynamic_modules() {
initOnce();
return dynamic_modules;
}
4 changes: 3 additions & 1 deletion Core/jni/main/inject/config_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

int is_app_need_hook(JNIEnv *env, jstring appDataDir);

int is_global_mode();
bool is_global_mode();

bool is_dynamic_modules();

#endif //EDXPOSED_CONFIG_MANAGER_H
4 changes: 2 additions & 2 deletions Core/jni/main/inject/framework_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,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;Z)V",
"(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;ZZ)V",
uid, gid, gids, runtime_flags, rlimits,
_mount_external, se_info, se_name, fdsToClose, fdsToIgnore,
is_child_zygote, instructionSet, appDataDir, is_global_mode());
is_child_zygote, instructionSet, appDataDir, is_global_mode(), is_dynamic_modules());
}

int onNativeForkAndSpecializePost(JNIEnv *env, jclass clazz, jint res) {
Expand Down
2 changes: 1 addition & 1 deletion Core/template_override/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ LATESTARTSERVICE=false

print_modname() {
ui_print "************************************"
ui_print " Riru - Ed Xposed v0.2.9.6 "
ui_print " Riru - Ed Xposed v0.2.9.7 "
ui_print "************************************"
}

Expand Down
2 changes: 1 addition & 1 deletion Core/template_override/module.prop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=riru_edxposed
name=Riru - Ed Xposed
version=v0.2.9.6_beta
version=v0.2.9.7_beta
versionCode=1
author=givein2u
description=Magisk version of Xposed. Require Riru - Core installed.
Expand Down
2 changes: 1 addition & 1 deletion Core/template_override/riru_module.prop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Ed Xposed
version=v0.2.9.6_beta
version=v0.2.9.7_beta
versionCode=1
author=givein2u
description=Elder driver Xposed for Android Pie. Require Riru - Core installed.
2 changes: 1 addition & 1 deletion Core/template_override/system/framework/edconfig.dex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=90.0-0.2.9.6 (by Elder Driver)
version=90.0-0.2.9.7 (by Elder Driver)
arch=arm64
minsdk=23
maxsdk=28
Expand Down

0 comments on commit a0d7137

Please sign in to comment.