mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-05-04 12:50:47 +00:00
Add zygote namespace detection
This commit is contained in:
parent
a1fd7704e0
commit
a223f6056e
@ -9,10 +9,10 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/prctl.h>
|
|
||||||
|
|
||||||
#include "magisk.h"
|
#include "magisk.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "magisk.h"
|
#include "magisk.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -17,6 +19,10 @@ struct vector *hide_list, *new_list;
|
|||||||
|
|
||||||
static pthread_t proc_monitor_thread;
|
static pthread_t proc_monitor_thread;
|
||||||
|
|
||||||
|
static void kill_proc(int pid) {
|
||||||
|
kill(pid, SIGTERM);
|
||||||
|
}
|
||||||
|
|
||||||
void launch_magiskhide() {
|
void launch_magiskhide() {
|
||||||
/*
|
/*
|
||||||
* The setns system call do not support multithread processes
|
* The setns system call do not support multithread processes
|
||||||
@ -36,9 +42,15 @@ void launch_magiskhide() {
|
|||||||
FILE *fp = xfopen(HIDELIST, "r");
|
FILE *fp = xfopen(HIDELIST, "r");
|
||||||
file_to_vector(hide_list, fp);
|
file_to_vector(hide_list, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
char *line;
|
||||||
|
vec_for_each(hide_list, line) {
|
||||||
|
LOGI("hide_list: [%s]\n", line);
|
||||||
|
ps_filter_proc_name(line, kill_proc);
|
||||||
|
}
|
||||||
|
|
||||||
// Start a new thread to monitor processes
|
// Start a new thread to monitor processes
|
||||||
pthread_create(&proc_monitor_thread, NULL, proc_monitor, NULL);
|
pthread_create(&proc_monitor_thread, NULL, proc_monitor, NULL);
|
||||||
|
pthread_join(proc_monitor_thread, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_magiskhide() {
|
void stop_magiskhide() {
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
#define pthread_cleanup_push_fix(routine, arg) \
|
#define pthread_cleanup_push_fix(routine, arg) \
|
||||||
pthread_cleanup_push(routine, arg) } while(0);
|
pthread_cleanup_push(routine, arg) } while(0);
|
||||||
|
|
||||||
|
static int zygote_num = 0;
|
||||||
|
static char init_ns[32], zygote_ns[2][32];
|
||||||
|
|
||||||
static void read_namespace(const int pid, char* target, const size_t size) {
|
static void read_namespace(const int pid, char* target, const size_t size) {
|
||||||
char path[32];
|
char path[32];
|
||||||
snprintf(path, sizeof(path), "/proc/%d/ns/mnt", pid);
|
snprintf(path, sizeof(path), "/proc/%d/ns/mnt", pid);
|
||||||
@ -40,13 +43,21 @@ static void cleanup_handler(void *arg) {
|
|||||||
hide_list = new_list = NULL;
|
hide_list = new_list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void store_zygote_ns(int pid) {
|
||||||
|
do {
|
||||||
|
usleep(500);
|
||||||
|
read_namespace(pid, zygote_ns[zygote_num], 32);
|
||||||
|
} while (strcmp(zygote_ns[zygote_num], init_ns) == 0);
|
||||||
|
++zygote_num;
|
||||||
|
}
|
||||||
|
|
||||||
void *proc_monitor(void *args) {
|
void *proc_monitor(void *args) {
|
||||||
// Register the cancel signal
|
// Register the cancel signal
|
||||||
signal(SIGUSR1, quit_pthread);
|
signal(SIGUSR1, quit_pthread);
|
||||||
pthread_cleanup_push_fix(cleanup_handler, NULL);
|
pthread_cleanup_push_fix(cleanup_handler, NULL);
|
||||||
|
|
||||||
int pid, zygote_num = 0;
|
int pid;
|
||||||
char init_ns[32], zygote_ns[2][32], buffer[512];
|
char buffer[512];
|
||||||
FILE *p;
|
FILE *p;
|
||||||
|
|
||||||
// Get the mount namespace of init
|
// Get the mount namespace of init
|
||||||
@ -54,7 +65,7 @@ void *proc_monitor(void *args) {
|
|||||||
LOGI("proc_monitor: init ns=%s\n", init_ns);
|
LOGI("proc_monitor: init ns=%s\n", init_ns);
|
||||||
|
|
||||||
// Get the mount namespace of zygote
|
// Get the mount namespace of zygote
|
||||||
// TODO: Crawl through /proc to get process names
|
ps_filter_proc_name("zygote", store_zygote_ns);
|
||||||
|
|
||||||
switch(zygote_num) {
|
switch(zygote_num) {
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -97,6 +97,7 @@ static void proc_name_filter(int pid) {
|
|||||||
fdreadline(fd, buf, sizeof(buf));
|
fdreadline(fd, buf, sizeof(buf));
|
||||||
}
|
}
|
||||||
if (strstr(buf, ps_filter_pattern)) {
|
if (strstr(buf, ps_filter_pattern)) {
|
||||||
|
// printf("%d: %s\n", pid, buf);
|
||||||
ps_filter_cb(pid);
|
ps_filter_cb(pid);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user