mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 13:35:27 +00:00
Cleanup magiskinit code
This commit is contained in:
parent
2e299b3814
commit
50710c72ad
@ -15,57 +15,58 @@ vector<string> mount_list;
|
|||||||
|
|
||||||
template<char... cs> using chars = integer_sequence<char, cs...>;
|
template<char... cs> using chars = integer_sequence<char, cs...>;
|
||||||
|
|
||||||
|
// If quoted, parsing ends when we find char in [breaks]
|
||||||
|
// If not quoted, parsing ends when we find char in [breaks] + [escapes]
|
||||||
template<char... escapes, char... breaks>
|
template<char... escapes, char... breaks>
|
||||||
static string extract_qutoed_str_until(chars<escapes...>, chars<breaks...>,
|
static string extract_quoted_str_until(chars<escapes...>, chars<breaks...>,
|
||||||
string_view sv, size_t &begin, bool "ed) {
|
string_view str, size_t &pos, bool "ed) {
|
||||||
string result;
|
string result;
|
||||||
char match_array[] = {escapes..., breaks..., '"'};
|
char match_array[] = {escapes..., breaks..., '"'};
|
||||||
string_view match(match_array, sizeof(match_array));
|
string_view match(match_array, std::size(match_array));
|
||||||
for (auto end = begin;; ++end) {
|
for (size_t cur = pos;; ++cur) {
|
||||||
end = sv.find_first_of(match, end);
|
cur = str.find_first_of(match, cur);
|
||||||
if (end == string_view::npos || ((sv[end] == breaks) || ...) ||
|
if (cur == string_view::npos ||
|
||||||
(!quoted && ((sv[end] == escapes) || ...))) {
|
((str[cur] == breaks) || ...) ||
|
||||||
result.append(sv.substr(begin, end - begin));
|
(!quoted && ((str[cur] == escapes) || ...))) {
|
||||||
begin = end;
|
result.append(str.substr(pos, cur - pos));
|
||||||
|
pos = cur;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (sv[end] == '"') {
|
if (str[cur] == '"') {
|
||||||
quoted = !quoted;
|
quoted = !quoted;
|
||||||
result.append(sv.substr(begin, end - begin));
|
result.append(str.substr(pos, cur - pos));
|
||||||
begin = end + 1;
|
pos = cur + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//[pair_split][key][assign_split][assign][assign_split][value][pair_split]
|
// Parse string into key value pairs.
|
||||||
template<char... pair_spilt, char... assign, char... assign_split>
|
// The string format: [delim][key][padding]=[padding][value][delim]
|
||||||
static auto parse(chars<pair_spilt...>, chars<assign...>, chars<assign_split...>, string_view sv) {
|
template<char delim, char... padding>
|
||||||
vector<pair<string, string>> kv;
|
static kv_pairs parse_impl(chars<padding...>, string_view str) {
|
||||||
char next_array[] = {pair_spilt...};
|
kv_pairs kv;
|
||||||
string_view next(next_array, sizeof(next_array));
|
char skip_array[] = {'=', padding...};
|
||||||
char skip_array[] = {assign..., assign_split...};
|
string_view skip(skip_array, std::size(skip_array));
|
||||||
string_view skip(skip_array, sizeof(skip_array));
|
|
||||||
bool quoted = false;
|
bool quoted = false;
|
||||||
for (size_t cur = 0u; cur < sv.size();
|
for (size_t pos = 0u; pos < str.size(); pos = str.find_first_not_of(delim, pos)) {
|
||||||
cur = sv.find_first_not_of(next, cur)) {
|
auto key = extract_quoted_str_until(
|
||||||
auto key = extract_qutoed_str_until(chars<assign_split..., pair_spilt...>{},
|
chars<padding..., delim>{}, chars<'='>{}, str, pos, quoted);
|
||||||
chars<assign...>{}, sv, cur, quoted);
|
pos = str.find_first_not_of(skip, pos);
|
||||||
cur = sv.find_first_not_of(skip, cur);
|
if (pos == string_view::npos || str[pos] == delim) {
|
||||||
if (((cur == string_view::npos) || ... || (sv[cur] == pair_spilt))) {
|
|
||||||
kv.emplace_back(key, "");
|
kv.emplace_back(key, "");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto value = extract_qutoed_str_until(chars<pair_spilt...>{}, chars<>{}, sv, cur, quoted);
|
auto value = extract_quoted_str_until(chars<delim>{}, chars<>{}, str, pos, quoted);
|
||||||
kv.emplace_back(key, value);
|
kv.emplace_back(key, value);
|
||||||
}
|
}
|
||||||
return kv;
|
return kv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto parse_cmdline(string_view sv) {
|
static kv_pairs parse_cmdline(string_view str) {
|
||||||
return parse(chars<' '>{}, chars<'='>{}, chars<>{}, sv);
|
return parse_impl<' '>(chars<>{}, str);
|
||||||
}
|
}
|
||||||
static auto parse_bootconfig(string_view sv) {
|
static kv_pairs parse_bootconfig(string_view str) {
|
||||||
return parse(chars<'\n'>{}, chars<'='>{}, chars<' '>{}, sv);
|
return parse_impl<'\n'>(chars<' '>{}, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define test_bit(bit, array) (array[bit / 8] & (1 << (bit % 8)))
|
#define test_bit(bit, array) (array[bit / 8] & (1 << (bit % 8)))
|
||||||
@ -158,17 +159,54 @@ void setup_klog() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BootConfig::set(const kv_pairs &kv) {
|
||||||
|
for (const auto &[key, value] : kv) {
|
||||||
|
if (key == "androidboot.slot_suffix") {
|
||||||
|
strlcpy(slot, value.data(), sizeof(slot));
|
||||||
|
} else if (key == "androidboot.slot") {
|
||||||
|
slot[0] = '_';
|
||||||
|
strlcpy(slot + 1, value.data(), sizeof(slot) - 1);
|
||||||
|
} else if (key == "skip_initramfs") {
|
||||||
|
skip_initramfs = true;
|
||||||
|
} else if (key == "androidboot.force_normal_boot") {
|
||||||
|
force_normal_boot = !value.empty() && value[0] == '1';
|
||||||
|
} else if (key == "rootwait") {
|
||||||
|
rootwait = true;
|
||||||
|
} else if (key == "androidboot.android_dt_dir") {
|
||||||
|
strlcpy(dt_dir, value.data(), sizeof(dt_dir));
|
||||||
|
} else if (key == "androidboot.hardware") {
|
||||||
|
strlcpy(hardware, value.data(), sizeof(hardware));
|
||||||
|
} else if (key == "androidboot.hardware.platform") {
|
||||||
|
strlcpy(hardware_plat, value.data(), sizeof(hardware_plat));
|
||||||
|
} else if (key == "androidboot.fstab_suffix") {
|
||||||
|
strlcpy(fstab_suffix, value.data(), sizeof(fstab_suffix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BootConfig::print() {
|
||||||
|
LOGD("skip_initramfs=[%d]\n", skip_initramfs);
|
||||||
|
LOGD("force_normal_boot=[%d]\n", force_normal_boot);
|
||||||
|
LOGD("rootwait=[%d]\n", rootwait);
|
||||||
|
LOGD("slot=[%s]\n", slot);
|
||||||
|
LOGD("dt_dir=[%s]\n", dt_dir);
|
||||||
|
LOGD("fstab_suffix=[%s]\n", fstab_suffix);
|
||||||
|
LOGD("hardware=[%s]\n", hardware);
|
||||||
|
LOGD("hardware.platform=[%s]\n", hardware_plat);
|
||||||
|
}
|
||||||
|
|
||||||
#define read_dt(name, key) \
|
#define read_dt(name, key) \
|
||||||
sprintf(file_name, "%s/" name, cmd->dt_dir); \
|
snprintf(file_name, sizeof(file_name), "%s/" name, config->key); \
|
||||||
if (access(file_name, R_OK) == 0){ \
|
if (access(file_name, R_OK) == 0) { \
|
||||||
string data = full_read(file_name); \
|
string data = full_read(file_name); \
|
||||||
if (!data.empty()) { \
|
if (!data.empty()) { \
|
||||||
data.pop_back(); \
|
data.pop_back(); \
|
||||||
strcpy(cmd->key, data.data()); \
|
LOGD(name "=[%s]\n", data.data()); \
|
||||||
|
strlcpy(config->key, data.data(), sizeof(config->key)); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_kernel_info(cmdline *cmd) {
|
void load_kernel_info(BootConfig *config) {
|
||||||
// Get kernel data using procfs and sysfs
|
// Get kernel data using procfs and sysfs
|
||||||
xmkdir("/proc", 0755);
|
xmkdir("/proc", 0755);
|
||||||
xmount("proc", "/proc", "proc", 0, nullptr);
|
xmount("proc", "/proc", "proc", 0, nullptr);
|
||||||
@ -181,85 +219,31 @@ void load_kernel_info(cmdline *cmd) {
|
|||||||
// Log to kernel
|
// Log to kernel
|
||||||
setup_klog();
|
setup_klog();
|
||||||
|
|
||||||
for (const auto&[key, value] : parse_cmdline(full_read("/proc/cmdline"))) {
|
config->set(parse_cmdline(full_read("/proc/cmdline")));
|
||||||
if (key == "androidboot.slot_suffix") {
|
|
||||||
strcpy(cmd->slot, value.data());
|
|
||||||
} else if (key == "androidboot.slot") {
|
|
||||||
cmd->slot[0] = '_';
|
|
||||||
strcpy(cmd->slot + 1, value.data());
|
|
||||||
} else if (key == "skip_initramfs") {
|
|
||||||
cmd->skip_initramfs = true;
|
|
||||||
} else if (key == "androidboot.force_normal_boot") {
|
|
||||||
cmd->force_normal_boot = value[0] == '1';
|
|
||||||
} else if (key == "rootwait") {
|
|
||||||
cmd->rootwait = true;
|
|
||||||
} else if (key == "androidboot.android_dt_dir") {
|
|
||||||
strcpy(cmd->dt_dir, value.data());
|
|
||||||
} else if (key == "androidboot.hardware") {
|
|
||||||
strcpy(cmd->hardware, value.data());
|
|
||||||
} else if (key == "androidboot.hardware.platform") {
|
|
||||||
strcpy(cmd->hardware_plat, value.data());
|
|
||||||
} else if (key == "androidboot.fstab_suffix") {
|
|
||||||
strcpy(cmd->fstab_suffix, value.data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGD("Kernel cmdline info:\n");
|
LOGD("Kernel cmdline info:\n");
|
||||||
LOGD("skip_initramfs=[%d]\n", cmd->skip_initramfs);
|
config->print();
|
||||||
LOGD("force_normal_boot=[%d]\n", cmd->force_normal_boot);
|
|
||||||
LOGD("rootwait=[%d]\n", cmd->rootwait);
|
|
||||||
LOGD("slot=[%s]\n", cmd->slot);
|
|
||||||
LOGD("dt_dir=[%s]\n", cmd->dt_dir);
|
|
||||||
LOGD("fstab_suffix=[%s]\n", cmd->fstab_suffix);
|
|
||||||
LOGD("hardware=[%s]\n", cmd->hardware);
|
|
||||||
LOGD("hardware.platform=[%s]\n", cmd->hardware_plat);
|
|
||||||
|
|
||||||
for (const auto&[key, value] : parse_bootconfig(full_read("/proc/bootconfig"))) {
|
|
||||||
if (key == "androidboot.slot_suffix") {
|
|
||||||
strcpy(cmd->slot, value.data());
|
|
||||||
} else if (key == "androidboot.force_normal_boot") {
|
|
||||||
cmd->force_normal_boot = value[0] == '1';
|
|
||||||
} else if (key == "androidboot.android_dt_dir") {
|
|
||||||
strcpy(cmd->dt_dir, value.data());
|
|
||||||
} else if (key == "androidboot.hardware") {
|
|
||||||
strcpy(cmd->hardware, value.data());
|
|
||||||
} else if (key == "androidboot.hardware.platform") {
|
|
||||||
strcpy(cmd->hardware_plat, value.data());
|
|
||||||
} else if (key == "androidboot.fstab_suffix") {
|
|
||||||
strcpy(cmd->fstab_suffix, value.data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
config->set(parse_bootconfig(full_read("/proc/bootconfig")));
|
||||||
LOGD("Boot config info:\n");
|
LOGD("Boot config info:\n");
|
||||||
LOGD("force_normal_boot=[%d]\n", cmd->force_normal_boot);
|
config->print();
|
||||||
LOGD("slot=[%s]\n", cmd->slot);
|
|
||||||
LOGD("dt_dir=[%s]\n", cmd->dt_dir);
|
|
||||||
LOGD("fstab_suffix=[%s]\n", cmd->fstab_suffix);
|
|
||||||
LOGD("hardware=[%s]\n", cmd->hardware);
|
|
||||||
LOGD("hardware.platform=[%s]\n", cmd->hardware_plat);
|
|
||||||
|
|
||||||
parse_prop_file("/.backup/.magisk", [=](auto key, auto value) -> bool {
|
parse_prop_file("/.backup/.magisk", [=](auto key, auto value) -> bool {
|
||||||
if (key == "RECOVERYMODE" && value == "true") {
|
if (key == "RECOVERYMODE" && value == "true") {
|
||||||
LOGD("Running in recovery mode, waiting for key...\n");
|
LOGD("Running in recovery mode, waiting for key...\n");
|
||||||
cmd->skip_initramfs = !check_key_combo();
|
config->skip_initramfs = !check_key_combo();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (cmd->dt_dir[0] == '\0')
|
if (config->dt_dir[0] == '\0')
|
||||||
strcpy(cmd->dt_dir, DEFAULT_DT_DIR);
|
strlcpy(config->dt_dir, DEFAULT_DT_DIR, sizeof(config->dt_dir));
|
||||||
|
|
||||||
|
LOGD("Device tree:\n");
|
||||||
char file_name[128];
|
char file_name[128];
|
||||||
read_dt("fstab_suffix", fstab_suffix)
|
read_dt("fstab_suffix", fstab_suffix)
|
||||||
read_dt("hardware", hardware)
|
read_dt("hardware", hardware)
|
||||||
read_dt("hardware.platform", hardware_plat)
|
read_dt("hardware.platform", hardware_plat)
|
||||||
|
|
||||||
LOGD("Device tree info:\n");
|
|
||||||
LOGD("dt_dir=[%s]\n", cmd->dt_dir);
|
|
||||||
LOGD("fstab_suffix=[%s]\n", cmd->fstab_suffix);
|
|
||||||
LOGD("hardware=[%s]\n", cmd->hardware);
|
|
||||||
LOGD("hardware.platform=[%s]\n", cmd->hardware_plat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_two_stage() {
|
bool check_two_stage() {
|
||||||
|
@ -56,7 +56,7 @@ static int dump_manager(const char *path, mode_t mode) {
|
|||||||
|
|
||||||
class RecoveryInit : public BaseInit {
|
class RecoveryInit : public BaseInit {
|
||||||
public:
|
public:
|
||||||
RecoveryInit(char *argv[], cmdline *cmd) : BaseInit(argv, cmd) {}
|
RecoveryInit(char *argv[], BootConfig *cmd) : BaseInit(argv, cmd) {}
|
||||||
void start() override {
|
void start() override {
|
||||||
LOGD("Ramdisk is recovery, abort\n");
|
LOGD("Ramdisk is recovery, abort\n");
|
||||||
rename("/.backup/init", "/init");
|
rename("/.backup/init", "/init");
|
||||||
@ -141,25 +141,25 @@ int main(int argc, char *argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
BaseInit *init;
|
BaseInit *init;
|
||||||
cmdline cmd{};
|
BootConfig config{};
|
||||||
|
|
||||||
if (argc > 1 && argv[1] == "selinux_setup"sv) {
|
if (argc > 1 && argv[1] == "selinux_setup"sv) {
|
||||||
setup_klog();
|
setup_klog();
|
||||||
init = new SecondStageInit(argv);
|
init = new SecondStageInit(argv);
|
||||||
} else {
|
} else {
|
||||||
// This will also mount /sys and /proc
|
// This will also mount /sys and /proc
|
||||||
load_kernel_info(&cmd);
|
load_kernel_info(&config);
|
||||||
|
|
||||||
if (cmd.skip_initramfs)
|
if (config.skip_initramfs)
|
||||||
init = new SARInit(argv, &cmd);
|
init = new SARInit(argv, &config);
|
||||||
else if (cmd.force_normal_boot)
|
else if (config.force_normal_boot)
|
||||||
init = new FirstStageInit(argv, &cmd);
|
init = new FirstStageInit(argv, &config);
|
||||||
else if (access("/sbin/recovery", F_OK) == 0 || access("/system/bin/recovery", F_OK) == 0)
|
else if (access("/sbin/recovery", F_OK) == 0 || access("/system/bin/recovery", F_OK) == 0)
|
||||||
init = new RecoveryInit(argv, &cmd);
|
init = new RecoveryInit(argv, &config);
|
||||||
else if (check_two_stage())
|
else if (check_two_stage())
|
||||||
init = new FirstStageInit(argv, &cmd);
|
init = new FirstStageInit(argv, &config);
|
||||||
else
|
else
|
||||||
init = new RootFSInit(argv, &cmd);
|
init = new RootFSInit(argv, &config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the main routine
|
// Run the main routine
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#include "raw_data.hpp"
|
#include "raw_data.hpp"
|
||||||
|
|
||||||
struct cmdline {
|
using kv_pairs = std::vector<std::pair<std::string, std::string>>;
|
||||||
|
|
||||||
|
struct BootConfig {
|
||||||
bool skip_initramfs;
|
bool skip_initramfs;
|
||||||
bool force_normal_boot;
|
bool force_normal_boot;
|
||||||
bool rootwait;
|
bool rootwait;
|
||||||
@ -11,6 +13,9 @@ struct cmdline {
|
|||||||
char fstab_suffix[32];
|
char fstab_suffix[32];
|
||||||
char hardware[32];
|
char hardware[32];
|
||||||
char hardware_plat[32];
|
char hardware_plat[32];
|
||||||
|
|
||||||
|
void set(const kv_pairs &);
|
||||||
|
void print();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct fstab_entry {
|
struct fstab_entry {
|
||||||
@ -32,7 +37,7 @@ struct fstab_entry {
|
|||||||
extern std::vector<std::string> mount_list;
|
extern std::vector<std::string> mount_list;
|
||||||
|
|
||||||
bool unxz(int fd, const uint8_t *buf, size_t size);
|
bool unxz(int fd, const uint8_t *buf, size_t size);
|
||||||
void load_kernel_info(cmdline *cmd);
|
void load_kernel_info(BootConfig *config);
|
||||||
bool check_two_stage();
|
bool check_two_stage();
|
||||||
void setup_klog();
|
void setup_klog();
|
||||||
|
|
||||||
@ -42,13 +47,13 @@ void setup_klog();
|
|||||||
|
|
||||||
class BaseInit {
|
class BaseInit {
|
||||||
protected:
|
protected:
|
||||||
cmdline *cmd = nullptr;
|
BootConfig *config = nullptr;
|
||||||
char **argv = nullptr;
|
char **argv = nullptr;
|
||||||
|
|
||||||
[[noreturn]] void exec_init();
|
[[noreturn]] void exec_init();
|
||||||
void read_dt_fstab(std::vector<fstab_entry> &fstab);
|
void read_dt_fstab(std::vector<fstab_entry> &fstab);
|
||||||
public:
|
public:
|
||||||
BaseInit(char *argv[], cmdline *cmd) : cmd(cmd), argv(argv) {}
|
BaseInit(char *argv[], BootConfig *config) : config(config), argv(argv) {}
|
||||||
virtual ~BaseInit() = default;
|
virtual ~BaseInit() = default;
|
||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
};
|
};
|
||||||
@ -56,7 +61,7 @@ public:
|
|||||||
class MagiskInit : public BaseInit {
|
class MagiskInit : public BaseInit {
|
||||||
protected:
|
protected:
|
||||||
mmap_data self;
|
mmap_data self;
|
||||||
mmap_data config;
|
mmap_data magisk_config;
|
||||||
std::string custom_rules_dir;
|
std::string custom_rules_dir;
|
||||||
|
|
||||||
void mount_with_dt();
|
void mount_with_dt();
|
||||||
@ -64,7 +69,7 @@ protected:
|
|||||||
void setup_tmp(const char *path);
|
void setup_tmp(const char *path);
|
||||||
void mount_rules_dir(const char *dev_base, const char *mnt_base);
|
void mount_rules_dir(const char *dev_base, const char *mnt_base);
|
||||||
public:
|
public:
|
||||||
MagiskInit(char *argv[], cmdline *cmd) : BaseInit(argv, cmd) {}
|
MagiskInit(char *argv[], BootConfig *cmd) : BaseInit(argv, cmd) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SARBase : virtual public MagiskInit {
|
class SARBase : virtual public MagiskInit {
|
||||||
@ -86,7 +91,7 @@ class FirstStageInit : public BaseInit {
|
|||||||
private:
|
private:
|
||||||
void prepare();
|
void prepare();
|
||||||
public:
|
public:
|
||||||
FirstStageInit(char *argv[], cmdline *cmd) : BaseInit(argv, cmd) {
|
FirstStageInit(char *argv[], BootConfig *cmd) : BaseInit(argv, cmd) {
|
||||||
LOGD("%s\n", __FUNCTION__);
|
LOGD("%s\n", __FUNCTION__);
|
||||||
};
|
};
|
||||||
void start() override {
|
void start() override {
|
||||||
@ -106,7 +111,7 @@ private:
|
|||||||
void early_mount();
|
void early_mount();
|
||||||
void first_stage_prep();
|
void first_stage_prep();
|
||||||
public:
|
public:
|
||||||
SARInit(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd), is_two_stage(false) {
|
SARInit(char *argv[], BootConfig *cmd) : MagiskInit(argv, cmd), is_two_stage(false) {
|
||||||
LOGD("%s\n", __FUNCTION__);
|
LOGD("%s\n", __FUNCTION__);
|
||||||
};
|
};
|
||||||
void start() override {
|
void start() override {
|
||||||
@ -136,7 +141,7 @@ private:
|
|||||||
void early_mount();
|
void early_mount();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RootFSInit(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) {
|
RootFSInit(char *argv[], BootConfig *cmd) : MagiskInit(argv, cmd) {
|
||||||
LOGD("%s\n", __FUNCTION__);
|
LOGD("%s\n", __FUNCTION__);
|
||||||
}
|
}
|
||||||
void start() override {
|
void start() override {
|
||||||
|
@ -105,12 +105,12 @@ if (access(#val, F_OK) == 0) {\
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseInit::read_dt_fstab(vector<fstab_entry> &fstab) {
|
void BaseInit::read_dt_fstab(vector<fstab_entry> &fstab) {
|
||||||
if (access(cmd->dt_dir, F_OK) != 0)
|
if (access(config->dt_dir, F_OK) != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char cwd[128];
|
char cwd[128];
|
||||||
getcwd(cwd, sizeof(cwd));
|
getcwd(cwd, sizeof(cwd));
|
||||||
chdir(cmd->dt_dir);
|
chdir(config->dt_dir);
|
||||||
run_finally cd([&]{ chdir(cwd); });
|
run_finally cd([&]{ chdir(cwd); });
|
||||||
|
|
||||||
if (access("fstab", F_OK) != 0)
|
if (access("fstab", F_OK) != 0)
|
||||||
@ -159,7 +159,7 @@ void MagiskInit::mount_with_dt() {
|
|||||||
if (is_lnk(entry.mnt_point.data()))
|
if (is_lnk(entry.mnt_point.data()))
|
||||||
continue;
|
continue;
|
||||||
// Derive partname from dev
|
// Derive partname from dev
|
||||||
sprintf(blk_info.partname, "%s%s", basename(entry.dev.data()), cmd->slot);
|
sprintf(blk_info.partname, "%s%s", basename(entry.dev.data()), config->slot);
|
||||||
setup_block(true);
|
setup_block(true);
|
||||||
xmkdir(entry.mnt_point.data(), 0755);
|
xmkdir(entry.mnt_point.data(), 0755);
|
||||||
xmount(blk_info.block_dev, entry.mnt_point.data(), entry.type.data(), MS_RDONLY, nullptr);
|
xmount(blk_info.block_dev, entry.mnt_point.data(), entry.type.data(), MS_RDONLY, nullptr);
|
||||||
@ -300,7 +300,7 @@ void SARBase::backup_files() {
|
|||||||
|
|
||||||
self = mmap_data::ro("/proc/self/exe");
|
self = mmap_data::ro("/proc/self/exe");
|
||||||
if (access("/.backup/.magisk", R_OK) == 0)
|
if (access("/.backup/.magisk", R_OK) == 0)
|
||||||
config = mmap_data::ro("/.backup/.magisk");
|
magisk_config = mmap_data::ro("/.backup/.magisk");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SARBase::mount_system_root() {
|
void SARBase::mount_system_root() {
|
||||||
@ -320,13 +320,13 @@ void SARBase::mount_system_root() {
|
|||||||
if (dev >= 0)
|
if (dev >= 0)
|
||||||
goto mount_root;
|
goto mount_root;
|
||||||
|
|
||||||
sprintf(blk_info.partname, "system%s", cmd->slot);
|
sprintf(blk_info.partname, "system%s", config->slot);
|
||||||
dev = setup_block(false);
|
dev = setup_block(false);
|
||||||
if (dev >= 0)
|
if (dev >= 0)
|
||||||
goto mount_root;
|
goto mount_root;
|
||||||
|
|
||||||
// Poll forever if rootwait was given in cmdline
|
// Poll forever if rootwait was given in cmdline
|
||||||
} while (cmd->rootwait);
|
} while (config->rootwait);
|
||||||
|
|
||||||
// We don't really know what to do at this point...
|
// We don't really know what to do at this point...
|
||||||
LOGE("Cannot find root partition, abort\n");
|
LOGE("Cannot find root partition, abort\n");
|
||||||
@ -396,7 +396,7 @@ void MagiskInit::setup_tmp(const char *path) {
|
|||||||
xmkdir(BLOCKDIR, 0);
|
xmkdir(BLOCKDIR, 0);
|
||||||
|
|
||||||
int fd = xopen(INTLROOT "/config", O_WRONLY | O_CREAT, 0);
|
int fd = xopen(INTLROOT "/config", O_WRONLY | O_CREAT, 0);
|
||||||
xwrite(fd, config.buf, config.sz);
|
xwrite(fd, magisk_config.buf, magisk_config.sz);
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = xopen("magiskinit", O_WRONLY | O_CREAT, 0755);
|
fd = xopen("magiskinit", O_WRONLY | O_CREAT, 0755);
|
||||||
xwrite(fd, self.buf, self.sz);
|
xwrite(fd, self.buf, self.sz);
|
||||||
|
@ -372,7 +372,7 @@ void MagiskProxy::start() {
|
|||||||
|
|
||||||
// Backup stuffs before removing them
|
// Backup stuffs before removing them
|
||||||
self = mmap_data::ro("/sbin/magisk");
|
self = mmap_data::ro("/sbin/magisk");
|
||||||
config = mmap_data::ro("/.backup/.magisk");
|
magisk_config = mmap_data::ro("/.backup/.magisk");
|
||||||
auto magisk = mmap_data::ro("/sbin/magisk32.xz");
|
auto magisk = mmap_data::ro("/sbin/magisk32.xz");
|
||||||
auto magisk64 = mmap_data::ro("/sbin/magisk64.xz");
|
auto magisk64 = mmap_data::ro("/sbin/magisk64.xz");
|
||||||
char custom_rules_dir[64];
|
char custom_rules_dir[64];
|
||||||
|
@ -57,7 +57,7 @@ static void read_fstab_file(const char *fstab_file, vector<fstab_entry> &fstab)
|
|||||||
extern uint32_t patch_verity(void *buf, uint32_t size);
|
extern uint32_t patch_verity(void *buf, uint32_t size);
|
||||||
|
|
||||||
void FirstStageInit::prepare() {
|
void FirstStageInit::prepare() {
|
||||||
if (cmd->force_normal_boot) {
|
if (config->force_normal_boot) {
|
||||||
xmkdirs(FSR "/system/bin", 0755);
|
xmkdirs(FSR "/system/bin", 0755);
|
||||||
rename("/init" /* magiskinit */, FSR "/system/bin/init");
|
rename("/init" /* magiskinit */, FSR "/system/bin/init");
|
||||||
symlink("/system/bin/init", FSR "/init");
|
symlink("/system/bin/init", FSR "/init");
|
||||||
@ -78,7 +78,7 @@ void FirstStageInit::prepare() {
|
|||||||
fstab_file[0] = '\0';
|
fstab_file[0] = '\0';
|
||||||
|
|
||||||
// Find existing fstab file
|
// Find existing fstab file
|
||||||
for (const char *suffix : { cmd->fstab_suffix, cmd->hardware, cmd->hardware_plat }) {
|
for (const char *suffix : {config->fstab_suffix, config->hardware, config->hardware_plat }) {
|
||||||
if (suffix[0] == '\0')
|
if (suffix[0] == '\0')
|
||||||
continue;
|
continue;
|
||||||
for (const char *prefix: { "odm/etc/fstab", "vendor/etc/fstab", "fstab" }) {
|
for (const char *prefix: { "odm/etc/fstab", "vendor/etc/fstab", "fstab" }) {
|
||||||
@ -111,9 +111,9 @@ exit_loop:
|
|||||||
|
|
||||||
if (fstab_file[0] == '\0') {
|
if (fstab_file[0] == '\0') {
|
||||||
const char *suffix =
|
const char *suffix =
|
||||||
cmd->fstab_suffix[0] ? cmd->fstab_suffix :
|
config->fstab_suffix[0] ? config->fstab_suffix :
|
||||||
(cmd->hardware[0] ? cmd->hardware :
|
(config->hardware[0] ? config->hardware :
|
||||||
(cmd->hardware_plat[0] ? cmd->hardware_plat : nullptr));
|
(config->hardware_plat[0] ? config->hardware_plat : nullptr));
|
||||||
if (suffix == nullptr) {
|
if (suffix == nullptr) {
|
||||||
LOGE("Cannot determine fstab suffix!\n");
|
LOGE("Cannot determine fstab suffix!\n");
|
||||||
return;
|
return;
|
||||||
@ -241,7 +241,7 @@ void SARInit::first_stage_prep() {
|
|||||||
string tmp_dir = read_string(client);
|
string tmp_dir = read_string(client);
|
||||||
chdir(tmp_dir.data());
|
chdir(tmp_dir.data());
|
||||||
int cfg = xopen(INTLROOT "/config", O_WRONLY | O_CREAT, 0);
|
int cfg = xopen(INTLROOT "/config", O_WRONLY | O_CREAT, 0);
|
||||||
xwrite(cfg, config.buf, config.sz);
|
xwrite(cfg, magisk_config.buf, magisk_config.sz);
|
||||||
close(cfg);
|
close(cfg);
|
||||||
restore_folder(ROOTOVL, overlays);
|
restore_folder(ROOTOVL, overlays);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user