Add Zygisk API getFlags()

This commit is contained in:
topjohnwu
2022-01-17 19:54:33 -08:00
parent 76ddfeb93a
commit bb7a74e4b4
11 changed files with 173 additions and 82 deletions
+19 -9
View File
@@ -9,6 +9,7 @@
#include <db.hpp>
#include "zygisk.hpp"
#include "module.hpp"
#include "deny/deny.hpp"
using namespace std;
@@ -166,7 +167,7 @@ static int zygisk_log(int prio, const char *fmt, va_list ap) {
return ret;
}
std::vector<int> remote_get_info(int uid, const char *process, AppInfo *info) {
std::vector<int> remote_get_info(int uid, const char *process, uint32_t *flags) {
vector<int> fds;
if (int fd = connect_daemon(); fd >= 0) {
write_int(fd, ZYGISK_REQUEST);
@@ -174,8 +175,8 @@ std::vector<int> remote_get_info(int uid, const char *process, AppInfo *info) {
write_int(fd, uid);
write_string(fd, process);
xxread(fd, info, sizeof(*info));
if (!info->on_denylist) {
xxread(fd, flags, sizeof(*flags));
if ((*flags & UNMOUNT_MASK) != UNMOUNT_MASK) {
fds = recv_fds(fd);
}
close(fd);
@@ -314,11 +315,13 @@ static void magiskd_passthrough(int client) {
atomic<int> cached_manager_app_id = -1;
extern bool uid_granted_root(int uid);
static void get_process_info(int client, const sock_cred *cred) {
AppInfo info{};
int uid = read_int(client);
string process = read_string(client);
uint32_t flags = 0;
// This function is called on every single zygote process specialization,
// so performance is critical. get_manager_app_id() is expensive as it goes
// through a SQLite query and potentially multiple filesystem stats, so we
@@ -334,15 +337,22 @@ static void get_process_info(int client, const sock_cred *cred) {
}
if (to_app_id(uid) == manager_app_id) {
info.is_magisk_app = true;
} else if (denylist_enabled) {
info.on_denylist = is_deny_target(uid, process);
flags |= PROCESS_IS_MAGISK_APP;
}
if (denylist_enforced) {
flags |= DENYLIST_ENFORCING;
}
if (is_deny_target(uid, process)) {
flags |= PROCESS_ON_DENYLIST;
}
if (uid_granted_root(uid)) {
flags |= PROCESS_GRANTED_ROOT;
}
}
xwrite(client, &info, sizeof(info));
xwrite(client, &flags, sizeof(flags));
if (!info.on_denylist) {
if ((flags & UNMOUNT_MASK) != UNMOUNT_MASK) {
char buf[256];
get_exe(cred->pid, buf, sizeof(buf));
vector<int> fds = get_module_fds(str_ends(buf, "64"));