Migrate PREINITDEVICE in recovery mode

Close #6917
This commit is contained in:
topjohnwu
2023-06-02 16:49:04 -07:00
parent 7eebe62bb6
commit feb44f875e
7 changed files with 23 additions and 44 deletions

View File

@@ -76,7 +76,7 @@ void cpio::rm(const char *name, bool r) {
}
}
void cpio::extract_entry(const entry_map::value_type &e, const char *file) {
static void extract_entry(const cpio::entry_map::value_type &e, const char *file) {
fprintf(stderr, "Extract [%s] to [%s]\n", e.first.data(), file);
unlink(file);
rmdir(file);

View File

@@ -44,7 +44,6 @@ public:
protected:
entry_map entries;
static void extract_entry(const entry_map::value_type &e, const char *file);
void rm(entry_map::iterator it);
void mv(entry_map::iterator it, const char *name);

View File

@@ -85,8 +85,6 @@ Supported actions:
Create ramdisk backups from ORIG
restore
Restore ramdisk from ramdisk backup stored within incpio
sha1
Print stock boot SHA1 if previously backed up in ramdisk
dtb <file> <action> [args...]
Do dtb related actions to <file>

View File

@@ -18,7 +18,6 @@ class magisk_cpio : public cpio {
public:
void patch();
int test();
char *sha1();
void restore();
void backup(const char *orig);
};
@@ -81,35 +80,6 @@ int magisk_cpio::test() {
return ret;
}
#define for_each_line(line, buf, size) \
for (char *line = (char *) buf; line < (char *) buf + size && line[0]; line = strchr(line + 1, '\n') + 1)
char *magisk_cpio::sha1() {
char sha1[41];
for (auto &e : entries) {
if (e.first == "init.magisk.rc" || e.first == "overlay/init.magisk.rc") {
for_each_line(line, e.second->data, e.second->filesize) {
if (strncmp(line, "#STOCKSHA1=", 11) == 0) {
strncpy(sha1, line + 12, 40);
sha1[40] = '\0';
return strdup(sha1);
}
}
} else if (e.first == ".backup/.magisk") {
for_each_line(line, e.second->data, e.second->filesize) {
if (str_starts(line, "SHA1=")) {
strncpy(sha1, line + 5, 40);
sha1[40] = '\0';
return strdup(sha1);
}
}
} else if (e.first == ".backup/.sha1") {
return (char *) e.second->data;
}
}
return nullptr;
}
#define for_each_str(str, buf, size) \
for (char *str = (char *) buf; str < (char *) buf + size; str += strlen(str) + 1)
@@ -263,10 +233,6 @@ int cpio_commands(int argc, char *argv[]) {
exit(cpio.test());
} else if (cmdv[0] == "restore"sv) {
cpio.restore();
} else if (cmdv[0] == "sha1"sv) {
char *sha1 = cpio.sha1();
if (sha1) printf("%s\n", sha1);
return 0;
} else if (cmdv[0] == "patch"sv) {
cpio.patch();
} else if (cmdc == 2 && cmdv[0] == "exists"sv) {