2018-09-27 22:26:41 +00:00
|
|
|
#include <libgen.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2020-03-09 08:50:30 +00:00
|
|
|
#include <magisk.hpp>
|
|
|
|
#include <selinux.hpp>
|
2022-05-12 09:03:42 +00:00
|
|
|
#include <base.hpp>
|
2018-09-27 22:26:41 +00:00
|
|
|
|
2021-01-07 06:21:17 +00:00
|
|
|
using namespace std;
|
2019-04-03 21:25:47 +00:00
|
|
|
|
2020-01-21 17:17:30 +00:00
|
|
|
using main_fun = int (*)(int, char *[]);
|
|
|
|
|
2021-10-27 08:53:16 +00:00
|
|
|
constexpr const char *applets[] = { "su", "resetprop", "zygisk", nullptr };
|
|
|
|
static main_fun applet_mains[] = { su_client_main, resetprop_main, zygisk_main, nullptr };
|
2018-09-27 22:26:41 +00:00
|
|
|
|
2021-01-07 06:21:17 +00:00
|
|
|
static int call_applet(int argc, char *argv[]) {
|
2020-12-31 06:11:24 +00:00
|
|
|
// Applets
|
2021-01-07 06:21:17 +00:00
|
|
|
string_view base = basename(argv[0]);
|
2021-10-27 08:53:16 +00:00
|
|
|
for (int i = 0; applets[i]; ++i) {
|
|
|
|
if (base == applets[i]) {
|
|
|
|
return (*applet_mains[i])(argc, argv);
|
2020-12-31 06:11:24 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-07 06:21:17 +00:00
|
|
|
fprintf(stderr, "%s: applet not found\n", base.data());
|
|
|
|
return 1;
|
2018-09-27 22:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2021-04-10 04:29:42 +00:00
|
|
|
enable_selinux();
|
2020-12-31 06:11:24 +00:00
|
|
|
cmdline_logging();
|
|
|
|
init_argv0(argc, argv);
|
|
|
|
|
2021-01-18 20:37:08 +00:00
|
|
|
string_view base = basename(argv[0]);
|
2022-02-11 09:26:24 +00:00
|
|
|
|
|
|
|
// app_process is actually not an applet
|
|
|
|
if (str_starts(base, "app_process")) {
|
|
|
|
return app_process_main(argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
umask(0);
|
2021-01-18 20:37:08 +00:00
|
|
|
if (base == "magisk" || base == "magisk32" || base == "magisk64") {
|
2020-12-31 06:11:24 +00:00
|
|
|
if (argc > 1 && argv[1][0] != '-') {
|
|
|
|
// Calling applet via magisk [applet] args
|
|
|
|
--argc;
|
|
|
|
++argv;
|
|
|
|
} else {
|
|
|
|
return magisk_main(argc, argv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 06:21:17 +00:00
|
|
|
return call_applet(argc, argv);
|
2018-09-27 22:26:41 +00:00
|
|
|
}
|