Integrate MagiskHide into Magisk Daemon

This commit is contained in:
topjohnwu
2017-04-09 07:25:10 +08:00
parent 054a1e5ea4
commit 144ff5e716
12 changed files with 297 additions and 75 deletions
+2 -2
View File
@@ -12,8 +12,8 @@
#include "utils.h"
static void *logger_thread(void *args) {
rename("/cache/magisk.log", "/cache/last_magisk.log");
FILE *logfile = xfopen("/cache/magisk.log", "w");
// rename("/cache/magisk.log", "/cache/last_magisk.log");
FILE *logfile = xfopen("/cache/magisk_test.log", "w");
// Disable buffering
setbuf(logfile, NULL);
// Start logcat
+5 -1
View File
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <dirent.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -34,6 +35,9 @@ void *xcalloc(size_t nmemb, size_t size);
void *xrealloc(void *ptr, size_t size);
ssize_t xsendmsg(int sockfd, const struct msghdr *msg, int flags);
ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags);
int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
int xsocketpair(int domain, int type, int protocol, int sv[2]);
// log_monitor.c
@@ -48,4 +52,4 @@ ssize_t fdreadline(int fd, char *buf, size_t size);
void ps(void (*func)(int));
void ps_filter_proc_name(const char *filter, void (*func)(int));
#endif
#endif
+41 -16
View File
@@ -39,10 +39,11 @@ int xopen(const char *pathname, int flags) {
}
ssize_t xwrite(int fd, const void *buf, size_t count) {
if (count != write(fd, buf, count)) {
int ret = write(fd, buf, count);
if (count != ret) {
PLOGE("write");
}
return count;
return ret;
}
// Read error other than EOF
@@ -56,24 +57,27 @@ ssize_t xread(int fd, void *buf, size_t count) {
// Read exact same size as count
ssize_t xxread(int fd, void *buf, size_t count) {
if (count != read(fd, buf, count)) {
int ret = read(fd, buf, count);
if (count != ret) {
PLOGE("read");
}
return count;
return ret;
}
int xpipe(int pipefd[2]) {
if (pipe(pipefd) == -1) {
int ret = pipe(pipefd);
if (ret == -1) {
PLOGE("pipe");
}
return 0;
return ret;
}
int xsetns(int fd, int nstype) {
if (setns(fd, nstype) == -1) {
int ret = setns(fd, nstype);
if (ret == -1) {
PLOGE("setns");
}
return 0;
return ret;
}
DIR *xopendir(const char *name) {
@@ -102,10 +106,11 @@ pid_t xsetsid() {
}
int xsetcon(char *context) {
if (setcon(context) == -1) {
int ret = setcon(context);
if (ret == -1) {
PLOGE("setcon: %s", context);
}
return 0;
return ret;
}
int xsocket(int domain, int type, int protocol) {
@@ -117,24 +122,27 @@ int xsocket(int domain, int type, int protocol) {
}
int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
if (bind(sockfd, addr, addrlen) == -1) {
int ret = bind(sockfd, addr, addrlen);
if (ret == -1) {
PLOGE("bind");
}
return 0;
return ret;
}
int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
if (connect(sockfd, addr, addrlen) == -1) {
int ret = connect(sockfd, addr, addrlen);
if (ret == -1) {
PLOGE("bind");
}
return 0;
return ret;
}
int xlisten(int sockfd, int backlog) {
if (listen(sockfd, backlog) == -1) {
int ret = listen(sockfd, backlog);
if (ret == -1) {
PLOGE("listen");
}
return 0;
return ret;
}
int xaccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
@@ -185,4 +193,21 @@ ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags) {
return rec;
}
int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg) {
errno = pthread_create(thread, attr, start_routine, arg);
if (errno) {
PLOGE("pthread_create");
}
return errno;
}
int xsocketpair(int domain, int type, int protocol, int sv[2]) {
int ret = socketpair(domain, type, protocol, sv);
if (ret == -1) {
PLOGE("socketpair");
}
return ret;
}