Magisk/native/jni/core/applets.cpp

54 lines
1.1 KiB
C++
Raw Normal View History

2018-09-27 22:26:41 +00:00
#include <libgen.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
2019-02-10 08:57:51 +00:00
#include <magisk.h>
#include <selinux.h>
2019-02-15 09:31:39 +00:00
#include <utils.h>
2018-09-27 22:26:41 +00:00
using namespace std::literals;
2018-11-08 20:23:36 +00:00
static int (*applet_main[]) (int, char *[]) =
{ su_client_main, resetprop_main, magiskhide_main, nullptr };
2018-09-27 22:26:41 +00:00
[[noreturn]] static void call_applet(int argc, char **argv) {
2018-09-27 22:26:41 +00: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));
}
}
fprintf(stderr, "%s: applet not found\n", basename(argv[0]));
2018-09-27 22:26:41 +00:00
exit(1);
}
int main(int argc, char *argv[]) {
umask(0);
2019-10-19 07:11:54 +00:00
selinux_builtin_impl();
2018-10-27 22:34:38 +00:00
cmdline_logging();
2019-02-15 09:31:39 +00:00
init_argv0(argc, argv);
2018-09-27 22:26:41 +00:00
if (basename(argv[0]) == "magisk.bin"sv) {
if (argc == 1)
return 1;
// Running through wrapper
2018-09-27 22:26:41 +00:00
--argc;
++argv;
}
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 22:26:41 +00:00
}