From 2df771c3d25e81f17855f55c66d9adfa9152afef Mon Sep 17 00:00:00 2001 From: programminghoch10 <16062290+programminghoch10@users.noreply.github.com> Date: Wed, 13 Nov 2024 22:51:01 +0100 Subject: [PATCH] switch from using magisk mirror to denylist exec --- magiskmodule/customize.sh | 21 +++++++++++++-------- magiskmodule/service.sh | 27 ++++++++++++++++++--------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/magiskmodule/customize.sh b/magiskmodule/customize.sh index ce41655..f47644d 100644 --- a/magiskmodule/customize.sh +++ b/magiskmodule/customize.sh @@ -8,21 +8,26 @@ cd "$MODPATH" [ ! -f ./version.sh ] && abort "Missing version.sh" . ./version.sh -MAGISKTMP="$(magisk --path)" || MAGISKTMP=/sbin -MIRROR="$MAGISKTMP"/.magisk/mirror -ui_print "- Found Magisk mirror at $MIRROR" - findConfigFile() { for path in /storage/emulated/0 /data/adb; do [ -f "$path/$1" ] && echo "$path/$1" && break done } +#shellcheck disable=SC2154 +[ "$MAGISK_VER_CODE" -ge 23010 ] || abort "magisk version $MAGISK_VER_CODE unsupported" +[ -n "$(command -v magisk)" ] || abort "magisk command not found" +magisk --denylist exec true || abort "magisk denylist exec failed" +denylist_run() { + magisk --denylist exec "$@" +} + BLACKLIST="$(findConfigFile revancedrepackaged-blacklist.txt)" [ -n "$BLACKLIST" ] && ui_print "- Found blacklist at $BLACKLIST" ui_print "- Preparing Patching Process" +#shellcheck disable=SC2154 [ ! -f aapt2lib/"$ARCH"/libaapt2.so ] && abort "Failed to locate libaapt2.so for $ARCH" mv -v aapt2lib/"$ARCH"/libaapt2.so aapt2 rm -r aapt2lib @@ -60,12 +65,10 @@ processPackage() { ui_print "- Found APK at $apkpath" - apkpath="$MIRROR"/"$apkpath" - patchAPK "$packagename" "$apkpath" [ ! -f overlay/"$packagename".apk ] && abort "Couldn't locate patched file!" - sha256sum < "$apkpath" > overlay/"$packagename".sha256sum + denylist_run cat "$apkpath" | sha256sum > overlay/"$packagename".sha256sum chcon u:object_r:apk_data_file:s0 overlay/"$packagename".apk } @@ -74,6 +77,7 @@ patchAPK() { packagename="$1" apkpath="$2" cd "$TMPDIR" + denylist_run cat "$apkpath" > app.apk ui_print "- Patching $packagename" @@ -98,12 +102,13 @@ patchAPK() { --include='Custom branding' \ --options=options.json \ --purge \ - "$apkpath" \ + app.apk \ 2>&1 || abort "Patching failed! $?" [ ! -f out.apk ] && abort "Patching failed!" mv -v out.apk "$MODPATH"/overlay/"$packagename".apk + rm app.apk cd "$MODPATH" } diff --git a/magiskmodule/service.sh b/magiskmodule/service.sh index c150097..6acc1f4 100644 --- a/magiskmodule/service.sh +++ b/magiskmodule/service.sh @@ -4,24 +4,32 @@ cd "$(dirname "$0")" . ./version.sh logi() { - msg="ReVancedRepackaged: $1" + msg="ReVancedRepackaged: $*" log -t Magisk "$msg" echo "$msg" >> /cache/magisk.log } +abort() { + logi "$@" + touch remove + exit 1 +} + +[ -z "$(command -v magisk)" ] && abort "magisk command not found" +magisk --denylist exec true || abort "magisk denylist exec failed" +denylist_run() { + magisk --denylist exec "$@" +} -[ -z "$(ls overlay)" ] && logi "No overlays found!" && touch remove && exit 1 +[ -z "$(ls overlay)" ] && abort "No overlays found!" while [ "$(getprop sys.boot_completed)" != "1" ]; do sleep 1 done -MAGISKTMP="$(magisk --path)" || MAGISKTMP=/sbin -MIRROR="$MAGISKTMP"/.magisk/mirror - checkHash() { packagename="$1" apkpath="$2" - [ "$(sha256sum < "$apkpath")" = "$(cat overlay/"$packagename".sha256sum)" ] && return 0 + [ "$(denylist_run cat "$apkpath" | sha256sum)" = "$(cat overlay/"$packagename".sha256sum)" ] && return 0 logi "Package $packagename has changed their base.apk! Removing their overlay, because a repatch is required." rm overlay/"$packagename".* return 1 @@ -38,8 +46,9 @@ overlayPackage() { | cut -d':' -f2) [ -z "$apkpath" ] && \ - apkpath=$(find -H \ - "$MIRROR"/data/app \ + apkpath=$(denylist_run \ + find -H \ + /data/app \ -wholename "*${packagename}*/base.apk") [ -z "$apkpath" ] \ @@ -48,7 +57,7 @@ overlayPackage() { checkHash "$packagename" "$apkpath" || return 1 - mount -o bind "$MIRROR"/"$overlayapk" "$apkpath" || { + mount -o bind "$overlayapk" "$apkpath" || { logi "Failed to mount $overlayapk on $apkpath" return 1 }