Magisk/native/jni/core/applets.cpp

41 lines
920 B
C++
Raw Normal View History

2018-09-28 00:26:41 +02:00
#include <libgen.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
2019-02-10 09:57:51 +01:00
#include <magisk.h>
#include <selinux.h>
2019-02-15 10:31:39 +01:00
#include <utils.h>
2018-09-28 00:26:41 +02:00
2018-11-08 21:23:36 +01:00
static int (*applet_main[]) (int, char *[]) =
2019-02-12 08:44:46 +01:00
{ magisk_main, su_client_main, resetprop_main, magiskhide_main, nullptr };
2018-09-28 00:26:41 +02:00
2019-03-04 22:45:18 +01:00
[[noreturn]] static void call_applets(int argc, char *argv[]) {
2018-09-28 00:26:41 +02: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-03-04 22:45:18 +01:00
if (strncmp(basename(argv[0]), "app_process", 11) == 0)
exit(app_process_main(argc, argv));
2018-09-28 00:26:41 +02:00
fprintf(stderr, "%s: applet not found\n", argv[0]);
exit(1);
}
int main(int argc, char *argv[]) {
umask(0);
dload_selinux();
2018-10-28 00:34:38 +02:00
cmdline_logging();
2019-02-15 10:31:39 +01:00
init_argv0(argc, argv);
2018-09-28 00:26:41 +02:00
2019-02-24 20:14:03 +01:00
if ((strcmp(basename(argv[0]), "magisk") == 0 && argc > 1 && argv[1][0] != '-')) {
2018-09-28 00:26:41 +02:00
--argc;
++argv;
}
call_applets(argc, argv);
}