Magisk/native/jni/core/applets.cpp

51 lines
1.1 KiB
C++
Raw Normal View History

2018-09-27 18:26:41 -04:00
#include <libgen.h>
#include <sys/types.h>
#include <sys/stat.h>
2020-03-09 01:50:30 -07:00
#include <magisk.hpp>
#include <selinux.hpp>
#include <utils.hpp>
2018-09-27 18:26:41 -04:00
using namespace std;
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
static int call_applet(int argc, char *argv[]) {
// Applets
string_view base = basename(argv[0]);
for (int i = 0; applet_names[i]; ++i) {
if (base == applet_names[i]) {
return (*applet_main[i])(argc, argv);
}
}
#if ENABLE_INJECT
if (str_starts(base, "app_process")) {
return app_process_main(argc, argv);
}
#endif
fprintf(stderr, "%s: applet not found\n", base.data());
return 1;
2018-09-27 18:26:41 -04:00
}
int main(int argc, char *argv[]) {
umask(0);
dload_selinux();
cmdline_logging();
init_argv0(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);
}
}
return call_applet(argc, argv);
2018-09-27 18:26:41 -04:00
}