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>
|
2019-02-15 04:31:39 -05:00
|
|
|
#include <utils.h>
|
2018-09-27 18:26:41 -04:00
|
|
|
|
2019-04-03 17:25:47 -04:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2020-01-22 01:17:30 +08:00
|
|
|
using main_fun = int (*)(int, char *[]);
|
|
|
|
|
|
|
|
static main_fun applet_main[] = { su_client_main, resetprop_main, magiskhide_main, nullptr };
|
2018-09-27 18:26:41 -04:00
|
|
|
|
2019-04-03 17:25:47 -04:00
|
|
|
[[noreturn]] static void call_applet(int argc, char **argv) {
|
2018-09-27 18:26:41 -04:00
|
|
|
// Applets
|
|
|
|
for (int i = 0; applet_names[i]; ++i) {
|
|
|
|
if (strcmp(basename(argv[0]), applet_names[i]) == 0) {
|
|
|
|
exit((*applet_main[i])(argc, argv));
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 17:25:47 -04:00
|
|
|
fprintf(stderr, "%s: applet not found\n", basename(argv[0]));
|
2018-09-27 18:26:41 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
umask(0);
|
2019-10-20 07:13:03 -04:00
|
|
|
dload_selinux();
|
2018-10-27 18:34:38 -04:00
|
|
|
cmdline_logging();
|
2019-02-15 04:31:39 -05:00
|
|
|
init_argv0(argc, argv);
|
2018-09-27 18:26:41 -04:00
|
|
|
|
2019-04-03 17:25:47 -04:00
|
|
|
if (basename(argv[0]) == "magisk"sv) {
|
|
|
|
if (argc > 1 && argv[1][0] != '-') {
|
|
|
|
// Calling applet via magisk [applet] args
|
|
|
|
--argc;
|
|
|
|
++argv;
|
|
|
|
} else {
|
|
|
|
return magisk_main(argc, argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
call_applet(argc, argv);
|
2018-09-27 18:26:41 -04:00
|
|
|
}
|
|
|
|
|