diff --git a/native/src/core/daemon.cpp b/native/src/core/daemon.cpp index 31dc4fd0a..c38d697a8 100644 --- a/native/src/core/daemon.cpp +++ b/native/src/core/daemon.cpp @@ -45,7 +45,7 @@ const char *get_magisk_tmp() { return path; } -int connect_daemon(int req, bool create) { +int connect_daemon(RequestCode req, bool create) { int fd = xsocket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0); sockaddr_un addr = {.sun_family = AF_LOCAL}; const char *tmp = get_magisk_tmp(); @@ -74,7 +74,7 @@ int connect_daemon(int req, bool create) { while (connect(fd, reinterpret_cast(&addr), sizeof(addr))) usleep(10000); } - write_int(fd, req); + write_int(fd, +req); int res = read_int(fd); if (res < +RespondCode::ERROR || res >= +RespondCode::END) res = +RespondCode::ERROR; diff --git a/native/src/core/deny/cli.cpp b/native/src/core/deny/cli.cpp index dc7c38857..fe6c3bfd6 100644 --- a/native/src/core/deny/cli.cpp +++ b/native/src/core/deny/cli.cpp @@ -90,7 +90,7 @@ int denylist_cli(int argc, char **argv) { } // Send request - int fd = connect_daemon(+RequestCode::DENYLIST); + int fd = connect_daemon(RequestCode::DENYLIST); write_int(fd, req); if (req == DenyRequest::ADD || req == DenyRequest::REMOVE) { write_string(fd, argv[2]); diff --git a/native/src/core/include/core.hpp b/native/src/core/include/core.hpp index 6e53aa767..829b5197f 100644 --- a/native/src/core/include/core.hpp +++ b/native/src/core/include/core.hpp @@ -27,7 +27,7 @@ int zygisk_main(int argc, char *argv[]); struct ModuleInfo; // Daemon -int connect_daemon(int req, bool create = false); +int connect_daemon(RequestCode req, bool create = false); const char *get_magisk_tmp(); void unlock_blocks(); bool check_key_combo(); diff --git a/native/src/core/magisk.cpp b/native/src/core/magisk.cpp index c5ff2e912..335575bcd 100644 --- a/native/src/core/magisk.cpp +++ b/native/src/core/magisk.cpp @@ -60,12 +60,12 @@ int magisk_main(int argc, char *argv[]) { #endif return 0; } else if (argv[1] == "-v"sv) { - int fd = connect_daemon(+RequestCode::CHECK_VERSION); + int fd = connect_daemon(RequestCode::CHECK_VERSION); string v = read_string(fd); printf("%s\n", v.data()); return 0; } else if (argv[1] == "-V"sv) { - int fd = connect_daemon(+RequestCode::CHECK_VERSION_CODE); + int fd = connect_daemon(RequestCode::CHECK_VERSION_CODE); printf("%d\n", read_int(fd)); return 0; } else if (argv[1] == "--list"sv) { @@ -85,29 +85,29 @@ int magisk_main(int argc, char *argv[]) { cp_afc(argv[2], argv[3]); return 0; } else if (argv[1] == "--daemon"sv) { - close(connect_daemon(+RequestCode::START_DAEMON, true)); + close(connect_daemon(RequestCode::START_DAEMON, true)); return 0; } else if (argv[1] == "--stop"sv) { - int fd = connect_daemon(+RequestCode::STOP_DAEMON); + int fd = connect_daemon(RequestCode::STOP_DAEMON); return read_int(fd); } else if (argv[1] == "--post-fs-data"sv) { - int fd = connect_daemon(+RequestCode::POST_FS_DATA, true); + int fd = connect_daemon(RequestCode::POST_FS_DATA, true); struct pollfd pfd = { fd, POLLIN, 0 }; poll(&pfd, 1, 1000 * POST_FS_DATA_WAIT_TIME); return 0; } else if (argv[1] == "--service"sv) { - close(connect_daemon(+RequestCode::LATE_START, true)); + close(connect_daemon(RequestCode::LATE_START, true)); return 0; } else if (argv[1] == "--boot-complete"sv) { - close(connect_daemon(+RequestCode::BOOT_COMPLETE)); + close(connect_daemon(RequestCode::BOOT_COMPLETE)); return 0; } else if (argv[1] == "--zygote-restart"sv) { - close(connect_daemon(+RequestCode::ZYGOTE_RESTART)); + close(connect_daemon(RequestCode::ZYGOTE_RESTART)); return 0; } else if (argv[1] == "--denylist"sv) { return denylist_cli(argc - 1, argv + 1); } else if (argc >= 3 && argv[1] == "--sqlite"sv) { - int fd = connect_daemon(+RequestCode::SQLITE_CMD); + int fd = connect_daemon(RequestCode::SQLITE_CMD); write_string(fd, argv[2]); string res; for (;;) { @@ -125,7 +125,7 @@ int magisk_main(int argc, char *argv[]) { } else { usage(); } - int fd = connect_daemon(+RequestCode::REMOVE_MODULES); + int fd = connect_daemon(RequestCode::REMOVE_MODULES); write_int(fd, do_reboot); return read_int(fd); } else if (argv[1] == "--path"sv) { diff --git a/native/src/core/su/su.cpp b/native/src/core/su/su.cpp index 07fa4423a..0c27d54f2 100644 --- a/native/src/core/su/su.cpp +++ b/native/src/core/su/su.cpp @@ -206,7 +206,7 @@ int su_client_main(int argc, char *argv[]) { } // Connect to client - owned_fd fd = connect_daemon(+RequestCode::SUPERUSER); + owned_fd fd = connect_daemon(RequestCode::SUPERUSER); // Send request req.write_to_fd(fd); diff --git a/native/src/core/zygisk/module.cpp b/native/src/core/zygisk/module.cpp index 8aa8f8930..dfb5e3788 100644 --- a/native/src/core/zygisk/module.cpp +++ b/native/src/core/zygisk/module.cpp @@ -11,6 +11,13 @@ using namespace std; +static int zygisk_request(int req) { + int fd = connect_daemon(RequestCode::ZYGISK); + if (fd < 0) return fd; + write_int(fd, req); + return fd; +} + ZygiskModule::ZygiskModule(int id, void *handle, void *entry) : id(id), handle(handle), entry{entry}, api{}, mod{nullptr} { // Make sure all pointers are null diff --git a/native/src/core/zygisk/zygisk.hpp b/native/src/core/zygisk/zygisk.hpp index 517f2588e..611ddff9a 100644 --- a/native/src/core/zygisk/zygisk.hpp +++ b/native/src/core/zygisk/zygisk.hpp @@ -25,13 +25,6 @@ void hook_entry(); void hookJniNativeMethods(JNIEnv *env, const char *clz, JNINativeMethod *methods, int numMethods); -inline int zygisk_request(int req) { - int fd = connect_daemon(+RequestCode::ZYGISK); - if (fd < 0) return fd; - write_int(fd, req); - return fd; -} - // The reference of the following structs // https://cs.android.com/android/platform/superproject/main/+/main:art/libnativebridge/include/nativebridge/native_bridge.h