Generalize unxz

This commit is contained in:
topjohnwu
2023-09-21 05:47:21 -07:00
parent 15e13a8d8b
commit 46275b90c2
4 changed files with 24 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
#include <magisk.hpp>
#include <sepolicy.hpp>
#include <base.hpp>
#include <embed.hpp>
#include "init.hpp"
@@ -38,6 +38,16 @@ void MagiskInit::patch_sepolicy(const char *in, const char *out) {
}
}
static void dump_preload() {
int fd = xopen("/dev/preload.so", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd < 0)
return;
fd_channel ch(fd);
if (!unxz(ch, byte_view(init_ld_xz, sizeof(init_ld_xz))))
return;
close(fd);
}
#define MOCK_COMPAT SELINUXMOCK "/compatible"
#define MOCK_LOAD SELINUXMOCK "/load"
#define MOCK_ENFORCE SELINUXMOCK "/enforce"
@@ -50,7 +60,7 @@ bool MagiskInit::hijack_sepolicy() {
// This meant that instead of going through convoluted methods trying to alter
// and block init's control flow, we can just LD_PRELOAD and replace the
// security_load_policy function with our own implementation.
dump_preload("/dev/preload.so", 0644);
dump_preload();
setenv("LD_PRELOAD", "/dev/preload.so", 1);
}