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