Make MagiskHide work without magisk.img

This commit is contained in:
topjohnwu 2017-09-06 02:25:40 +08:00
parent 0bf404f75e
commit eceba26894
6 changed files with 47 additions and 28 deletions

View File

@ -589,7 +589,7 @@ void post_fs_data(int client) {
// Trim, mount magisk.img, which will also travel through the modules // Trim, mount magisk.img, which will also travel through the modules
// After this, it will create the module list // After this, it will create the module list
if (prepare_img()) if (prepare_img())
goto unblock; goto core_only; // Mounting fails, we can only do core only stuffs
// Run common scripts // Run common scripts
LOGI("* Running post-fs-data.d scripts\n"); LOGI("* Running post-fs-data.d scripts\n");

View File

@ -40,6 +40,7 @@ static void *request_handler(void *args) {
case STOP_MAGISKHIDE: case STOP_MAGISKHIDE:
case ADD_HIDELIST: case ADD_HIDELIST:
case RM_HIDELIST: case RM_HIDELIST:
case LS_HIDELIST:
case POST_FS: case POST_FS:
case POST_FS_DATA: case POST_FS_DATA:
case LATE_START: case LATE_START:
@ -65,6 +66,9 @@ static void *request_handler(void *args) {
case RM_HIDELIST: case RM_HIDELIST:
rm_hide_list(client); rm_hide_list(client);
break; break;
case LS_HIDELIST:
ls_hide_list(client);
break;
case SUPERUSER: case SUPERUSER:
su_daemon_receiver(client); su_daemon_receiver(client);
break; break;

View File

@ -15,6 +15,7 @@ typedef enum {
STOP_MAGISKHIDE, STOP_MAGISKHIDE,
ADD_HIDELIST, ADD_HIDELIST,
RM_HIDELIST, RM_HIDELIST,
LS_HIDELIST,
SUPERUSER, SUPERUSER,
CHECK_VERSION, CHECK_VERSION,
CHECK_VERSION_CODE, CHECK_VERSION_CODE,
@ -69,6 +70,7 @@ void launch_magiskhide(int client);
void stop_magiskhide(int client); void stop_magiskhide(int client);
void add_hide_list(int client); void add_hide_list(int client);
void rm_hide_list(int client); void rm_hide_list(int client);
void ls_hide_list(int client);
/************* /*************
* Superuser * * Superuser *

View File

@ -140,10 +140,7 @@ int add_list(char *proc) {
pthread_mutex_unlock(&hide_lock); pthread_mutex_unlock(&hide_lock);
pthread_mutex_lock(&file_lock); pthread_mutex_lock(&file_lock);
if (vector_to_file(HIDELIST, hide_list)) { vector_to_file(HIDELIST, hide_list); // Do not complain if file not found
pthread_mutex_unlock(&file_lock);
return DAEMON_ERROR;
}
pthread_mutex_unlock(&file_lock); pthread_mutex_unlock(&file_lock);
return DAEMON_SUCCESS; return DAEMON_SUCCESS;
} }
@ -184,8 +181,7 @@ int rm_list(char *proc) {
ret = DAEMON_SUCCESS; ret = DAEMON_SUCCESS;
pthread_mutex_lock(&file_lock); pthread_mutex_lock(&file_lock);
if (vector_to_file(HIDELIST, hide_list)) vector_to_file(HIDELIST, hide_list); // Do not complain if file not found
ret = DAEMON_ERROR;
pthread_mutex_unlock(&file_lock); pthread_mutex_unlock(&file_lock);
} else { } else {
ret = HIDE_ITEM_NOT_EXIST; ret = HIDE_ITEM_NOT_EXIST;
@ -241,3 +237,18 @@ void rm_hide_list(int client) {
write_int(client, rm_list(proc)); write_int(client, rm_list(proc));
close(client); close(client);
} }
void ls_hide_list(int client) {
err_handler = do_nothing;
if (!hideEnabled) {
write_int(client, HIDE_NOT_ENABLED);
return;
}
write_int(client, DAEMON_SUCCESS);
write_int(client, vec_size(hide_list));
char *s;
vec_for_each(hide_list, s) {
write_string(client, s);
}
close(client);
}

View File

@ -123,15 +123,7 @@ int magiskhide_main(int argc, char *argv[]) {
} else if (strcmp(argv[1], "--rm") == 0 && argc > 2) { } else if (strcmp(argv[1], "--rm") == 0 && argc > 2) {
req = RM_HIDELIST; req = RM_HIDELIST;
} else if (strcmp(argv[1], "--ls") == 0) { } else if (strcmp(argv[1], "--ls") == 0) {
FILE *fp = fopen(HIDELIST, "r"); req = LS_HIDELIST;
if (fp == NULL)
return 1;
char buffer[512];
while (fgets(buffer, sizeof(buffer), fp)) {
printf("%s", buffer);
}
fclose(fp);
return 0;
} }
int fd = connect_daemon(); int fd = connect_daemon();
write_int(fd, req); write_int(fd, req);
@ -139,28 +131,38 @@ int magiskhide_main(int argc, char *argv[]) {
write_string(fd, argv[2]); write_string(fd, argv[2]);
} }
daemon_response code = read_int(fd); daemon_response code = read_int(fd);
close(fd);
switch (code) { switch (code) {
case DAEMON_ERROR: case DAEMON_ERROR:
fprintf(stderr, "Error occured in daemon...\n"); fprintf(stderr, "Error occured in daemon...\n");
break; return code;
case DAEMON_SUCCESS: case DAEMON_SUCCESS:
break; break;
case ROOT_REQUIRED: case ROOT_REQUIRED:
fprintf(stderr, "Root is required for this operation\n"); fprintf(stderr, "Root is required for this operation\n");
break; return code;
case HIDE_NOT_ENABLED: case HIDE_NOT_ENABLED:
fprintf(stderr, "Magisk hide is not enabled yet\n"); fprintf(stderr, "Magisk hide is not enabled yet\n");
break; return code;
case HIDE_IS_ENABLED: case HIDE_IS_ENABLED:
fprintf(stderr, "Magisk hide is already enabled\n"); fprintf(stderr, "Magisk hide is already enabled\n");
break; return code;
case HIDE_ITEM_EXIST: case HIDE_ITEM_EXIST:
fprintf(stderr, "Process [%s] already exists in hide list\n", argv[2]); fprintf(stderr, "Process [%s] already exists in hide list\n", argv[2]);
break; return code;
case HIDE_ITEM_NOT_EXIST: case HIDE_ITEM_NOT_EXIST:
fprintf(stderr, "Process [%s] does not exist in hide list\n", argv[2]); fprintf(stderr, "Process [%s] does not exist in hide list\n", argv[2]);
break;
}
return code; return code;
} }
if (req == LS_HIDELIST) {
int argc = read_int(fd);
for (int i = 0; i < argc; ++i) {
char *s = read_string(fd);
printf("%s\n", s);
free(s);
}
}
close(fd);
return 0;
}

View File

@ -70,7 +70,7 @@ int file_to_vector(const char* filename, struct vector *v) {
size_t len = 0; size_t len = 0;
ssize_t read; ssize_t read;
FILE *fp = fopen(filename, "r"); FILE *fp = xfopen(filename, "r");
if (fp == NULL) if (fp == NULL)
return 1; return 1;