zygisk: Let client send arch info

This commit is contained in:
Wang Han 2025-01-10 17:35:14 +08:00 committed by John Wu
parent a1b2830c06
commit 7c1d2ec61e
2 changed files with 8 additions and 21 deletions

View File

@ -39,6 +39,7 @@ int remote_get_info(int uid, const char *process, uint32_t *flags, vector<int> &
if (int fd = zygisk_request(ZygiskRequest::GET_INFO); fd >= 0) {
write_int(fd, uid);
write_string(fd, process);
write_int(fd, sizeof(void*) == 8 ? 1 : 0);
xxread(fd, flags, sizeof(*flags));
if (should_load_modules(*flags)) {
fds = recv_fds(fd);
@ -68,13 +69,6 @@ static vector<int> get_module_fds(bool is_64_bit) {
return fds;
}
static bool get_exe(int pid, char *buf, size_t sz) {
char exe[128];
if (ssprintf(exe, sizeof(exe), "/proc/%d/exe", pid) < 0)
return false;
return xreadlink(exe, buf, sz) > 0;
}
static pthread_mutex_t zygiskd_lock = PTHREAD_MUTEX_INITIALIZER;
static int zygiskd_sockets[] = { -1, -1 };
#define zygiskd_socket zygiskd_sockets[is_64_bit]
@ -125,6 +119,7 @@ static void connect_companion(int client, bool is_64_bit) {
static void get_process_info(int client, const sock_cred *cred) {
int uid = read_int(client);
string process = read_string(client);
int arch = read_int(client);
auto &daemon = MagiskD();
uint32_t flags = 0;
@ -145,13 +140,7 @@ static void get_process_info(int client, const sock_cred *cred) {
xwrite(client, &flags, sizeof(flags));
if (should_load_modules(flags)) {
char buf[256];
if (!get_exe(cred->pid, buf, sizeof(buf))) {
LOGW("zygisk: remote process %d probably died, abort\n", cred->pid);
send_fd(client, -1);
return;
}
vector<int> fds = get_module_fds(str_ends(buf, "64"));
vector<int> fds = get_module_fds(arch);
send_fds(client, fds.data(), fds.size());
}
@ -191,18 +180,15 @@ static void get_moddir(int client) {
void zygisk_handler(int client, const sock_cred *cred) {
int code = read_int(client);
char buf[256];
switch (code) {
case ZygiskRequest::GET_INFO:
get_process_info(client, cred);
break;
case ZygiskRequest::CONNECT_COMPANION:
if (get_exe(cred->pid, buf, sizeof(buf))) {
connect_companion(client, str_ends(buf, "64"));
} else {
LOGW("zygisk: remote process %d probably died, abort\n", cred->pid);
}
case ZygiskRequest::CONNECT_COMPANION: {
int arch = read_int(client);
connect_companion(client, arch);
break;
}
case ZygiskRequest::GET_MODDIR:
get_moddir(client);
break;

View File

@ -78,6 +78,7 @@ bool ZygiskModule::valid() const {
int ZygiskModule::connectCompanion() const {
if (int fd = zygisk_request(ZygiskRequest::CONNECT_COMPANION); fd >= 0) {
write_int(fd, sizeof(void*) == 8 ? 1 : 0);
write_int(fd, id);
return fd;
}