Magisk/jni/main.c

71 lines
1.6 KiB
C
Raw Normal View History

/* main.c - The entry point, should be multi-call
2017-04-04 19:44:13 +00:00
*/
#include <stdlib.h>
#include <pthread.h>
2017-04-04 19:44:13 +00:00
#include "utils.h"
#include "magisk.h"
2017-04-07 23:37:43 +00:00
#include "daemon.h"
2017-04-04 19:44:13 +00:00
char magiskbuf[BUF_SIZE];
2017-04-05 22:12:29 +00:00
char *argv0;
2017-04-04 19:44:13 +00:00
void stub(const char *fmt, ...) {}
// Global error hander function
// Should be changed each thread/process
__thread void (*err_handler)(void);
void exit_proc() {
exit(-1);
}
void exit_thread() {
pthread_exit(NULL);
}
int main(int argc, char *argv[]) {
2017-04-05 22:12:29 +00:00
argv0 = argv[0];
// Exit the whole app if error occurs by default
err_handler = exit_proc;
2017-04-05 22:12:29 +00:00
char * arg = strrchr(argv[0], '/');
if (arg) ++arg;
if (strcmp(arg, "magisk") == 0) {
if (strcmp(argv[1], "--post-fs") == 0) {
// TODO: post-fs mode
return 0;
} else if (strcmp(argv[1], "--post-fs-data") == 0) {
// TODO: post-fs-data mode
return 0;
} else if (strcmp(argv[1], "--install") == 0) {
2017-04-05 22:12:29 +00:00
// TODO: Install symlinks
return 0;
2017-04-07 23:37:43 +00:00
} else if (strcmp(argv[1], "--test") == 0) {
// Temporary testing entry
int fd = connect_daemon();
write_int(fd, TEST);
2017-04-07 23:37:43 +00:00
write_string(fd, argv[2]);
return read_int(fd);
} else {
// It's calling applets
--argc;
++argv;
2017-04-05 22:12:29 +00:00
arg = argv[0];
}
}
// Applets
2017-04-05 22:12:29 +00:00
if (strcmp(arg, "su") == 0) {
2017-04-07 23:37:43 +00:00
// return su_main(argc, argv);
2017-04-05 22:12:29 +00:00
} else if (strcmp(arg, "magiskpolicy") == 0) {
return magiskpolicy_main(argc, argv);
} else if (strcmp(arg, "resetprop") == 0) {
return resetprop_main(argc, argv);
} else if (strcmp(arg, "magiskhide") == 0) {
return magiskhide_main(argc, argv);
} else {
2017-04-05 22:12:29 +00:00
fprintf(stderr, "Applet \'%s\' not found\n", arg);
}
2017-04-05 22:12:29 +00:00
return 1;
2017-04-04 19:44:13 +00:00
}