mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-11 23:13:35 +00:00
Add daemon response code
This commit is contained in:
parent
d66c284bed
commit
58849f28a8
@ -32,6 +32,27 @@ static void *request_handler(void *args) {
|
|||||||
int client = *((int *) args);
|
int client = *((int *) args);
|
||||||
free(args);
|
free(args);
|
||||||
client_request req = read_int(client);
|
client_request req = read_int(client);
|
||||||
|
|
||||||
|
struct ucred credentials;
|
||||||
|
get_client_cred(client, &credentials);
|
||||||
|
|
||||||
|
switch (req) {
|
||||||
|
case LAUNCH_MAGISKHIDE:
|
||||||
|
case STOP_MAGISKHIDE:
|
||||||
|
case ADD_HIDELIST:
|
||||||
|
case RM_HIDELIST:
|
||||||
|
case POST_FS:
|
||||||
|
case POST_FS_DATA:
|
||||||
|
case LATE_START:
|
||||||
|
if (credentials.uid != 0) {
|
||||||
|
write_int(client, ROOT_REQUIRED);
|
||||||
|
close(client);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (req) {
|
switch (req) {
|
||||||
case LAUNCH_MAGISKHIDE:
|
case LAUNCH_MAGISKHIDE:
|
||||||
launch_magiskhide(client);
|
launch_magiskhide(client);
|
||||||
@ -65,9 +86,8 @@ static void *request_handler(void *args) {
|
|||||||
case LATE_START:
|
case LATE_START:
|
||||||
late_start(client);
|
late_start(client);
|
||||||
break;
|
break;
|
||||||
case TEST:
|
default:
|
||||||
// test(client);
|
close(client);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ extern pthread_t sepol_patch;
|
|||||||
|
|
||||||
// Commands require connecting to daemon
|
// Commands require connecting to daemon
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
DO_NOTHING = 0,
|
||||||
LAUNCH_MAGISKHIDE,
|
LAUNCH_MAGISKHIDE,
|
||||||
STOP_MAGISKHIDE,
|
STOP_MAGISKHIDE,
|
||||||
ADD_HIDELIST,
|
ADD_HIDELIST,
|
||||||
@ -23,6 +24,17 @@ typedef enum {
|
|||||||
TEST
|
TEST
|
||||||
} client_request;
|
} client_request;
|
||||||
|
|
||||||
|
// Return codes for daemon
|
||||||
|
typedef enum {
|
||||||
|
DAEMON_ERROR = -1,
|
||||||
|
DAEMON_SUCCESS = 0,
|
||||||
|
ROOT_REQUIRED,
|
||||||
|
HIDE_IS_ENABLED,
|
||||||
|
HIDE_NOT_ENABLED,
|
||||||
|
HIDE_ITEM_EXIST,
|
||||||
|
HIDE_ITEM_NOT_EXIST,
|
||||||
|
} daemon_response;
|
||||||
|
|
||||||
// daemon.c
|
// daemon.c
|
||||||
|
|
||||||
void start_daemon();
|
void start_daemon();
|
||||||
|
@ -19,7 +19,7 @@ int add_list(char *proc) {
|
|||||||
char *line;
|
char *line;
|
||||||
struct vector *new_list = xmalloc(sizeof(*new_list));
|
struct vector *new_list = xmalloc(sizeof(*new_list));
|
||||||
if (new_list == NULL)
|
if (new_list == NULL)
|
||||||
return HIDE_ERROR;
|
return DAEMON_ERROR;
|
||||||
vec_init(new_list);
|
vec_init(new_list);
|
||||||
|
|
||||||
vec_for_each(hide_list, line) {
|
vec_for_each(hide_list, line) {
|
||||||
@ -47,10 +47,10 @@ int add_list(char *proc) {
|
|||||||
pthread_mutex_lock(&file_lock);
|
pthread_mutex_lock(&file_lock);
|
||||||
if (vector_to_file(HIDELIST, hide_list)) {
|
if (vector_to_file(HIDELIST, hide_list)) {
|
||||||
pthread_mutex_unlock(&file_lock);
|
pthread_mutex_unlock(&file_lock);
|
||||||
return HIDE_ERROR;
|
return DAEMON_ERROR;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&file_lock);
|
pthread_mutex_unlock(&file_lock);
|
||||||
return HIDE_SUCCESS;
|
return DAEMON_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rm_list(char *proc) {
|
int rm_list(char *proc) {
|
||||||
@ -59,7 +59,7 @@ int rm_list(char *proc) {
|
|||||||
return HIDE_NOT_ENABLED;
|
return HIDE_NOT_ENABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
hide_ret ret = HIDE_ERROR;
|
daemon_response ret = DAEMON_ERROR;
|
||||||
char *line;
|
char *line;
|
||||||
int do_rm = 0;
|
int do_rm = 0;
|
||||||
struct vector *new_list = xmalloc(sizeof(*new_list));
|
struct vector *new_list = xmalloc(sizeof(*new_list));
|
||||||
@ -87,10 +87,10 @@ int rm_list(char *proc) {
|
|||||||
hide_list = new_list;
|
hide_list = new_list;
|
||||||
pthread_mutex_unlock(&hide_lock);
|
pthread_mutex_unlock(&hide_lock);
|
||||||
|
|
||||||
ret = HIDE_SUCCESS;
|
ret = DAEMON_SUCCESS;
|
||||||
pthread_mutex_lock(&file_lock);
|
pthread_mutex_lock(&file_lock);
|
||||||
if (vector_to_file(HIDELIST, hide_list))
|
if (vector_to_file(HIDELIST, hide_list))
|
||||||
ret = HIDE_ERROR;
|
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;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
/* magiskhide.c - initialize the environment for Magiskhide
|
/* magiskhide.c - initialize the environment for Magiskhide
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO: Functions to modify hiding list
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -88,7 +86,7 @@ void launch_magiskhide(int client) {
|
|||||||
pthread_mutex_init(&hide_lock, NULL);
|
pthread_mutex_init(&hide_lock, NULL);
|
||||||
pthread_mutex_init(&file_lock, NULL);
|
pthread_mutex_init(&file_lock, NULL);
|
||||||
|
|
||||||
write_int(client, HIDE_SUCCESS);
|
write_int(client, DAEMON_SUCCESS);
|
||||||
close(client);
|
close(client);
|
||||||
|
|
||||||
// Get thread reference
|
// Get thread reference
|
||||||
@ -99,7 +97,7 @@ void launch_magiskhide(int client) {
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
hideEnabled = 0;
|
hideEnabled = 0;
|
||||||
write_int(client, HIDE_ERROR);
|
write_int(client, DAEMON_ERROR);
|
||||||
close(client);
|
close(client);
|
||||||
if (hide_pid != -1) {
|
if (hide_pid != -1) {
|
||||||
int kill = -1;
|
int kill = -1;
|
||||||
@ -125,7 +123,7 @@ void stop_magiskhide(int client) {
|
|||||||
setprop("persist.magisk.hide", "0");
|
setprop("persist.magisk.hide", "0");
|
||||||
pthread_kill(proc_monitor_thread, SIGUSR1);
|
pthread_kill(proc_monitor_thread, SIGUSR1);
|
||||||
|
|
||||||
write_int(client, HIDE_SUCCESS);
|
write_int(client, DAEMON_SUCCESS);
|
||||||
close(client);
|
close(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +131,7 @@ int magiskhide_main(int argc, char *argv[]) {
|
|||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
}
|
}
|
||||||
client_request req;
|
client_request req = DO_NOTHING;
|
||||||
if (strcmp(argv[1], "--enable") == 0) {
|
if (strcmp(argv[1], "--enable") == 0) {
|
||||||
req = LAUNCH_MAGISKHIDE;
|
req = LAUNCH_MAGISKHIDE;
|
||||||
} else if (strcmp(argv[1], "--disable") == 0) {
|
} else if (strcmp(argv[1], "--disable") == 0) {
|
||||||
@ -156,13 +154,16 @@ int magiskhide_main(int argc, char *argv[]) {
|
|||||||
if (req == ADD_HIDELIST || req == RM_HIDELIST) {
|
if (req == ADD_HIDELIST || req == RM_HIDELIST) {
|
||||||
write_string(fd, argv[2]);
|
write_string(fd, argv[2]);
|
||||||
}
|
}
|
||||||
hide_ret code = read_int(fd);
|
daemon_response code = read_int(fd);
|
||||||
close(fd);
|
close(fd);
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case HIDE_ERROR:
|
case DAEMON_ERROR:
|
||||||
fprintf(stderr, "Error occured in daemon...\n");
|
fprintf(stderr, "Error occured in daemon...\n");
|
||||||
break;
|
break;
|
||||||
case HIDE_SUCCESS:
|
case DAEMON_SUCCESS:
|
||||||
|
break;
|
||||||
|
case ROOT_REQUIRED:
|
||||||
|
fprintf(stderr, "Root is required for this operation\n");
|
||||||
break;
|
break;
|
||||||
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");
|
||||||
|
@ -6,15 +6,6 @@
|
|||||||
#define HIDELIST "/magisk/.core/magiskhide/hidelist"
|
#define HIDELIST "/magisk/.core/magiskhide/hidelist"
|
||||||
#define DUMMYPATH "/dev/magisk/dummy"
|
#define DUMMYPATH "/dev/magisk/dummy"
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
HIDE_ERROR = -1,
|
|
||||||
HIDE_SUCCESS = 0,
|
|
||||||
HIDE_IS_ENABLED,
|
|
||||||
HIDE_NOT_ENABLED,
|
|
||||||
HIDE_ITEM_EXIST,
|
|
||||||
HIDE_ITEM_NOT_EXIST
|
|
||||||
} hide_ret;
|
|
||||||
|
|
||||||
// Kill process
|
// Kill process
|
||||||
void kill_proc(int pid);
|
void kill_proc(int pid);
|
||||||
|
|
||||||
|
2
jni/su
2
jni/su
@ -1 +1 @@
|
|||||||
Subproject commit 9120f71f197e3cabf68c55154e30501679fb3aa8
|
Subproject commit 9a1043574a0109e98872bc6e3fe2dcd2f406849a
|
@ -386,3 +386,9 @@ void clone_attr(const char *source, const char *target) {
|
|||||||
lsetfilecon(target, con);
|
lsetfilecon(target, con);
|
||||||
free(con);
|
free(con);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void get_client_cred(int fd, struct ucred *cred) {
|
||||||
|
socklen_t ucred_length = sizeof(*cred);
|
||||||
|
if(getsockopt(fd, SOL_SOCKET, SO_PEERCRED, cred, &ucred_length))
|
||||||
|
PLOGE("getsockopt");
|
||||||
|
}
|
||||||
|
@ -89,5 +89,6 @@ int cp_afc(const char *source, const char *target);
|
|||||||
int clone_dir(const char *source, const char *target);
|
int clone_dir(const char *source, const char *target);
|
||||||
int rm_rf(const char *target);
|
int rm_rf(const char *target);
|
||||||
void clone_attr(const char *source, const char *target);
|
void clone_attr(const char *source, const char *target);
|
||||||
|
void get_client_cred(int fd, struct ucred *cred);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user