mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-14 14:31:53 +00:00
Generalize unxz
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user