mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-11 22:53:37 +00:00
MagiskHide small update
This commit is contained in:
parent
0a53c42a8a
commit
70e332b9e8
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
FILE *logfile;
|
FILE *logfile;
|
||||||
int i, list_size;
|
int i, list_size;
|
||||||
char **hide_list = NULL;
|
char **hide_list = NULL, cache_block[256];
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
|
||||||
char **file_to_str_arr(FILE *fp, int *size) {
|
char **file_to_str_arr(FILE *fp, int *size) {
|
||||||
@ -58,7 +58,7 @@ void lazy_unmount(const char* mountpoint) {
|
|||||||
//WARNING: Calling this will change our current namespace
|
//WARNING: Calling this will change our current namespace
|
||||||
//We don't care because we don't want to run from here anyway
|
//We don't care because we don't want to run from here anyway
|
||||||
int hideMagisk(int pid, int uid) {
|
int hideMagisk(int pid, int uid) {
|
||||||
struct stat info;
|
// struct stat info;
|
||||||
char path[256];
|
char path[256];
|
||||||
// snprintf(path, 256, "/proc/%d", pid);
|
// snprintf(path, 256, "/proc/%d", pid);
|
||||||
// if (stat(path, &info) == -1) {
|
// if (stat(path, &info) == -1) {
|
||||||
@ -87,32 +87,40 @@ int hideMagisk(int pid, int uid) {
|
|||||||
|
|
||||||
int mount_size;
|
int mount_size;
|
||||||
char **mount_list = file_to_str_arr(mount_fp, &mount_size), mountpoint[256], cache_block[256];
|
char **mount_list = file_to_str_arr(mount_fp, &mount_size), mountpoint[256], cache_block[256];
|
||||||
fclose(mount_fp);
|
|
||||||
|
|
||||||
// Find the cache block
|
// Find the cache block name if not found yet
|
||||||
for(i = 0; i < mount_size; ++i) {
|
if (strlen(cache_block) == 0) {
|
||||||
if (strstr(mount_list[i], "/cache")) {
|
for(i = 0; i < mount_size; ++i) {
|
||||||
sscanf(mount_list[i], "%256s", cache_block);
|
if (strstr(mount_list[i], " /cache ")) {
|
||||||
break;
|
sscanf(mount_list[i], "%256s", cache_block);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmount in inverse order
|
// First unmount the dummy skeletons and the cache mounts
|
||||||
for(i = mount_size - 1; i >= 0; --i) {
|
for(i = mount_size - 1; i >= 0; --i) {
|
||||||
if (strstr(mount_list[i], cache_block) && strstr(mount_list[i], "/system")) {
|
if (strstr(mount_list[i], "tmpfs /system/") || strstr(mount_list[i], "tmpfs /vendor/")
|
||||||
|
|| (strstr(mount_list[i], cache_block) && strstr(mount_list[i], "/system")) ) {
|
||||||
sscanf(mount_list[i], "%256s %256s", mountpoint, mountpoint);
|
sscanf(mount_list[i], "%256s %256s", mountpoint, mountpoint);
|
||||||
} else if (strstr(mount_list[i], "/dev/block/loop")) {
|
lazy_unmount(mountpoint);
|
||||||
if (strstr(mount_list[i], "/dev/magisk")) continue;
|
}
|
||||||
// Everything from loop mount
|
free(mount_list[i]);
|
||||||
sscanf(mount_list[i], "%256s %256s", mountpoint, mountpoint);
|
}
|
||||||
} else if (strstr(mount_list[i], "tmpfs /system/")) {
|
// Free memory
|
||||||
// Directly unmount skeletons
|
free(mount_list);
|
||||||
sscanf(mount_list[i], "%256s %256s", mountpoint, mountpoint);
|
|
||||||
} else {
|
// Re-read mount infos
|
||||||
free(mount_list[i]);
|
fseek(mount_fp, 0, SEEK_SET);
|
||||||
continue;
|
mount_list = file_to_str_arr(mount_fp, &mount_size);
|
||||||
|
fclose(mount_fp);
|
||||||
|
|
||||||
|
// Unmount loop mounts
|
||||||
|
for(i = mount_size - 1; i >= 0; --i) {
|
||||||
|
if (strstr(mount_list[i], "/dev/block/loop")) {
|
||||||
|
sscanf(mount_list[i], "%256s %256s", mountpoint, mountpoint);
|
||||||
|
lazy_unmount(mountpoint);
|
||||||
}
|
}
|
||||||
lazy_unmount(mountpoint);
|
|
||||||
free(mount_list[i]);
|
free(mount_list[i]);
|
||||||
}
|
}
|
||||||
// Free memory
|
// Free memory
|
||||||
@ -170,7 +178,7 @@ void *monitor_list(void *path) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_list((char*) listpath);
|
update_list(listpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -194,6 +202,9 @@ int main(int argc, char **argv, char **envp) {
|
|||||||
logfile = fopen(LOGFILE, "a+");
|
logfile = fopen(LOGFILE, "a+");
|
||||||
setbuf(logfile, NULL);
|
setbuf(logfile, NULL);
|
||||||
|
|
||||||
|
// Set cache block to null
|
||||||
|
cache_block[0] = 0;
|
||||||
|
|
||||||
pthread_t list_monitor;
|
pthread_t list_monitor;
|
||||||
|
|
||||||
pthread_mutex_init(&mutex, NULL);
|
pthread_mutex_init(&mutex, NULL);
|
||||||
@ -246,8 +257,7 @@ int main(int argc, char **argv, char **envp) {
|
|||||||
pthread_kill(list_monitor, SIGQUIT);
|
pthread_kill(list_monitor, SIGQUIT);
|
||||||
pthread_mutex_destroy(&mutex);
|
pthread_mutex_destroy(&mutex);
|
||||||
|
|
||||||
fprintf(logfile, "MagiskHide: Error occurred...\n");
|
fprintf(logfile, "MagiskHide: Cannot read from logcat, abort...\n");
|
||||||
|
|
||||||
fclose(logfile);
|
fclose(logfile);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user