mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-10 05:41:56 +00:00
Make magiskinit not magiskpolicy
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <fcntl.h>
|
||||
#include <libgen.h>
|
||||
#include <vector>
|
||||
|
||||
#include <xz.h>
|
||||
|
||||
#include <magisk.hpp>
|
||||
#include <utils.hpp>
|
||||
#include <binaries.h>
|
||||
|
||||
@@ -15,12 +12,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Debug toggle
|
||||
#define ENABLE_TEST 0
|
||||
|
||||
constexpr int (*init_applet_main[])(int, char *[]) =
|
||||
{ magiskpolicy_main, magiskpolicy_main, nullptr };
|
||||
|
||||
bool unxz(int fd, const uint8_t *buf, size_t size) {
|
||||
uint8_t out[8192];
|
||||
xz_crc32_init();
|
||||
@@ -65,64 +56,12 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#if ENABLE_TEST
|
||||
class TestInit : public BaseInit {
|
||||
public:
|
||||
TestInit(char *argv[], BootConfig *cmd) : BaseInit(argv, cmd) {};
|
||||
void start() override {
|
||||
// Place init tests here
|
||||
}
|
||||
};
|
||||
|
||||
static int test_main(int argc, char *argv[]) {
|
||||
// Log to console
|
||||
cmdline_logging();
|
||||
log_cb.ex = nop_ex;
|
||||
|
||||
// Switch to isolate namespace
|
||||
xunshare(CLONE_NEWNS);
|
||||
xmount(nullptr, "/", nullptr, MS_PRIVATE | MS_REC, nullptr);
|
||||
|
||||
// Unmount everything in reverse
|
||||
vector<string> mounts;
|
||||
parse_mnt("/proc/mounts", [&](mntent *me) {
|
||||
if (me->mnt_dir != "/"sv)
|
||||
mounts.emplace_back(me->mnt_dir);
|
||||
return true;
|
||||
});
|
||||
for (auto &m : reversed(mounts))
|
||||
xumount(m.data());
|
||||
|
||||
// chroot jail
|
||||
chdir(dirname(argv[0]));
|
||||
chroot(".");
|
||||
chdir("/");
|
||||
|
||||
cmdline cmd{};
|
||||
load_kernel_info(&cmd);
|
||||
|
||||
auto init = make_unique<TestInit>(argv, &cmd);
|
||||
init->start();
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif // ENABLE_TEST
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
umask(0);
|
||||
|
||||
auto name = basename(argv[0]);
|
||||
if (name == "magisk"sv)
|
||||
return magisk_proxy_main(argc, argv);
|
||||
for (int i = 0; init_applet[i]; ++i) {
|
||||
if (strcmp(name, init_applet[i]) == 0)
|
||||
return (*init_applet_main[i])(argc, argv);
|
||||
}
|
||||
|
||||
#if ENABLE_TEST
|
||||
if (getenv("INIT_TEST") != nullptr)
|
||||
return test_main(argc, argv);
|
||||
#endif
|
||||
|
||||
if (argc > 1 && argv[1] == "-x"sv) {
|
||||
if (argc > 2 && argv[2] == "manager"sv)
|
||||
|
||||
Reference in New Issue
Block a user