mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 12:05:30 +00:00
Rename rules to preinit
It is possible that we will allow more preinit files for modules. Rename the partition and folders from rules to preinit.
This commit is contained in:
parent
7048aa1014
commit
4e2b88b3d0
@ -43,10 +43,10 @@ data class LocalModule(
|
|||||||
set(enable) {
|
set(enable) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
disableFile.delete()
|
disableFile.delete()
|
||||||
Shell.cmd("copy_rules").submit()
|
Shell.cmd("copy_preinit_files").submit()
|
||||||
} else {
|
} else {
|
||||||
!disableFile.createNewFile()
|
!disableFile.createNewFile()
|
||||||
Shell.cmd("copy_rules").submit()
|
Shell.cmd("copy_preinit_files").submit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,10 +56,10 @@ data class LocalModule(
|
|||||||
if (remove) {
|
if (remove) {
|
||||||
if (updateFile.exists()) return
|
if (updateFile.exists()) return
|
||||||
removeFile.createNewFile()
|
removeFile.createNewFile()
|
||||||
Shell.cmd("copy_rules").submit()
|
Shell.cmd("copy_preinit_files").submit()
|
||||||
} else {
|
} else {
|
||||||
removeFile.delete()
|
removeFile.delete()
|
||||||
Shell.cmd("copy_rules").submit()
|
Shell.cmd("copy_preinit_files").submit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class ShellInit : Shell.Initializer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shell.isRoot) {
|
if (shell.isRoot) {
|
||||||
add("export MAGISKTMP=\$(magisk --path)/.magisk")
|
add("export MAGISKTMP=\$(magisk --path)")
|
||||||
// Test if we can properly execute stuff in /data
|
// Test if we can properly execute stuff in /data
|
||||||
Info.noDataExec = !shell.newJob().add("$localBB sh -c \"$localBB true\"").exec().isSuccess
|
Info.noDataExec = !shell.newJob().add("$localBB sh -c \"$localBB true\"").exec().isSuccess
|
||||||
}
|
}
|
||||||
@ -49,9 +49,9 @@ class ShellInit : Shell.Initializer() {
|
|||||||
if (Info.noDataExec) {
|
if (Info.noDataExec) {
|
||||||
// Copy it out of /data to workaround Samsung bullshit
|
// Copy it out of /data to workaround Samsung bullshit
|
||||||
add(
|
add(
|
||||||
"if [ -x \$MAGISKTMP/busybox/busybox ]; then",
|
"if [ -x \$MAGISKTMP/.magisk/busybox/busybox ]; then",
|
||||||
" cp -af $localBB \$MAGISKTMP/busybox/busybox",
|
" cp -af $localBB \$MAGISKTMP/.magisk/busybox/busybox",
|
||||||
" exec \$MAGISKTMP/busybox/busybox sh",
|
" exec \$MAGISKTMP/.magisk/busybox/busybox sh",
|
||||||
"else",
|
"else",
|
||||||
" cp -af $localBB /dev/busybox",
|
" cp -af $localBB /dev/busybox",
|
||||||
" exec /dev/busybox sh",
|
" exec /dev/busybox sh",
|
||||||
|
@ -14,7 +14,7 @@ env_check() {
|
|||||||
[ -f "$MAGISKBIN/magiskpolicy" ] || return 1
|
[ -f "$MAGISKBIN/magiskpolicy" ] || return 1
|
||||||
fi
|
fi
|
||||||
if [ "$2" -ge 25210 ]; then
|
if [ "$2" -ge 25210 ]; then
|
||||||
[ -b "$MAGISKTMP/block/rules" ] || return 2
|
[ -b "$MAGISKTMP/.magisk/block/preinit" ] || return 2
|
||||||
fi
|
fi
|
||||||
grep -xqF "MAGISK_VER='$1'" "$MAGISKBIN/util_functions.sh" || return 3
|
grep -xqF "MAGISK_VER='$1'" "$MAGISKBIN/util_functions.sh" || return 3
|
||||||
grep -xqF "MAGISK_VER_CODE=$2" "$MAGISKBIN/util_functions.sh" || return 3
|
grep -xqF "MAGISK_VER_CODE=$2" "$MAGISKBIN/util_functions.sh" || return 3
|
||||||
@ -67,7 +67,7 @@ direct_install() {
|
|||||||
rm -f $1/new-boot.img
|
rm -f $1/new-boot.img
|
||||||
fix_env $1
|
fix_env $1
|
||||||
run_migrations
|
run_migrations
|
||||||
copy_rules
|
copy_preinit_files
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -12,39 +12,28 @@ Magisk will mount a `tmpfs` directory to store some temporary data. For devices
|
|||||||
# Binaries like magisk, magiskinit, and all symlinks to
|
# Binaries like magisk, magiskinit, and all symlinks to
|
||||||
# applets are directly stored in this path. This means when
|
# applets are directly stored in this path. This means when
|
||||||
# this is /sbin, these binaries will be directly in PATH.
|
# this is /sbin, these binaries will be directly in PATH.
|
||||||
MAGISKBASE=$(magisk --path)
|
MAGISKTMP=$(magisk --path)
|
||||||
|
|
||||||
# Magisk internal stuffs
|
# Magisk internal stuffs
|
||||||
MAGISKTMP=$MAGISKBASE/.magisk
|
INTERNALDIR=$MAGISKTMP/.magisk
|
||||||
|
|
||||||
# Magisk's BusyBox directory. Within this folder stores
|
|
||||||
# the busybox binary and symlinks to all of its applets.
|
|
||||||
# Any usage of this directory is deprecated, please
|
|
||||||
# directly call /data/adb/magisk/busybox and use
|
|
||||||
# BusyBox's ASH Standalone mode.
|
|
||||||
# The creation of this path will be removed in the future.
|
|
||||||
$MAGISKTMP/busybox
|
|
||||||
|
|
||||||
# /data/adb/modules will be bind mounted here.
|
# /data/adb/modules will be bind mounted here.
|
||||||
# The original folder is not used due to nosuid mount flag.
|
# The original folder is not used due to nosuid mount flag.
|
||||||
$MAGISKTMP/modules
|
$INTERNALDIR/modules
|
||||||
|
|
||||||
# The current Magisk installation config
|
# The current Magisk installation config
|
||||||
$MAGISKTMP/config
|
$INTERNALDIR/config
|
||||||
|
|
||||||
# Partition mirrors
|
# Partition mirrors
|
||||||
# Each directory in this path will be mounted with the
|
# Each directory in this path will be mounted with the
|
||||||
# partition of its directory name.
|
# partition of its directory name.
|
||||||
# e.g. system, system_ext, vendor, data ...
|
# e.g. system, system_ext, vendor, data ...
|
||||||
$MAGISKTMP/mirror
|
$INTERNALDIR/mirror
|
||||||
|
|
||||||
# Block devices Magisk creates internally to mount mirrors.
|
|
||||||
$MAGISKTMP/block
|
|
||||||
|
|
||||||
# Root directory patch files
|
# Root directory patch files
|
||||||
# On system-as-root devices, / is not writable.
|
# On system-as-root devices, / is not writable.
|
||||||
# All pre-init patched files are stored here and bind mounted.
|
# All pre-init patched files are stored here and bind mounted.
|
||||||
$MAGISKTMP/rootdir
|
$INTERNALDIR/rootdir
|
||||||
```
|
```
|
||||||
|
|
||||||
### Paths in `/data`
|
### Paths in `/data`
|
||||||
|
@ -506,14 +506,14 @@ string find_apk_path(const char *pkg) {
|
|||||||
return path.append("/base.apk");
|
return path.append("/base.apk");
|
||||||
}
|
}
|
||||||
|
|
||||||
string find_rules_dir(const char *base_dir) {
|
string resolve_preinit_dir(const char *base_dir) {
|
||||||
string rules_dir = base_dir;
|
string dir = base_dir;
|
||||||
if (access((rules_dir + "/unencrypted").data(), F_OK) == 0) {
|
if (access((dir + "/unencrypted").data(), F_OK) == 0) {
|
||||||
rules_dir += "/unencrypted/magisk";
|
dir += "/unencrypted/magisk";
|
||||||
} else if (access((rules_dir + "/adb").data(), F_OK) == 0) {
|
} else if (access((dir + "/adb").data(), F_OK) == 0) {
|
||||||
rules_dir += "/adb/modules";
|
dir += "/adb/modules";
|
||||||
} else {
|
} else {
|
||||||
rules_dir += "/magisk";
|
dir += "/magisk";
|
||||||
}
|
}
|
||||||
return rules_dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ void frm_rf(int dirfd);
|
|||||||
void clone_dir(int src, int dest);
|
void clone_dir(int src, int dest);
|
||||||
std::vector<mount_info> parse_mount_info(const char *pid);
|
std::vector<mount_info> parse_mount_info(const char *pid);
|
||||||
std::string find_apk_path(const char *pkg);
|
std::string find_apk_path(const char *pkg);
|
||||||
std::string find_rules_dir(const char *base_dir);
|
std::string resolve_preinit_dir(const char *base_dir);
|
||||||
|
|
||||||
using sFILE = std::unique_ptr<FILE, decltype(&fclose)>;
|
using sFILE = std::unique_ptr<FILE, decltype(&fclose)>;
|
||||||
using sDIR = std::unique_ptr<DIR, decltype(&closedir)>;
|
using sDIR = std::unique_ptr<DIR, decltype(&closedir)>;
|
||||||
|
@ -60,20 +60,20 @@ static void mount_mirrors() {
|
|||||||
restorecon();
|
restorecon();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check and mount rules
|
// Check and mount preinit mirror
|
||||||
if (struct stat st{}; stat((MAGISKTMP + "/" BLOCKDIR "/rules").data(), &st) == 0 && (st.st_mode & S_IFBLK)) {
|
if (struct stat st{}; stat((MAGISKTMP + "/" PREINITDEV).data(), &st) == 0 && (st.st_mode & S_IFBLK)) {
|
||||||
dev_t rules_dev = st.st_rdev;
|
dev_t preinit_dev = st.st_rdev;
|
||||||
for (const auto &info: self_mount_info) {
|
for (const auto &info: self_mount_info) {
|
||||||
if (info.root == "/" && info.device == rules_dev) {
|
if (info.root == "/" && info.device == preinit_dev) {
|
||||||
auto flags = split_ro(info.fs_option, ",");
|
auto flags = split_ro(info.fs_option, ",");
|
||||||
auto rw = std::any_of(flags.begin(), flags.end(), [](const auto &flag) {
|
auto rw = std::any_of(flags.begin(), flags.end(), [](const auto &flag) {
|
||||||
return flag == "rw"sv;
|
return flag == "rw"sv;
|
||||||
});
|
});
|
||||||
if (!rw) continue;
|
if (!rw) continue;
|
||||||
string custom_rules_dir = find_rules_dir(info.target.data());
|
string preinit_dir = resolve_preinit_dir(info.target.data());
|
||||||
xmkdir(custom_rules_dir.data(), 0700);
|
xmkdir(preinit_dir.data(), 0700);
|
||||||
auto rules_dir = MAGISKTMP + "/" RULESDIR;
|
auto mirror_dir = MAGISKTMP + "/" PREINITMIRR;
|
||||||
mount_mirror(custom_rules_dir, rules_dir);
|
mount_mirror(preinit_dir, mirror_dir);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ static void mount_mirrors() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_t find_rules_device() {
|
dev_t find_preinit_device() {
|
||||||
const int UNKNOWN = 0;
|
const int UNKNOWN = 0;
|
||||||
const int PERSIST = 1;
|
const int PERSIST = 1;
|
||||||
const int METADATA = 2;
|
const int METADATA = 2;
|
||||||
@ -113,12 +113,12 @@ dev_t find_rules_device() {
|
|||||||
int matched = UNKNOWN;
|
int matched = UNKNOWN;
|
||||||
dev_t rules_dev = 0;
|
dev_t rules_dev = 0;
|
||||||
bool encrypted = getprop("ro.crypto.state") == "encrypted";
|
bool encrypted = getprop("ro.crypto.state") == "encrypted";
|
||||||
string custom_rules_dir;
|
string preinit_dir;
|
||||||
|
|
||||||
bool mount = getuid() == 0 && getenv("MAGISKTMP");
|
bool mount = getuid() == 0 && getenv("MAGISKTMP");
|
||||||
|
|
||||||
for (const auto &info: parse_mount_info("self")) {
|
for (const auto &info: parse_mount_info("self")) {
|
||||||
if (info.target.ends_with(RULESDIR))
|
if (info.target.ends_with(PREINITMIRR))
|
||||||
return info.device;
|
return info.device;
|
||||||
if (info.root != "/" || info.source.find("/dm-") != string::npos)
|
if (info.root != "/" || info.source.find("/dm-") != string::npos)
|
||||||
continue;
|
continue;
|
||||||
@ -146,17 +146,17 @@ dev_t find_rules_device() {
|
|||||||
} else continue;
|
} else continue;
|
||||||
|
|
||||||
if (mount) {
|
if (mount) {
|
||||||
custom_rules_dir = find_rules_dir(info.target.data());
|
preinit_dir = resolve_preinit_dir(info.target.data());
|
||||||
}
|
}
|
||||||
rules_dev = info.device;
|
rules_dev = info.device;
|
||||||
matched = new_matched;
|
matched = new_matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!custom_rules_dir.empty()) {
|
if (!preinit_dir.empty()) {
|
||||||
auto rules_dir = getenv("MAGISKTMP") + "/rules"s;
|
auto mirror_dir = string(getenv("MAGISKTMP")) + "/" PREINITMIRR;
|
||||||
mkdirs(custom_rules_dir.data(), 0700);
|
mkdirs(preinit_dir.data(), 0700);
|
||||||
mkdirs(rules_dir.data(), 0700);
|
mkdirs(mirror_dir.data(), 0700);
|
||||||
xmount(custom_rules_dir.data(), rules_dir.data(), nullptr, MS_BIND, nullptr);
|
xmount(preinit_dir.data(), mirror_dir.data(), nullptr, MS_BIND, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rules_dev;
|
return rules_dev;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
extern bool RECOVERY_MODE;
|
extern bool RECOVERY_MODE;
|
||||||
extern std::atomic<ino_t> pkg_xml_ino;
|
extern std::atomic<ino_t> pkg_xml_ino;
|
||||||
|
|
||||||
dev_t find_rules_device();
|
dev_t find_preinit_device();
|
||||||
void unlock_blocks();
|
void unlock_blocks();
|
||||||
void reboot();
|
void reboot();
|
||||||
void start_log_daemon();
|
void start_log_daemon();
|
||||||
|
@ -122,7 +122,6 @@ int magisk_main(int argc, char *argv[]) {
|
|||||||
do_reboot = 1;
|
do_reboot = 1;
|
||||||
} else {
|
} else {
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
int fd = connect_daemon(MainRequest::REMOVE_MODULES);
|
int fd = connect_daemon(MainRequest::REMOVE_MODULES);
|
||||||
write_int(fd, do_reboot);
|
write_int(fd, do_reboot);
|
||||||
@ -134,8 +133,8 @@ int magisk_main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
} else if (argc >= 3 && argv[1] == "--install-module"sv) {
|
} else if (argc >= 3 && argv[1] == "--install-module"sv) {
|
||||||
install_module(argv[2]);
|
install_module(argv[2]);
|
||||||
} else if (argv[1] == "--rules-device"sv) {
|
} else if (argv[1] == "--preinit-device"sv) {
|
||||||
auto dev = find_rules_device();
|
auto dev = find_preinit_device();
|
||||||
if (dev) printf("%u:%u\n", major(dev), minor(dev));
|
if (dev) printf("%u:%u\n", major(dev), minor(dev));
|
||||||
return dev ? 0 : 1;
|
return dev ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
@ -437,7 +437,7 @@ void handle_modules() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int check_rules_dir(char *buf, size_t sz) {
|
static int check_rules_dir(char *buf, size_t sz) {
|
||||||
int off = ssprintf(buf, sz, "%s/%s", MAGISKTMP.data(), RULESDIR);
|
int off = ssprintf(buf, sz, "%s/%s", MAGISKTMP.data(), PREINITMIRR);
|
||||||
struct stat st1{};
|
struct stat st1{};
|
||||||
struct stat st2{};
|
struct stat st2{};
|
||||||
if (xstat(buf, &st1) < 0 || xstat(MODULEROOT, &st2) < 0)
|
if (xstat(buf, &st1) < 0 || xstat(MODULEROOT, &st2) < 0)
|
||||||
|
@ -18,8 +18,9 @@
|
|||||||
extern std::string MAGISKTMP;
|
extern std::string MAGISKTMP;
|
||||||
#define INTLROOT ".magisk"
|
#define INTLROOT ".magisk"
|
||||||
#define MIRRDIR INTLROOT "/mirror"
|
#define MIRRDIR INTLROOT "/mirror"
|
||||||
#define RULESDIR INTLROOT "/rules"
|
#define PREINITMIRR INTLROOT "/preinit"
|
||||||
#define BLOCKDIR INTLROOT "/block"
|
#define BLOCKDIR INTLROOT "/block"
|
||||||
|
#define PREINITDEV BLOCKDIR "/preinit"
|
||||||
#define WORKERDIR INTLROOT "/worker"
|
#define WORKERDIR INTLROOT "/worker"
|
||||||
#define MODULEMNT INTLROOT "/modules"
|
#define MODULEMNT INTLROOT "/modules"
|
||||||
#define BBPATH INTLROOT "/busybox"
|
#define BBPATH INTLROOT "/busybox"
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
|
|
||||||
class MagiskInit : public BaseInit {
|
class MagiskInit : public BaseInit {
|
||||||
private:
|
private:
|
||||||
dev_t rules_dev = 0;
|
dev_t preinit_dev = 0;
|
||||||
|
|
||||||
void parse_config_file();
|
void parse_config_file();
|
||||||
void patch_sepolicy(const char *in, const char *out);
|
void patch_sepolicy(const char *in, const char *out);
|
||||||
|
@ -111,38 +111,40 @@ static void switch_root(const string &path) {
|
|||||||
frm_rf(root);
|
frm_rf(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mount_rules_dir(string path, dev_t rules_dev) {
|
#define PREINITMNT MIRRDIR "/preinit"
|
||||||
if (!rules_dev) return;
|
|
||||||
xmknod(BLOCKDIR "/rules", S_IFBLK | 0600, rules_dev);
|
static void mount_preinit_dir(string path, dev_t preinit_dev) {
|
||||||
xmkdir(MIRRDIR "/rules", 0);
|
if (!preinit_dev) return;
|
||||||
|
xmknod(PREINITDEV, S_IFBLK | 0600, preinit_dev);
|
||||||
|
xmkdir(PREINITMNT, 0);
|
||||||
|
|
||||||
bool mounted = false;
|
bool mounted = false;
|
||||||
// first of all, find if rules dev is already mounted
|
// First, find if it is already mounted
|
||||||
for (auto &info : parse_mount_info("self")) {
|
for (auto &info : parse_mount_info("self")) {
|
||||||
if (info.root == "/" && info.device == rules_dev) {
|
if (info.root == "/" && info.device == preinit_dev) {
|
||||||
// Already mounted, just bind mount
|
// Already mounted, just bind mount
|
||||||
xmount(info.target.data(), MIRRDIR "/rules", nullptr, MS_BIND, nullptr);
|
xmount(info.target.data(), PREINITMNT, nullptr, MS_BIND, nullptr);
|
||||||
mounted = true;
|
mounted = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mounted || mount(BLOCKDIR "/rules", MIRRDIR "/rules", "ext4", MS_RDONLY, nullptr) == 0 ||
|
if (mounted || mount(PREINITDEV, PREINITMNT, "ext4", MS_RDONLY, nullptr) == 0 ||
|
||||||
mount(BLOCKDIR "/rules", MIRRDIR "/rules", "f2fs", MS_RDONLY, nullptr) == 0) {
|
mount(PREINITDEV, PREINITMNT, "f2fs", MS_RDONLY, nullptr) == 0) {
|
||||||
string custom_rules_dir = find_rules_dir(MIRRDIR "/rules");
|
string preinit_dir = resolve_preinit_dir(PREINITMNT);
|
||||||
// Create bind mount
|
// Create bind mount
|
||||||
xmkdirs(RULESDIR, 0);
|
xmkdirs(PREINITMIRR, 0);
|
||||||
if (access(custom_rules_dir.data(), F_OK)) {
|
if (access(preinit_dir.data(), F_OK)) {
|
||||||
LOGW("empty rules: %s\n", custom_rules_dir.data());
|
LOGW("empty preinit: %s\n", preinit_dir.data());
|
||||||
} else {
|
} else {
|
||||||
LOGD("rules: %s\n", custom_rules_dir.data());
|
LOGD("preinit: %s\n", preinit_dir.data());
|
||||||
xmount(custom_rules_dir.data(), RULESDIR, nullptr, MS_BIND, nullptr);
|
xmount(preinit_dir.data(), PREINITMIRR, nullptr, MS_BIND, nullptr);
|
||||||
mount_list.emplace_back(path += "/" RULESDIR);
|
mount_list.emplace_back(path += "/" PREINITMIRR);
|
||||||
}
|
}
|
||||||
xumount2(MIRRDIR "/rules", MNT_DETACH);
|
xumount2(PREINITMNT, MNT_DETACH);
|
||||||
} else {
|
} else {
|
||||||
PLOGE("Failed to mount rules %u:%u", major(rules_dev), minor(rules_dev));
|
PLOGE("Failed to mount rules %u:%u", major(preinit_dev), minor(preinit_dev));
|
||||||
unlink(BLOCKDIR "/rules");
|
unlink(PREINITDEV);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +248,7 @@ void MagiskInit::setup_tmp(const char *path) {
|
|||||||
xmkdir(BLOCKDIR, 0);
|
xmkdir(BLOCKDIR, 0);
|
||||||
xmkdir(WORKERDIR, 0);
|
xmkdir(WORKERDIR, 0);
|
||||||
|
|
||||||
mount_rules_dir(path, rules_dev);
|
mount_preinit_dir(path, preinit_dev);
|
||||||
|
|
||||||
cp_afc(".backup/.magisk", INTLROOT "/config");
|
cp_afc(".backup/.magisk", INTLROOT "/config");
|
||||||
rm_rf(".backup");
|
rm_rf(".backup");
|
||||||
|
@ -185,7 +185,7 @@ static void extract_files(bool sbin) {
|
|||||||
void MagiskInit::parse_config_file() {
|
void MagiskInit::parse_config_file() {
|
||||||
dev_t dev = 0;
|
dev_t dev = 0;
|
||||||
parse_prop_file("/data/.backup/.magisk", [&dev](auto key, auto value) -> bool {
|
parse_prop_file("/data/.backup/.magisk", [&dev](auto key, auto value) -> bool {
|
||||||
if (key == "RULESDEVICE") {
|
if (key == "PREINITDEVICE") {
|
||||||
unsigned int dev_major = 0;
|
unsigned int dev_major = 0;
|
||||||
unsigned int dev_minor = 0;
|
unsigned int dev_minor = 0;
|
||||||
sscanf(value.data(), "%u:%u", &dev_major, &dev_minor);
|
sscanf(value.data(), "%u:%u", &dev_major, &dev_minor);
|
||||||
@ -194,7 +194,7 @@ void MagiskInit::parse_config_file() {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
rules_dev = dev;
|
preinit_dev = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ROOTMIR MIRRDIR "/system_root"
|
#define ROOTMIR MIRRDIR "/system_root"
|
||||||
|
@ -15,12 +15,12 @@ void MagiskInit::patch_sepolicy(const char *in, const char *out) {
|
|||||||
sepol->magisk_rules();
|
sepol->magisk_rules();
|
||||||
|
|
||||||
// Custom rules
|
// Custom rules
|
||||||
if (auto dir = xopen_dir(RULESDIR)) {
|
if (auto dir = xopen_dir(PREINITMIRR)) {
|
||||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||||
auto rule = RULESDIR "/"s + entry->d_name + "/sepolicy.rule";
|
auto rule = PREINITMIRR "/"s + entry->d_name + "/sepolicy.rule";
|
||||||
if (xaccess(rule.data(), R_OK) == 0 &&
|
if (xaccess(rule.data(), R_OK) == 0 &&
|
||||||
access((RULESDIR "/"s + entry->d_name + "/disable").data(), F_OK) != 0 &&
|
access((PREINITMIRR "/"s + entry->d_name + "/disable").data(), F_OK) != 0 &&
|
||||||
access((RULESDIR "/"s + entry->d_name + "/remove").data(), F_OK) != 0) {
|
access((PREINITMIRR "/"s + entry->d_name + "/remove").data(), F_OK) != 0) {
|
||||||
LOGD("Loading custom sepolicy patch: [%s]\n", rule.data());
|
LOGD("Loading custom sepolicy patch: [%s]\n", rule.data());
|
||||||
sepol->load_rule_file(rule.data());
|
sepol->load_rule_file(rule.data());
|
||||||
}
|
}
|
||||||
@ -96,12 +96,12 @@ bool MagiskInit::hijack_sepolicy() {
|
|||||||
|
|
||||||
// Read all custom rules into memory
|
// Read all custom rules into memory
|
||||||
string rules;
|
string rules;
|
||||||
if (auto dir = xopen_dir(RULESDIR)) {
|
if (auto dir = xopen_dir(PREINITMIRR)) {
|
||||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||||
auto rule_file = RULESDIR "/"s + entry->d_name + "/sepolicy.rule";
|
auto rule_file = PREINITMIRR "/"s + entry->d_name + "/sepolicy.rule";
|
||||||
if (xaccess(rule_file.data(), R_OK) == 0 &&
|
if (xaccess(rule_file.data(), R_OK) == 0 &&
|
||||||
access((RULESDIR "/"s + entry->d_name + "/disable").data(), F_OK) != 0 &&
|
access((PREINITMIRR "/"s + entry->d_name + "/disable").data(), F_OK) != 0 &&
|
||||||
access((RULESDIR "/"s + entry->d_name + "/remove").data(), F_OK) != 0) {
|
access((PREINITMIRR "/"s + entry->d_name + "/remove").data(), F_OK) != 0) {
|
||||||
LOGD("Load custom sepolicy patch: [%s]\n", rule_file.data());
|
LOGD("Load custom sepolicy patch: [%s]\n", rule_file.data());
|
||||||
full_read(rule_file.data(), rules);
|
full_read(rule_file.data(), rules);
|
||||||
rules += '\n';
|
rules += '\n';
|
||||||
|
@ -63,9 +63,9 @@ export KEEPFORCEENCRYPT=true
|
|||||||
echo "KEEPVERITY=$KEEPVERITY" > config
|
echo "KEEPVERITY=$KEEPVERITY" > config
|
||||||
echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config
|
echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config
|
||||||
if [ -e "/system/bin/linker64" ]; then
|
if [ -e "/system/bin/linker64" ]; then
|
||||||
echo "RULESDEVICE=$(./magisk64 --rules-device)" >> config
|
echo "PREINITDEVICE=$(./magisk64 --preinit-device)" >> config
|
||||||
else
|
else
|
||||||
echo "RULESDEVICE=$(./magisk32 --rules-device)" >> config
|
echo "PREINITDEVICE=$(./magisk32 --preinit-device)" >> config
|
||||||
fi
|
fi
|
||||||
# For API 28, we also patch advancedFeatures.ini to disable SAR
|
# For API 28, we also patch advancedFeatures.ini to disable SAR
|
||||||
# Manually override skip_initramfs by setting RECOVERYMODE=true
|
# Manually override skip_initramfs by setting RECOVERYMODE=true
|
||||||
|
@ -77,7 +77,6 @@ fi
|
|||||||
export KEEPVERITY
|
export KEEPVERITY
|
||||||
export KEEPFORCEENCRYPT
|
export KEEPFORCEENCRYPT
|
||||||
export PATCHVBMETAFLAG
|
export PATCHVBMETAFLAG
|
||||||
export MAGISKTMP
|
|
||||||
|
|
||||||
chmod -R 755 .
|
chmod -R 755 .
|
||||||
|
|
||||||
@ -138,7 +137,7 @@ case $((STATUS & 3)) in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Work around custom legacy Sony /init -> /(s)bin/init_sony : /init.real setup
|
# Workaround custom legacy Sony /init -> /(s)bin/init_sony : /init.real setup
|
||||||
INIT=init
|
INIT=init
|
||||||
if [ $((STATUS & 4)) -ne 0 ]; then
|
if [ $((STATUS & 4)) -ne 0 ]; then
|
||||||
INIT=init.real
|
INIT=init.real
|
||||||
@ -153,24 +152,26 @@ ui_print "- Patching ramdisk"
|
|||||||
# Compress to save precious ramdisk space
|
# Compress to save precious ramdisk space
|
||||||
SKIP32="#"
|
SKIP32="#"
|
||||||
SKIP64="#"
|
SKIP64="#"
|
||||||
if [ -f magisk32 ]; then
|
|
||||||
$BOOTMODE && [ -z "$RULESDEVICE" ] && RULESDEVICE=$(./magisk32 --rules-device)
|
|
||||||
./magiskboot compress=xz magisk32 magisk32.xz
|
|
||||||
unset SKIP32
|
|
||||||
fi
|
|
||||||
if [ -f magisk64 ]; then
|
if [ -f magisk64 ]; then
|
||||||
$BOOTMODE && [ -z "$RULESDEVICE" ] && RULESDEVICE=$(./magisk64 --rules-device)
|
$BOOTMODE && [ -z "$PREINITDEVICE" ] && PREINITDEVICE=$(./magisk64 --preinit-device)
|
||||||
./magiskboot compress=xz magisk64 magisk64.xz
|
./magiskboot compress=xz magisk64 magisk64.xz
|
||||||
unset SKIP64
|
unset SKIP64
|
||||||
fi
|
fi
|
||||||
|
if [ -f magisk32 ]; then
|
||||||
|
$BOOTMODE && [ -z "$PREINITDEVICE" ] && PREINITDEVICE=$(./magisk32 --preinit-device)
|
||||||
|
./magiskboot compress=xz magisk32 magisk32.xz
|
||||||
|
unset SKIP32
|
||||||
|
fi
|
||||||
./magiskboot compress=xz stub.apk stub.xz
|
./magiskboot compress=xz stub.apk stub.xz
|
||||||
|
|
||||||
echo "KEEPVERITY=$KEEPVERITY" > config
|
echo "KEEPVERITY=$KEEPVERITY" > config
|
||||||
echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config
|
echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config
|
||||||
echo "PATCHVBMETAFLAG=$PATCHVBMETAFLAG" >> config
|
echo "PATCHVBMETAFLAG=$PATCHVBMETAFLAG" >> config
|
||||||
echo "RECOVERYMODE=$RECOVERYMODE" >> config
|
echo "RECOVERYMODE=$RECOVERYMODE" >> config
|
||||||
[ -n "$RULESDEVICE" ] && ui_print "- Rules partition device ID: $RULESDEVICE"
|
if [ -n "$PREINITDEVICE" ]; then
|
||||||
[ -n "$RULESDEVICE" ] && echo "RULESDEVICE=$RULESDEVICE" >> config
|
ui_print "- Pre-init storage partition device ID: $PREINITDEVICE"
|
||||||
|
echo "PREINITDEVICE=$PREINITDEVICE" >> config
|
||||||
|
fi
|
||||||
[ -n "$SHA1" ] && echo "SHA1=$SHA1" >> config
|
[ -n "$SHA1" ] && echo "SHA1=$SHA1" >> config
|
||||||
|
|
||||||
./magiskboot cpio ramdisk.cpio \
|
./magiskboot cpio ramdisk.cpio \
|
||||||
|
@ -49,7 +49,7 @@ getvar() {
|
|||||||
local VARNAME=$1
|
local VARNAME=$1
|
||||||
local VALUE
|
local VALUE
|
||||||
local PROPPATH='/data/.magisk /cache/.magisk'
|
local PROPPATH='/data/.magisk /cache/.magisk'
|
||||||
[ ! -z $MAGISKTMP ] && PROPPATH="$MAGISKTMP/config $PROPPATH"
|
[ ! -z $MAGISKTMP ] && PROPPATH="$MAGISKTMP/.magisk/config $PROPPATH"
|
||||||
VALUE=$(grep_prop $VARNAME $PROPPATH)
|
VALUE=$(grep_prop $VARNAME $PROPPATH)
|
||||||
[ ! -z $VALUE ] && eval $VARNAME=\$VALUE
|
[ ! -z $VALUE ] && eval $VARNAME=\$VALUE
|
||||||
}
|
}
|
||||||
@ -629,7 +629,7 @@ run_migrations() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_rules() {
|
copy_preinit_files() {
|
||||||
local RULESDIR=$(magisk --path)/.magisk/rules
|
local RULESDIR=$(magisk --path)/.magisk/rules
|
||||||
if ! grep -q " $RULESDIR " /proc/mounts; then
|
if ! grep -q " $RULESDIR " /proc/mounts; then
|
||||||
ui_print "- Unable to find rules dir"
|
ui_print "- Unable to find rules dir"
|
||||||
@ -785,10 +785,10 @@ install_module() {
|
|||||||
cp -af $MODPATH/module.prop $NVBASE/modules/$MODID/module.prop
|
cp -af $MODPATH/module.prop $NVBASE/modules/$MODID/module.prop
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Copy over custom rules
|
# Copy over custom sepolicy rules
|
||||||
if [ -f $MODPATH/sepolicy.rule ]; then
|
if [ -f $MODPATH/sepolicy.rule ]; then
|
||||||
ui_print "- Installing custom sepolicy rules"
|
ui_print "- Installing custom sepolicy rules"
|
||||||
copy_rules
|
copy_preinit_files
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Remove stuff that doesn't belong to modules and clean up any empty directories
|
# Remove stuff that doesn't belong to modules and clean up any empty directories
|
||||||
|
Loading…
Reference in New Issue
Block a user