2017-04-14 21:23:09 +02:00
|
|
|
/* main.c - The multicall entry point
|
2017-04-04 21:44:13 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-09 01:25:10 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-04-04 21:44:13 +02:00
|
|
|
#include "utils.h"
|
|
|
|
#include "magisk.h"
|
2017-04-08 01:37:43 +02:00
|
|
|
#include "daemon.h"
|
2017-04-04 21:44:13 +02:00
|
|
|
|
2017-04-06 00:12:29 +02:00
|
|
|
char *argv0;
|
2017-04-04 21:44:13 +02:00
|
|
|
|
2017-04-09 01:25:10 +02:00
|
|
|
// Global error hander function
|
|
|
|
// Should be changed each thread/process
|
|
|
|
__thread void (*err_handler)(void);
|
|
|
|
|
2017-04-05 00:08:53 +02:00
|
|
|
int main(int argc, char *argv[]) {
|
2017-04-06 00:12:29 +02:00
|
|
|
argv0 = argv[0];
|
2017-04-09 01:25:10 +02:00
|
|
|
// Exit the whole app if error occurs by default
|
|
|
|
err_handler = exit_proc;
|
2017-04-06 00:12:29 +02:00
|
|
|
char * arg = strrchr(argv[0], '/');
|
|
|
|
if (arg) ++arg;
|
|
|
|
if (strcmp(arg, "magisk") == 0) {
|
2017-04-14 21:23:09 +02:00
|
|
|
if (strcmp(argv[1], "-v") == 0) {
|
|
|
|
printf("Client: %s\n", VERSION_STR);
|
|
|
|
int fd = connect_daemon();
|
|
|
|
write_int(fd, CHECK_VERSION);
|
|
|
|
char *v = read_string(fd);
|
|
|
|
printf("Daemon: %s\n", v);
|
|
|
|
free(v);
|
|
|
|
return 0;
|
|
|
|
} else if (strcmp(argv[1], "-V") == 0) {
|
|
|
|
int fd = connect_daemon();
|
|
|
|
write_int(fd, CHECK_VERSION_CODE);
|
|
|
|
printf("%d\n", read_int(fd));
|
|
|
|
return 0;
|
|
|
|
} else if (strcmp(argv[1], "--post-fs") == 0) {
|
2017-04-06 00:12:29 +02:00
|
|
|
// TODO: post-fs mode
|
|
|
|
return 0;
|
|
|
|
} else if (strcmp(argv[1], "--post-fs-data") == 0) {
|
|
|
|
// TODO: post-fs-data mode
|
2017-04-05 00:08:53 +02:00
|
|
|
return 0;
|
2017-04-14 21:23:09 +02:00
|
|
|
} else if (strcmp(argv[1], "--service") == 0) {
|
|
|
|
// TODO: late_start service mode
|
|
|
|
return 0;
|
2017-04-05 00:08:53 +02:00
|
|
|
} else if (strcmp(argv[1], "--install") == 0) {
|
2017-04-06 00:12:29 +02:00
|
|
|
// TODO: Install symlinks
|
2017-04-05 00:08:53 +02:00
|
|
|
return 0;
|
2017-04-08 01:37:43 +02:00
|
|
|
} else if (strcmp(argv[1], "--test") == 0) {
|
|
|
|
// Temporary testing entry
|
|
|
|
int fd = connect_daemon();
|
2017-04-09 01:25:10 +02:00
|
|
|
write_int(fd, TEST);
|
2017-04-08 01:37:43 +02:00
|
|
|
write_string(fd, argv[2]);
|
2017-04-09 01:25:10 +02:00
|
|
|
return read_int(fd);
|
2017-04-05 00:08:53 +02:00
|
|
|
} else {
|
|
|
|
// It's calling applets
|
|
|
|
--argc;
|
|
|
|
++argv;
|
2017-04-06 00:12:29 +02:00
|
|
|
arg = argv[0];
|
2017-04-05 00:08:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Applets
|
2017-04-06 00:12:29 +02:00
|
|
|
if (strcmp(arg, "su") == 0) {
|
2017-04-14 21:23:09 +02:00
|
|
|
return su_client_main(argc, argv);
|
2017-04-06 00:12:29 +02: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);
|
2017-04-05 00:08:53 +02:00
|
|
|
} else {
|
2017-04-06 00:12:29 +02:00
|
|
|
fprintf(stderr, "Applet \'%s\' not found\n", arg);
|
2017-04-05 00:08:53 +02:00
|
|
|
}
|
2017-04-06 00:12:29 +02:00
|
|
|
return 1;
|
2017-04-14 21:23:09 +02:00
|
|
|
}
|