mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-10-27 17:40:36 +00:00
Directly accept RequestCode for connect_daemon
This commit is contained in:
@@ -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<sockaddr *>(&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;
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user