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);
|
||||
free(args);
|
||||
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) {
|
||||
case LAUNCH_MAGISKHIDE:
|
||||
launch_magiskhide(client);
|
||||
@ -65,9 +86,8 @@ static void *request_handler(void *args) {
|
||||
case LATE_START:
|
||||
late_start(client);
|
||||
break;
|
||||
case TEST:
|
||||
// test(client);
|
||||
break;
|
||||
default:
|
||||
close(client);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ extern pthread_t sepol_patch;
|
||||
|
||||
// Commands require connecting to daemon
|
||||
typedef enum {
|
||||
DO_NOTHING = 0,
|
||||
LAUNCH_MAGISKHIDE,
|
||||
STOP_MAGISKHIDE,
|
||||
ADD_HIDELIST,
|
||||
@ -23,6 +24,17 @@ typedef enum {
|
||||
TEST
|
||||
} 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
|
||||
|
||||
void start_daemon();
|
||||
|
@ -19,7 +19,7 @@ int add_list(char *proc) {
|
||||
char *line;
|
||||
struct vector *new_list = xmalloc(sizeof(*new_list));
|
||||
if (new_list == NULL)
|
||||
return HIDE_ERROR;
|
||||
return DAEMON_ERROR;
|
||||
vec_init(new_list);
|
||||
|
||||
vec_for_each(hide_list, line) {
|
||||
@ -47,10 +47,10 @@ int add_list(char *proc) {
|
||||
pthread_mutex_lock(&file_lock);
|
||||
if (vector_to_file(HIDELIST, hide_list)) {
|
||||
pthread_mutex_unlock(&file_lock);
|
||||
return HIDE_ERROR;
|
||||
return DAEMON_ERROR;
|
||||
}
|
||||
pthread_mutex_unlock(&file_lock);
|
||||
return HIDE_SUCCESS;
|
||||
return DAEMON_SUCCESS;
|
||||
}
|
||||
|
||||
int rm_list(char *proc) {
|
||||
@ -59,7 +59,7 @@ int rm_list(char *proc) {
|
||||
return HIDE_NOT_ENABLED;
|
||||
}
|
||||
|
||||
hide_ret ret = HIDE_ERROR;
|
||||
daemon_response ret = DAEMON_ERROR;
|
||||
char *line;
|
||||
int do_rm = 0;
|
||||
struct vector *new_list = xmalloc(sizeof(*new_list));
|
||||
@ -87,10 +87,10 @@ int rm_list(char *proc) {
|
||||
hide_list = new_list;
|
||||
pthread_mutex_unlock(&hide_lock);
|
||||
|
||||
ret = HIDE_SUCCESS;
|
||||
ret = DAEMON_SUCCESS;
|
||||
pthread_mutex_lock(&file_lock);
|
||||
if (vector_to_file(HIDELIST, hide_list))
|
||||
ret = HIDE_ERROR;
|
||||
ret = DAEMON_ERROR;
|
||||
pthread_mutex_unlock(&file_lock);
|
||||
} else {
|
||||
ret = HIDE_ITEM_NOT_EXIST;
|
||||
|
@ -1,8 +1,6 @@
|
||||
/* magiskhide.c - initialize the environment for Magiskhide
|
||||
*/
|
||||
|
||||
// TODO: Functions to modify hiding list
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -88,7 +86,7 @@ void launch_magiskhide(int client) {
|
||||
pthread_mutex_init(&hide_lock, NULL);
|
||||
pthread_mutex_init(&file_lock, NULL);
|
||||
|
||||
write_int(client, HIDE_SUCCESS);
|
||||
write_int(client, DAEMON_SUCCESS);
|
||||
close(client);
|
||||
|
||||
// Get thread reference
|
||||
@ -99,7 +97,7 @@ void launch_magiskhide(int client) {
|
||||
|
||||
error:
|
||||
hideEnabled = 0;
|
||||
write_int(client, HIDE_ERROR);
|
||||
write_int(client, DAEMON_ERROR);
|
||||
close(client);
|
||||
if (hide_pid != -1) {
|
||||
int kill = -1;
|
||||
@ -125,7 +123,7 @@ void stop_magiskhide(int client) {
|
||||
setprop("persist.magisk.hide", "0");
|
||||
pthread_kill(proc_monitor_thread, SIGUSR1);
|
||||
|
||||
write_int(client, HIDE_SUCCESS);
|
||||
write_int(client, DAEMON_SUCCESS);
|
||||
close(client);
|
||||
}
|
||||
|
||||
@ -133,7 +131,7 @@ int magiskhide_main(int argc, char *argv[]) {
|
||||
if (argc < 2) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
client_request req;
|
||||
client_request req = DO_NOTHING;
|
||||
if (strcmp(argv[1], "--enable") == 0) {
|
||||
req = LAUNCH_MAGISKHIDE;
|
||||
} 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) {
|
||||
write_string(fd, argv[2]);
|
||||
}
|
||||
hide_ret code = read_int(fd);
|
||||
daemon_response code = read_int(fd);
|
||||
close(fd);
|
||||
switch (code) {
|
||||
case HIDE_ERROR:
|
||||
case DAEMON_ERROR:
|
||||
fprintf(stderr, "Error occured in daemon...\n");
|
||||
break;
|
||||
case HIDE_SUCCESS:
|
||||
case DAEMON_SUCCESS:
|
||||
break;
|
||||
case ROOT_REQUIRED:
|
||||
fprintf(stderr, "Root is required for this operation\n");
|
||||
break;
|
||||
case HIDE_NOT_ENABLED:
|
||||
fprintf(stderr, "Magisk hide is not enabled yet\n");
|
||||
|
@ -6,15 +6,6 @@
|
||||
#define HIDELIST "/magisk/.core/magiskhide/hidelist"
|
||||
#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
|
||||
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);
|
||||
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 rm_rf(const char *target);
|
||||
void clone_attr(const char *source, const char *target);
|
||||
void get_client_cred(int fd, struct ucred *cred);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user