1
mirror of https://github.com/topjohnwu/Magisk synced 2024-11-14 22:28:37 +01:00
Magisk/jni/magiskhide/magiskhide.c

57 lines
1.2 KiB
C
Raw Normal View History

2017-04-06 00:12:29 +02:00
/* magiskhide.c - initialize the environment for Magiskhide
*/
2016-12-30 19:44:24 +01:00
2017-04-06 00:12:29 +02:00
// TODO: Functions to modify hiding list
2017-04-06 00:12:29 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
2016-12-30 19:44:24 +01:00
2017-04-06 00:12:29 +02:00
#include "magisk.h"
#include "utils.h"
#include "magiskhide.h"
2016-12-30 19:44:24 +01:00
2017-04-06 00:12:29 +02:00
int pipefd[2];
struct vector *hide_list, *new_list;
2016-12-30 19:44:24 +01:00
2017-04-06 00:12:29 +02:00
static pthread_t proc_monitor_thread;
2017-01-01 11:54:13 +01:00
2017-04-06 00:12:29 +02:00
void launch_magiskhide() {
/*
* The setns system call do not support multithread processes
* We have to fork a new process, and communicate with pipe
*/
2016-12-30 19:44:24 +01:00
2017-04-06 00:12:29 +02:00
xpipe(pipefd);
2016-12-30 19:44:24 +01:00
2017-04-06 00:12:29 +02:00
// Launch the hide daemon
hide_daemon();
2016-12-30 19:44:24 +01:00
close(pipefd[0]);
2017-04-06 00:12:29 +02:00
// Initialize the hide list
hide_list = new_list = malloc(sizeof(*hide_list));
vec_init(hide_list);
FILE *fp = xfopen(HIDELIST, "r");
file_to_vector(hide_list, fp);
fclose(fp);
2016-12-30 19:44:24 +01:00
2017-04-06 00:12:29 +02:00
// Start a new thread to monitor processes
pthread_create(&proc_monitor_thread, NULL, proc_monitor, NULL);
}
2016-12-30 19:44:24 +01:00
2017-04-06 00:12:29 +02:00
void stop_magiskhide() {
int kill = -1;
// Terminate hide daemon
xwrite(pipefd[1], &kill, sizeof(kill));
// Stop process monitor
pthread_kill(proc_monitor_thread, SIGUSR1);
pthread_join(proc_monitor_thread, NULL);
}
2016-12-30 19:44:24 +01:00
2017-04-06 00:12:29 +02:00
int magiskhide_main(int argc, char *argv[]) {
launch_magiskhide();
return 0;
}