2016-10-03 20:24:19 +00:00
|
|
|
typedef unsigned short int sa_family_t;
|
|
|
|
//Linux includes
|
|
|
|
#define _LINUX_TIME_H
|
2016-09-26 22:08:18 +00:00
|
|
|
#define _GNU_SOURCE
|
2016-10-03 20:24:19 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
2016-09-26 22:08:18 +00:00
|
|
|
#include <fcntl.h>
|
2016-10-03 20:24:19 +00:00
|
|
|
#include <linux/connector.h>
|
|
|
|
#include <linux/cn_proc.h>
|
|
|
|
#include <linux/netlink.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <sys/socket.h>
|
2016-09-26 22:08:18 +00:00
|
|
|
#include <stdio.h>
|
2016-10-03 20:24:19 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <unistd.h>
|
2016-10-14 21:18:16 +00:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <asm/unistd.h>
|
2016-10-05 18:17:21 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
|
2016-10-14 21:18:16 +00:00
|
|
|
char **file_to_str_arr(FILE *fp, int *size) {
|
|
|
|
int allocated = 16;
|
|
|
|
char *line = NULL, **array;
|
|
|
|
size_t len = 0;
|
|
|
|
ssize_t read;
|
|
|
|
|
|
|
|
array = (char **) malloc(sizeof(char*) * allocated);
|
2016-10-06 09:53:52 +00:00
|
|
|
|
2016-10-14 21:18:16 +00:00
|
|
|
*size = 0;
|
|
|
|
while ((read = getline(&line, &len, fp)) != -1) {
|
|
|
|
if (*size >= allocated) {
|
|
|
|
// Double our allocation and re-allocate
|
|
|
|
allocated *= 2;
|
|
|
|
array = (char **) realloc(array, sizeof(char*) * allocated);
|
|
|
|
}
|
|
|
|
// Remove end newline
|
|
|
|
if (line[read - 1] == '\n') {
|
|
|
|
line[read - 1] = '\0';
|
|
|
|
}
|
|
|
|
array[*size] = line;
|
|
|
|
line = NULL;
|
|
|
|
++(*size);
|
|
|
|
}
|
|
|
|
return array;
|
|
|
|
}
|
2016-09-26 22:08:18 +00:00
|
|
|
|
2016-10-03 20:24:19 +00: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 18:17:21 +00:00
|
|
|
int hideMagisk(int pid) {
|
2016-10-03 20:24:19 +00:00
|
|
|
char *path = NULL;
|
|
|
|
asprintf(&path, "/proc/%d/ns/mnt", pid);
|
|
|
|
int fd = open(path, O_RDONLY);
|
2016-10-03 21:23:03 +00:00
|
|
|
if(fd == -1) return 2;
|
2016-09-26 22:08:18 +00:00
|
|
|
int res = syscall(SYS_setns, fd, 0);
|
2016-10-03 21:23:03 +00:00
|
|
|
if(res == -1) return 3;
|
2016-09-26 22:08:18 +00:00
|
|
|
|
2016-10-18 22:22:00 +00:00
|
|
|
free(path);
|
2016-10-14 21:18:16 +00:00
|
|
|
path = NULL;
|
|
|
|
asprintf(&path, "/proc/%d/mounts", pid);
|
|
|
|
FILE *mount_fp = fopen(path, "r");
|
|
|
|
if (mount_fp == NULL) {
|
|
|
|
fprintf(stderr, "Error opening mount list!\n");
|
|
|
|
return 1;
|
2016-10-06 09:53:52 +00:00
|
|
|
}
|
2016-10-18 22:22:00 +00:00
|
|
|
free(path);
|
2016-10-06 09:53:52 +00:00
|
|
|
|
2016-10-14 21:18:16 +00:00
|
|
|
int mount_size;
|
|
|
|
char **mount_list = file_to_str_arr(mount_fp, &mount_size), mountpoint[256], *sbstr;
|
|
|
|
fclose(mount_fp);
|
2016-10-03 20:24:19 +00:00
|
|
|
|
2016-10-14 21:18:16 +00:00
|
|
|
int i, unmount = 0;
|
|
|
|
for(i = mount_size - 1; i >= 0; --i) {
|
|
|
|
if((strstr(mount_list[i], "/dev/block/loop") != NULL)) {
|
|
|
|
sscanf(mount_list[i], "%256s %256s", mountpoint, mountpoint);
|
|
|
|
if (strstr(mountpoint, "/.core/dummy") != NULL)
|
|
|
|
unmount = 0;
|
|
|
|
else
|
|
|
|
unmount = 1;
|
|
|
|
} else if ((sbstr = strstr(mount_list[i], "/.core/dummy")) != NULL) {
|
|
|
|
sscanf(sbstr, "/.core/dummy%256s", mountpoint);
|
|
|
|
unmount = 1;
|
|
|
|
}
|
|
|
|
if(unmount) {
|
|
|
|
unmount = 0;
|
|
|
|
res = umount2(mountpoint, MNT_DETACH);
|
|
|
|
if (res != -1) printf("Unmounted: %s\n", mountpoint);
|
|
|
|
else printf("Failed: %s\n", mountpoint);
|
|
|
|
}
|
|
|
|
free(mount_list[i]);
|
2016-10-06 09:53:52 +00:00
|
|
|
}
|
|
|
|
// Free memory
|
2016-10-14 21:18:16 +00:00
|
|
|
free(mount_list);
|
2016-10-18 22:22:00 +00:00
|
|
|
|
2016-10-14 21:18:16 +00:00
|
|
|
return 0;
|
2016-10-05 20:31:59 +00:00
|
|
|
}
|
2016-10-05 18:17:21 +00:00
|
|
|
|
2016-10-05 20:31:59 +00:00
|
|
|
int main(int argc, char **argv, char **envp) {
|
2016-10-14 21:18:16 +00:00
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "%s <process/package name list>\n", argv[0]);
|
|
|
|
return 1;
|
2016-10-06 09:53:52 +00:00
|
|
|
}
|
2016-10-14 21:18:16 +00:00
|
|
|
int i, hide_size;
|
|
|
|
char **hide_list;
|
2016-10-05 18:17:21 +00:00
|
|
|
|
2016-10-14 21:18:16 +00:00
|
|
|
FILE *hide_fp = fopen(argv[1], "r");
|
|
|
|
if (hide_fp == NULL) {
|
|
|
|
fprintf(stderr, "Error opening hide list\n");
|
|
|
|
return 1;
|
2016-10-05 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 21:18:16 +00:00
|
|
|
hide_list = file_to_str_arr(hide_fp, &hide_size);
|
|
|
|
fclose(hide_fp);
|
|
|
|
|
|
|
|
printf("Get process / package name from config:\n");
|
|
|
|
for(i = 0; i < hide_size; i++)
|
|
|
|
printf("%s\n", hide_list[i]);
|
|
|
|
printf("\n");
|
2016-10-06 09:53:52 +00:00
|
|
|
|
2016-10-05 20:31:59 +00:00
|
|
|
char buffer[512];
|
2016-10-03 21:23:03 +00:00
|
|
|
FILE *p = popen("while true;do logcat -b events -v raw -s am_proc_start;sleep 1;done", "r");
|
2016-10-03 20:24:19 +00:00
|
|
|
while(!feof(p)) {
|
|
|
|
//Format of am_proc_start is (as of Android 5.1 and 6.0)
|
|
|
|
//UserID, pid, unix uid, processName, hostingType, hostingName
|
2016-10-05 18:17:21 +00:00
|
|
|
fgets(buffer, sizeof(buffer), p);
|
2016-10-03 20:24:19 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
char *pos = buffer;
|
|
|
|
while(1) {
|
2016-10-05 18:17:21 +00:00
|
|
|
pos = strchr(pos, ',');
|
2016-10-03 20:24:19 +00: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 21:23:03 +00:00
|
|
|
continue;
|
2016-10-03 20:24:19 +00:00
|
|
|
}
|
2016-10-06 09:53:52 +00:00
|
|
|
for (i = 0; i < hide_size; ++i) {
|
|
|
|
if(strstr(processName, hide_list[i]) != NULL) {
|
2016-10-05 18:17:21 +00:00
|
|
|
printf("Disabling for process = %s, PID = %d, UID = %d\n", processName, pid, uid);
|
|
|
|
hideMagisk(pid);
|
2016-10-06 09:53:52 +00:00
|
|
|
break;
|
2016-10-05 18:17:21 +00:00
|
|
|
}
|
2016-10-03 20:24:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 18:17:21 +00:00
|
|
|
pclose(p);
|
2016-10-06 09:53:52 +00:00
|
|
|
|
|
|
|
// Free memory
|
|
|
|
for(i = 0; i < hide_size; ++i)
|
|
|
|
free(hide_list[i]);
|
|
|
|
free(hide_list);
|
|
|
|
|
2016-10-03 20:24:19 +00:00
|
|
|
return 0;
|
2016-09-26 22:08:18 +00:00
|
|
|
}
|