diff --git a/module.gradle b/module.gradle index e1082e6..1751f80 100644 --- a/module.gradle +++ b/module.gradle @@ -4,7 +4,7 @@ ext { moduleName = "ZygiskFrida" moduleAuthor = "lico-n" moduleDescription = "Injects frida gadget via zygisk." - moduleVersion = "v1.5.0" + moduleVersion = "v1.6.0" moduleVersionCode = 7 // Riru @@ -13,5 +13,5 @@ ext { moduleMaxRiruApiVersion = 26 // Frida - fridaVersion = "16.1.4" + fridaVersion = "16.1.7" } diff --git a/module/src/jni/child_gating.cpp b/module/src/jni/child_gating.cpp index 2b39d35..df4b02d 100644 --- a/module/src/jni/child_gating.cpp +++ b/module/src/jni/child_gating.cpp @@ -11,6 +11,7 @@ #include #include "config.h" +#include "inject.h" static std::string child_gating_mode; // NOLINT static std::vector injected_libraries; @@ -31,30 +32,27 @@ pid_t fork_replacement() { child_pid = getpid(); + auto logContext = "[child_gating][pid " + std::to_string(child_pid) + "] "; + if (child_gating_mode == "kill") { - LOGI("[child_gating][pid %d] killing child process", child_pid); + LOGI("%skilling child process", logContext.c_str()); exit(0); } if (child_gating_mode == "freeze") { - LOGI("[child_gating][pid %d] freezing child process", child_pid); + LOGI("%sfreezing child process", logContext.c_str()); std::promise().get_future().wait(); return 0; } if (child_gating_mode != "inject") { - LOGI("[child_gating][pid %d] unknown child_gating_mode %s", child_pid, child_gating_mode.c_str()); + LOGI("%sunknown child_gating_mode %s", logContext.c_str(), child_gating_mode.c_str()); return 0; } for (auto &lib_path : injected_libraries) { - LOGI("[child_gating][pid %d] Injecting %s", child_pid, lib_path.c_str()); - auto *handle = xdl_open(lib_path.c_str(), XDL_TRY_FORCE_LOAD); - if (handle) { - LOGI("[child_gating][pid %d] Injected %s with handle %p", child_pid, lib_path.c_str(), handle); - } else { - LOGE("[child_gating][pid %d]Failed to inject %s : %s", child_pid, lib_path.c_str(), dlerror()); - } + LOGI("%sInjecting %s", logContext.c_str(), lib_path.c_str()); + inject_lib(lib_path, logContext); } return 0; diff --git a/module/src/jni/inject.cpp b/module/src/jni/inject.cpp index de15ff5..16d425a 100644 --- a/module/src/jni/inject.cpp +++ b/module/src/jni/inject.cpp @@ -62,7 +62,28 @@ static void delay_start_up(uint64_t start_up_delay_ms) { } } -static void inject_libs(target_config const& cfg) { +void inject_lib(std::string const &lib_path, std::string const &logContext) { + auto *handle = xdl_open(lib_path.c_str(), XDL_TRY_FORCE_LOAD); + if (handle) { + LOGI("%sInjected %s with handle %p", logContext.c_str(), lib_path.c_str(), handle); + return; + } + + auto xdl_err = dlerror(); + + handle = dlopen(lib_path.c_str(), RTLD_NOW); + if (handle) { + LOGI("%sInjected %s with handle %p (dlopen)", logContext.c_str(), lib_path.c_str(), handle); + return; + } + + auto dl_err = dlerror(); + + LOGE("%sFailed to inject %s (xdl_open): %s", logContext.c_str(), lib_path.c_str(), xdl_err); + LOGE("%sFailed to inject %s (dlopen): %s", logContext.c_str(), lib_path.c_str(), dl_err); +} + +static void inject_libs(target_config const &cfg) { // We need to wait for process initialization to complete. // Loading the gadget before that will freeze the process // before the init has completed. This make the process @@ -75,14 +96,9 @@ static void inject_libs(target_config const& cfg) { delay_start_up(cfg.start_up_delay_ms); - for (auto & lib_path : cfg.injected_libraries) { + for (auto &lib_path : cfg.injected_libraries) { LOGI("Injecting %s", lib_path.c_str()); - auto *handle = xdl_open(lib_path.c_str(), XDL_TRY_FORCE_LOAD); - if (handle) { - LOGI("Injected %s with handle %p", lib_path.c_str(), handle); - } else { - LOGE("Failed to inject %s : %s", lib_path.c_str(), dlerror()); - } + inject_lib(lib_path, ""); } } diff --git a/module/src/jni/inject.h b/module/src/jni/inject.h index 4331d2f..c161797 100644 --- a/module/src/jni/inject.h +++ b/module/src/jni/inject.h @@ -3,6 +3,7 @@ #include +void inject_lib(std::string const& lib_path, std::string const& logContext); bool check_and_inject(std::string const& app_name); #endif // ZYGISKFRIDA_INJECT_H