mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-03 11:41:54 +00:00
Use component name as targets
Services can name their process name arbitrarily, for instance the service in com.google.android.gms that is responsible for SafetyNet is named com.google.android.gms.unstable. There are many apps out in the wild use dedicated services with special names to detect root, and previously the user is expected to add all of them to the hide list. In this commit, we change from targeting process names to component names. On Android, component names are composed of <pkg>/<cls>. When targeting component names, we can always know what application spawned the new process. This means that if the user adds a package name to the hidelist, MagiskHide can now target ALL possible processes of that specific application. To abide with this change, the default SafetyNet target is now changed from com.google.android.gms.unstable (process name) to com.google.android.gms/.droidguard.DroidGuardService (component name)
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
#include "daemon.h"
|
||||
#include "utils.h"
|
||||
#include "magiskhide.h"
|
||||
#include "flags.h"
|
||||
|
||||
static int sockfd = -1;
|
||||
extern char *system_block, *vendor_block, *magiskloop;
|
||||
@@ -61,7 +60,7 @@ static int parse_ppid(int pid) {
|
||||
}
|
||||
|
||||
static void hide_daemon(int pid) {
|
||||
LOGD("hide_daemon: start unmount for pid=[%d]\n", pid);
|
||||
LOGD("hide_daemon: handling pid=[%d]\n", pid);
|
||||
|
||||
char buffer[4096];
|
||||
Vector<CharArray> mounts;
|
||||
@@ -130,32 +129,32 @@ void proc_monitor() {
|
||||
FILE *log_in = fdopen(sockfd, "r");
|
||||
char buf[4096];
|
||||
while (fgets(buf, sizeof(buf), log_in)) {
|
||||
char *ss = strchr(buf, '[') + 1;
|
||||
int pid, ppid, num = 0;
|
||||
char *pos = ss, proc[256];
|
||||
char *log;
|
||||
int pid, ppid;
|
||||
struct stat ns, pns;
|
||||
|
||||
while((pos = strchr(pos, ','))) {
|
||||
*pos = ' ';
|
||||
++num;
|
||||
}
|
||||
if ((log = strchr(buf, '[')) == nullptr)
|
||||
continue;
|
||||
|
||||
if(sscanf(ss, num == 6 ? "%*d %d %*d %*d %256s" : "%*d %d %*d %256s", &pid, proc) != 2)
|
||||
// Extract pid
|
||||
if (sscanf(log, "[%*d,%d", &pid) != 1)
|
||||
continue;
|
||||
|
||||
// Extract last token (component name)
|
||||
const char *tok, *cpnt = "";
|
||||
while ((tok = strtok_r(nullptr, ",[]\n", &log)))
|
||||
cpnt = tok;
|
||||
if (cpnt[0] == '\0')
|
||||
continue;
|
||||
|
||||
// Make sure our target is alive
|
||||
if ((ppid = parse_ppid(pid)) < 0 || read_ns(ppid, &pns))
|
||||
continue;
|
||||
|
||||
// Allow hiding sub-services of applications
|
||||
char *colon = strchr(proc, ':');
|
||||
if (colon)
|
||||
*colon = '\0';
|
||||
|
||||
bool hide = false;
|
||||
pthread_mutex_lock(&list_lock);
|
||||
for (auto &s : hide_list) {
|
||||
if (s == proc) {
|
||||
if (strncmp(cpnt, s, s.size() - 1) == 0) {
|
||||
hide = true;
|
||||
break;
|
||||
}
|
||||
@@ -172,20 +171,11 @@ void proc_monitor() {
|
||||
if (kill(pid, SIGSTOP) == -1)
|
||||
continue;
|
||||
|
||||
// Restore the colon so we can log the actual process name
|
||||
if (colon)
|
||||
*colon = ':';
|
||||
#ifdef MAGISK_DEBUG
|
||||
LOGI("proc_monitor: %s (PID=[%d] ns=%llu)(PPID=[%d] ns=%llu)\n",
|
||||
proc, pid, ns.st_ino, ppid, pns.st_ino);
|
||||
#else
|
||||
LOGI("proc_monitor: %s\n", proc);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The setns system call do not support multithread processes
|
||||
* We have to fork a new process, setns, then do the unmounts
|
||||
*/
|
||||
LOGI("proc_monitor: %s PID=[%d] ns=[%llu]\n", cpnt, pid, ns.st_ino);
|
||||
if (fork_dont_care() == 0)
|
||||
hide_daemon(pid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user