2018-09-27 18:26:41 -04:00
|
|
|
#include <libgen.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2019-02-10 03:57:51 -05:00
|
|
|
#include <magisk.h>
|
|
|
|
#include <selinux.h>
|
2018-09-27 18:26:41 -04:00
|
|
|
|
2018-11-08 15:23:36 -05:00
|
|
|
static int (*applet_main[]) (int, char *[]) =
|
2019-02-12 02:44:46 -05:00
|
|
|
{ magisk_main, su_client_main, resetprop_main, magiskhide_main, nullptr };
|
2018-09-27 18:26:41 -04:00
|
|
|
|
|
|
|
char *argv0;
|
|
|
|
|
|
|
|
__attribute__((noreturn)) static void call_applets(int argc, char *argv[]) {
|
|
|
|
// Applets
|
|
|
|
for (int i = 0; applet_names[i]; ++i) {
|
|
|
|
if (strcmp(basename(argv[0]), applet_names[i]) == 0) {
|
|
|
|
strcpy(argv0, basename(argv[0]));
|
|
|
|
exit((*applet_main[i])(argc, argv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "%s: applet not found\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
umask(0);
|
|
|
|
argv0 = argv[0];
|
|
|
|
dload_selinux();
|
2018-10-27 18:34:38 -04:00
|
|
|
cmdline_logging();
|
2018-09-27 18:26:41 -04:00
|
|
|
|
|
|
|
if (strcmp(basename(argv0), "magisk.bin") == 0 ||
|
|
|
|
(strcmp(basename(argv[0]), "magisk") == 0
|
|
|
|
&& argc > 1 && argv[1][0] != '-')) {
|
|
|
|
--argc;
|
|
|
|
++argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
call_applets(argc, argv);
|
|
|
|
}
|
|
|
|
|