mirror of
https://github.com/topjohnwu/Magisk
synced 2024-11-13 20:54:12 +01:00
Change MagiskBoot patch behavior
Use environment variables to toggle configurations for patching ramdisk
This commit is contained in:
parent
4d91e50d6d
commit
a1ccd44013
@ -61,8 +61,9 @@ Supported actions:
|
|||||||
Test the current cpio's patch status
|
Test the current cpio's patch status
|
||||||
Return values:
|
Return values:
|
||||||
0:stock 1:Magisk 2:unsupported (phh, SuperSU, Xposed)
|
0:stock 1:Magisk 2:unsupported (phh, SuperSU, Xposed)
|
||||||
patch KEEPVERITY KEEPFORCEENCRYPT
|
patch
|
||||||
Ramdisk patches. KEEP**** are boolean values
|
Apply ramdisk patches. Configure settings with env variables:
|
||||||
|
KEEPVERITY KEEPFORCEENCRYPT
|
||||||
backup ORIG
|
backup ORIG
|
||||||
Create ramdisk backups from ORIG
|
Create ramdisk backups from ORIG
|
||||||
restore
|
restore
|
||||||
|
@ -24,7 +24,7 @@ class magisk_cpio : public cpio_rw {
|
|||||||
public:
|
public:
|
||||||
magisk_cpio() = default;
|
magisk_cpio() = default;
|
||||||
explicit magisk_cpio(const char *filename) : cpio_rw(filename) {}
|
explicit magisk_cpio(const char *filename) : cpio_rw(filename) {}
|
||||||
void patch(bool keepverity, bool keepforceencrypt);
|
void patch();
|
||||||
int test();
|
int test();
|
||||||
char *sha1();
|
char *sha1();
|
||||||
void restore();
|
void restore();
|
||||||
@ -33,9 +33,17 @@ public:
|
|||||||
void decompress();
|
void decompress();
|
||||||
};
|
};
|
||||||
|
|
||||||
void magisk_cpio::patch(bool keepverity, bool keepforceencrypt) {
|
static bool check_env(const char *name) {
|
||||||
|
const char *val = getenv(name);
|
||||||
|
return val ? strcmp(val, "true") == 0 : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void magisk_cpio::patch() {
|
||||||
|
bool keepverity = check_env("KEEPVERITY");
|
||||||
|
bool keepforceencrypt = check_env("KEEPFORCEENCRYPT");
|
||||||
fprintf(stderr, "Patch with flag KEEPVERITY=[%s] KEEPFORCEENCRYPT=[%s]\n",
|
fprintf(stderr, "Patch with flag KEEPVERITY=[%s] KEEPFORCEENCRYPT=[%s]\n",
|
||||||
keepverity ? "true" : "false", keepforceencrypt ? "true" : "false");
|
keepverity ? "true" : "false", keepforceencrypt ? "true" : "false");
|
||||||
|
|
||||||
auto next = entries.begin();
|
auto next = entries.begin();
|
||||||
decltype(next) cur;
|
decltype(next) cur;
|
||||||
while (next != entries.end()) {
|
while (next != entries.end()) {
|
||||||
@ -46,9 +54,12 @@ void magisk_cpio::patch(bool keepverity, bool keepforceencrypt) {
|
|||||||
str_contains(cur->first, "fstab") && S_ISREG(cur->second->mode);
|
str_contains(cur->first, "fstab") && S_ISREG(cur->second->mode);
|
||||||
if (!keepverity) {
|
if (!keepverity) {
|
||||||
if (fstab) {
|
if (fstab) {
|
||||||
|
fprintf(stderr, "Found fstab file [%s]\n", cur->first.data());
|
||||||
auto buf = patch_verity(cur->second->data, cur->second->filesize);
|
auto buf = patch_verity(cur->second->data, cur->second->filesize);
|
||||||
free(cur->second->data);
|
if (buf) {
|
||||||
cur->second->data = buf;
|
free(cur->second->data);
|
||||||
|
cur->second->data = buf;
|
||||||
|
}
|
||||||
} else if (cur->first == "verity_key") {
|
} else if (cur->first == "verity_key") {
|
||||||
rm(cur);
|
rm(cur);
|
||||||
continue;
|
continue;
|
||||||
@ -293,6 +304,8 @@ int cpio_commands(int argc, char *argv[]) {
|
|||||||
cpio.compress();
|
cpio.compress();
|
||||||
} else if (strcmp(cmdv[0], "decompress") == 0){
|
} else if (strcmp(cmdv[0], "decompress") == 0){
|
||||||
cpio.decompress();
|
cpio.decompress();
|
||||||
|
} else if (strcmp(cmdv[0], "patch") == 0) {
|
||||||
|
cpio.patch();
|
||||||
} else if (cmdc == 2 && strcmp(cmdv[0], "exists") == 0) {
|
} else if (cmdc == 2 && strcmp(cmdv[0], "exists") == 0) {
|
||||||
exit(!cpio.exists(cmdv[1]));
|
exit(!cpio.exists(cmdv[1]));
|
||||||
} else if (cmdc == 2 && strcmp(cmdv[0], "backup") == 0) {
|
} else if (cmdc == 2 && strcmp(cmdv[0], "backup") == 0) {
|
||||||
@ -302,8 +315,6 @@ int cpio_commands(int argc, char *argv[]) {
|
|||||||
cpio.rm(cmdv[1 + r], r);
|
cpio.rm(cmdv[1 + r], r);
|
||||||
} else if (cmdc == 3 && strcmp(cmdv[0], "mv") == 0) {
|
} else if (cmdc == 3 && strcmp(cmdv[0], "mv") == 0) {
|
||||||
cpio.mv(cmdv[1], cmdv[2]);
|
cpio.mv(cmdv[1], cmdv[2]);
|
||||||
} else if (cmdc == 3 && strcmp(cmdv[0], "patch") == 0) {
|
|
||||||
cpio.patch(strcmp(cmdv[1], "true") == 0, strcmp(cmdv[2], "true") == 0);
|
|
||||||
} else if (strcmp(cmdv[0], "extract") == 0) {
|
} else if (strcmp(cmdv[0], "extract") == 0) {
|
||||||
if (cmdc == 3) {
|
if (cmdc == 3) {
|
||||||
return !cpio.extract(cmdv[1], cmdv[2]);
|
return !cpio.extract(cmdv[1], cmdv[2]);
|
||||||
|
@ -59,6 +59,8 @@ BOOTIMAGE="$1"
|
|||||||
[ -z $KEEPVERITY ] && KEEPVERITY=false
|
[ -z $KEEPVERITY ] && KEEPVERITY=false
|
||||||
[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false
|
[ -z $KEEPFORCEENCRYPT ] && KEEPFORCEENCRYPT=false
|
||||||
[ -z $RECOVERYMODE ] && RECOVERYMODE=false
|
[ -z $RECOVERYMODE ] && RECOVERYMODE=false
|
||||||
|
export KEEPVERITY
|
||||||
|
export KEEPFORCEENCRYPT
|
||||||
|
|
||||||
chmod -R 755 .
|
chmod -R 755 .
|
||||||
|
|
||||||
@ -140,7 +142,7 @@ echo "RECOVERYMODE=$RECOVERYMODE" >> config
|
|||||||
|
|
||||||
./magiskboot cpio ramdisk.cpio \
|
./magiskboot cpio ramdisk.cpio \
|
||||||
"add 750 init magiskinit" \
|
"add 750 init magiskinit" \
|
||||||
"patch $KEEPVERITY $KEEPFORCEENCRYPT" \
|
"patch" \
|
||||||
"backup ramdisk.cpio.orig" \
|
"backup ramdisk.cpio.orig" \
|
||||||
"mkdir 000 .backup" \
|
"mkdir 000 .backup" \
|
||||||
"add 000 .backup/.magisk config"
|
"add 000 .backup/.magisk config"
|
||||||
|
Loading…
Reference in New Issue
Block a user