2016-10-03 22:24:19 +02:00
|
|
|
typedef unsigned short int sa_family_t;
|
|
|
|
//Linux includes
|
|
|
|
#define _LINUX_TIME_H
|
2016-09-27 00:08:18 +02:00
|
|
|
#define _GNU_SOURCE
|
2016-10-03 22:24:19 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
2016-09-27 00:08:18 +02:00
|
|
|
#include <fcntl.h>
|
2016-10-03 22:24:19 +02:00
|
|
|
#include <linux/connector.h>
|
|
|
|
#include <linux/cn_proc.h>
|
|
|
|
#include <linux/netlink.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <sys/socket.h>
|
2016-09-27 00:08:18 +02:00
|
|
|
#include <stdio.h>
|
2016-10-03 22:24:19 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <unistd.h>
|
2016-10-05 20:17:21 +02:00
|
|
|
#include <sys/mount.h>
|
2016-10-05 22:31:59 +02:00
|
|
|
#include <sys/inotify.h>
|
2016-10-05 20:17:21 +02:00
|
|
|
|
|
|
|
#define HIDE_LIST "/magisk/.core/hidelist"
|
2016-09-27 00:08:18 +02:00
|
|
|
|
2016-10-03 22:24:19 +02:00
|
|
|
//WARNING: Calling this will change our current namespace
|
|
|
|
//We don't care because we don't want to run from here anyway
|
2016-10-05 20:17:21 +02:00
|
|
|
int hideMagisk(int pid) {
|
2016-10-03 22:24:19 +02:00
|
|
|
char *path = NULL;
|
|
|
|
asprintf(&path, "/proc/%d/ns/mnt", pid);
|
|
|
|
int fd = open(path, O_RDONLY);
|
2016-10-03 23:23:03 +02:00
|
|
|
if(fd == -1) return 2;
|
2016-09-27 00:08:18 +02:00
|
|
|
//TODO: Fix non arm platforms
|
|
|
|
#define SYS_setns 375
|
|
|
|
int res = syscall(SYS_setns, fd, 0);
|
2016-10-03 23:23:03 +02:00
|
|
|
if(res == -1) return 3;
|
2016-09-27 00:08:18 +02:00
|
|
|
|
2016-10-05 20:17:21 +02:00
|
|
|
res = mount("/magisk/.core/mirror/system", "/system", "bind", MS_BIND, "");
|
2016-10-03 23:23:03 +02:00
|
|
|
if(res == -1) return 4;
|
2016-10-05 22:31:59 +02:00
|
|
|
res = umount2("/magisk", MNT_DETACH);
|
|
|
|
if(res == -1) return 4;
|
2016-10-03 22:24:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-05 22:31:59 +02:00
|
|
|
int loadList(int fd, char ***list, int *line, time_t *last_update) {
|
|
|
|
int allocated = 16, i;
|
|
|
|
char *buffer, *tok;
|
|
|
|
struct stat file_stat;
|
|
|
|
|
|
|
|
fstat(fd, &file_stat);
|
|
|
|
if (file_stat.st_mtime == *last_update) {
|
|
|
|
return 0;
|
2016-10-05 20:17:21 +02:00
|
|
|
}
|
2016-10-05 22:31:59 +02:00
|
|
|
off_t filesize = lseek(fd, 0, SEEK_END);
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
buffer = malloc(sizeof(char) * filesize);
|
|
|
|
read(fd, buffer, filesize);
|
|
|
|
fstat(fd, &file_stat);
|
|
|
|
*last_update = file_stat.st_mtime;
|
|
|
|
|
|
|
|
// Free memory
|
|
|
|
for (; *line >= 0; --(*line))
|
|
|
|
free((*list)[*line]);
|
|
|
|
*line = 0;
|
|
|
|
|
|
|
|
*list = (char **) malloc(sizeof(char*) * allocated);
|
|
|
|
|
|
|
|
tok = strtok(buffer, "\r\n");
|
|
|
|
while (tok != NULL) {
|
|
|
|
if (*line >= allocated) {
|
|
|
|
// Double our allocation and re-allocate
|
|
|
|
allocated = allocated * 2;
|
|
|
|
*list = (char **) realloc((*list), sizeof(char*) * allocated);
|
|
|
|
}
|
|
|
|
if (strlen(tok)) {
|
|
|
|
(*list)[*line] = malloc(strlen(tok));
|
|
|
|
strcpy((*list)[*line], tok);
|
|
|
|
++(*line);
|
|
|
|
}
|
|
|
|
tok = strtok(NULL, "\r\n");
|
|
|
|
}
|
2016-10-05 20:17:21 +02:00
|
|
|
|
|
|
|
printf("Get package name from config:\n");
|
2016-10-05 22:31:59 +02:00
|
|
|
for(i = 0; i < *line; i++)
|
|
|
|
printf("%s\n", (*list)[i]);
|
2016-10-05 20:17:21 +02:00
|
|
|
printf("\n");
|
2016-10-05 22:31:59 +02:00
|
|
|
free(buffer);
|
|
|
|
}
|
2016-10-05 20:17:21 +02:00
|
|
|
|
2016-10-05 22:31:59 +02:00
|
|
|
int main(int argc, char **argv, char **envp) {
|
|
|
|
int line = -1, i;
|
|
|
|
char **list;
|
|
|
|
time_t last_update = 0;
|
2016-10-05 20:17:21 +02:00
|
|
|
|
2016-10-05 22:31:59 +02:00
|
|
|
int fd = open(HIDE_LIST, O_RDONLY);
|
|
|
|
if (fd == -1){
|
|
|
|
printf("Error opening file\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
char buffer[512];
|
2016-10-03 23:23:03 +02:00
|
|
|
FILE *p = popen("while true;do logcat -b events -v raw -s am_proc_start;sleep 1;done", "r");
|
2016-10-03 22:24:19 +02:00
|
|
|
while(!feof(p)) {
|
2016-10-05 22:31:59 +02:00
|
|
|
|
|
|
|
loadList(fd, &list, &line, &last_update);
|
|
|
|
|
2016-10-03 22:24:19 +02:00
|
|
|
//Format of am_proc_start is (as of Android 5.1 and 6.0)
|
|
|
|
//UserID, pid, unix uid, processName, hostingType, hostingName
|
2016-10-05 20:17:21 +02:00
|
|
|
fgets(buffer, sizeof(buffer), p);
|
2016-10-03 22:24:19 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
char *pos = buffer;
|
|
|
|
while(1) {
|
2016-10-05 20:17:21 +02:00
|
|
|
pos = strchr(pos, ',');
|
2016-10-03 22:24:19 +02:00
|
|
|
if(pos == NULL)
|
|
|
|
break;
|
|
|
|
pos[0] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int user, pid, uid;
|
|
|
|
char processName[256], hostingType[16], hostingName[256];
|
|
|
|
int ret = sscanf(buffer, "[%d %d %d %256s %16s %256s]",
|
|
|
|
&user, &pid, &uid,
|
|
|
|
processName, hostingType, hostingName);
|
|
|
|
|
|
|
|
|
|
|
|
if(ret != 6) {
|
2016-10-03 23:23:03 +02:00
|
|
|
continue;
|
2016-10-03 22:24:19 +02:00
|
|
|
}
|
2016-10-05 22:31:59 +02:00
|
|
|
for (i = 0; i < line; ++i) {
|
2016-10-05 20:17:21 +02:00
|
|
|
if(strstr(processName, list[i]) != NULL) {
|
|
|
|
printf("Disabling for process = %s, PID = %d, UID = %d\n", processName, pid, uid);
|
|
|
|
hideMagisk(pid);
|
|
|
|
}
|
2016-10-03 22:24:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 22:31:59 +02:00
|
|
|
close(fd);
|
2016-10-05 20:17:21 +02:00
|
|
|
pclose(p);
|
|
|
|
for (; line >= 0; line--)
|
|
|
|
free(list[line]);
|
|
|
|
free(list);
|
|
|
|
|
2016-10-03 22:24:19 +02:00
|
|
|
return 0;
|
2016-09-27 00:08:18 +02:00
|
|
|
}
|