Commit ba55e2bc authored by topjohnwu's avatar topjohnwu

Backup proper magiskinit in A-only 2SI

parent 0a2c99f1
...@@ -68,7 +68,7 @@ protected: ...@@ -68,7 +68,7 @@ protected:
raw_data config; raw_data config;
dev_t system_dev; dev_t system_dev;
void backup_files(); void backup_files(const char *self_path);
void patch_rootdir(); void patch_rootdir();
public: public:
SARBase(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) { SARBase(char *argv[], cmdline *cmd) : MagiskInit(argv, cmd) {
......
...@@ -183,11 +183,11 @@ void RootFSInit::early_mount() { ...@@ -183,11 +183,11 @@ void RootFSInit::early_mount() {
mount_list.emplace_back("/dev/mnt/cache"); mount_list.emplace_back("/dev/mnt/cache");
} }
void SARBase::backup_files() { void SARBase::backup_files(const char *self_path) {
if (access("/overlay.d", F_OK) == 0) if (access("/overlay.d", F_OK) == 0)
cp_afc("/overlay.d", "/dev/overlay.d"); cp_afc("/overlay.d", "/dev/overlay.d");
full_read("/init", self.buf, self.sz); full_read(self_path, self.buf, self.sz);
full_read("/.backup/.magisk", config.buf, config.sz); full_read("/.backup/.magisk", config.buf, config.sz);
} }
...@@ -197,7 +197,7 @@ void SARInit::early_mount() { ...@@ -197,7 +197,7 @@ void SARInit::early_mount() {
xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755"); xmount("tmpfs", "/dev", "tmpfs", 0, "mode=755");
mount_list.emplace_back("/dev"); mount_list.emplace_back("/dev");
backup_files(); backup_files("/init");
LOGD("Cleaning rootfs\n"); LOGD("Cleaning rootfs\n");
int root = xopen("/", O_RDONLY | O_CLOEXEC); int root = xopen("/", O_RDONLY | O_CLOEXEC);
...@@ -232,7 +232,7 @@ void SARInit::early_mount() { ...@@ -232,7 +232,7 @@ void SARInit::early_mount() {
void SecondStageInit::early_mount() { void SecondStageInit::early_mount() {
// Early mounts should already be done by first stage init // Early mounts should already be done by first stage init
backup_files(); backup_files("/system/bin/init");
rm_rf("/system"); rm_rf("/system");
rm_rf("/.backup"); rm_rf("/.backup");
rm_rf("/overlay.d"); rm_rf("/overlay.d");
......
...@@ -407,20 +407,24 @@ static void patch_fstab(const string &fstab) { ...@@ -407,20 +407,24 @@ static void patch_fstab(const string &fstab) {
#define FSR "/first_stage_ramdisk" #define FSR "/first_stage_ramdisk"
void ABFirstStageInit::prepare() { void ABFirstStageInit::prepare() {
auto dir = xopen_dir(FSR); // It is actually possible to NOT have FSR, create it just in case
if (!dir) xmkdir(FSR, 0755);
return;
string fstab(FSR "/"); if (auto dir = xopen_dir(FSR); dir) {
for (dirent *de; (de = xreaddir(dir.get()));) { string fstab(FSR "/");
if (strstr(de->d_name, "fstab")) { for (dirent *de; (de = xreaddir(dir.get()));) {
fstab += de->d_name; if (strstr(de->d_name, "fstab")) {
break; fstab += de->d_name;
break;
}
} }
} if (fstab.length() == sizeof(FSR))
if (fstab.length() == sizeof(FSR)) return;
return;
patch_fstab(fstab); patch_fstab(fstab);
} else {
return;
}
// Move stuffs for next stage // Move stuffs for next stage
xmkdir(FSR "/system", 0755); xmkdir(FSR "/system", 0755);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment