mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-24 04:27:48 +00:00
Stop embedding executables
This commit is contained in:
@@ -7,7 +7,7 @@ LOCAL_MODULE := libbase
|
||||
LOCAL_C_INCLUDES := \
|
||||
src/include \
|
||||
$(LOCAL_PATH)/include \
|
||||
$(LOCAL_PATH)/../external/cxx-rs/include \
|
||||
src/external/cxx-rs/include \
|
||||
out/generated
|
||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
|
||||
LOCAL_EXPORT_STATIC_LIBRARIES := libcxx
|
||||
|
@@ -1,13 +0,0 @@
|
||||
#if defined(__arm__)
|
||||
#include <armeabi-v7a_binaries.h>
|
||||
#elif defined(__aarch64__)
|
||||
#include <arm64-v8a_binaries.h>
|
||||
#elif defined(__i386__)
|
||||
#include <x86_binaries.h>
|
||||
#elif defined(__x86_64__)
|
||||
#include <x86_64_binaries.h>
|
||||
#elif defined(__riscv)
|
||||
#include <riscv64_binaries.h>
|
||||
#else
|
||||
#error Unsupported ABI
|
||||
#endif
|
@@ -6,7 +6,6 @@
|
||||
#include <xz.h>
|
||||
|
||||
#include <base.hpp>
|
||||
#include <embed.hpp>
|
||||
|
||||
#include "init.hpp"
|
||||
|
||||
|
@@ -189,6 +189,7 @@ static void magic_mount(const string &sdir, const string &ddir = "") {
|
||||
static void extract_files(bool sbin) {
|
||||
const char *magisk_xz = sbin ? "/sbin/magisk.xz" : "magisk.xz";
|
||||
const char *stub_xz = sbin ? "/sbin/stub.xz" : "stub.xz";
|
||||
const char *init_ld_xz = sbin ? "/sbin/init-ld.xz" : "init-ld.xz";
|
||||
|
||||
if (access(magisk_xz, F_OK) == 0) {
|
||||
mmap_data magisk(magisk_xz);
|
||||
@@ -206,6 +207,14 @@ static void extract_files(bool sbin) {
|
||||
unxz(ch, stub);
|
||||
close(fd);
|
||||
}
|
||||
if (access(init_ld_xz, F_OK) == 0) {
|
||||
mmap_data init_ld(init_ld_xz);
|
||||
unlink(init_ld_xz);
|
||||
int fd = xopen("init-ld", O_WRONLY | O_CREAT, 0);
|
||||
fd_stream ch(fd);
|
||||
unxz(ch, init_ld);
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
void MagiskInit::parse_config_file() {
|
||||
@@ -279,16 +288,19 @@ void MagiskInit::patch_ro_root() {
|
||||
patch_rc_scripts("/", tmp_dir.data(), false);
|
||||
}
|
||||
|
||||
// Extract magisk
|
||||
// Extract overlay archives
|
||||
extract_files(false);
|
||||
|
||||
// Oculus Go will use a special sepolicy if unlocked
|
||||
if (access("/sepolicy.unlocked", F_OK) == 0) {
|
||||
patch_sepolicy("/sepolicy.unlocked", ROOTOVL "/sepolicy.unlocked");
|
||||
} else if ((access(SPLIT_PLAT_CIL, F_OK) != 0 && access("/sepolicy", F_OK) == 0) ||
|
||||
!hijack_sepolicy()) {
|
||||
patch_sepolicy("/sepolicy", ROOTOVL "/sepolicy");
|
||||
} else {
|
||||
bool patch = access(SPLIT_PLAT_CIL, F_OK) != 0 && access("/sepolicy", F_OK) == 0;
|
||||
if (patch || !hijack_sepolicy()) {
|
||||
patch_sepolicy("/sepolicy", ROOTOVL "/sepolicy");
|
||||
}
|
||||
}
|
||||
unlink("init-ld");
|
||||
|
||||
// Mount rootdir
|
||||
magic_mount(ROOTOVL);
|
||||
@@ -338,12 +350,14 @@ void MagiskInit::patch_rw_root() {
|
||||
setup_tmp(PRE_TMPDIR);
|
||||
chdir(PRE_TMPDIR);
|
||||
|
||||
// Extract magisk
|
||||
// Extract overlay archives
|
||||
extract_files(true);
|
||||
|
||||
if ((!treble && access("/sepolicy", F_OK) == 0) || !hijack_sepolicy()) {
|
||||
bool patch = !treble && access("/sepolicy", F_OK) == 0;
|
||||
if (patch || !hijack_sepolicy()) {
|
||||
patch_sepolicy("/sepolicy", "/sepolicy");
|
||||
}
|
||||
unlink("init-ld");
|
||||
|
||||
chdir("/");
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <consts.hpp>
|
||||
#include <sepolicy.hpp>
|
||||
#include <embed.hpp>
|
||||
|
||||
#include "init.hpp"
|
||||
|
||||
@@ -31,16 +30,6 @@ 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_stream 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"
|
||||
@@ -53,7 +42,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();
|
||||
cp_afc("init-ld", "/dev/preload.so");
|
||||
setenv("LD_PRELOAD", "/dev/preload.so", 1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user