Skip to content

Commit

Permalink
switch from using magisk mirror to denylist exec
Browse files Browse the repository at this point in the history
  • Loading branch information
programminghoch10 committed Nov 13, 2024
1 parent 1da6b9c commit 2df771c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
21 changes: 13 additions & 8 deletions magiskmodule/customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -74,6 +77,7 @@ patchAPK() {
packagename="$1"
apkpath="$2"
cd "$TMPDIR"
denylist_run cat "$apkpath" > app.apk

ui_print "- Patching $packagename"

Expand All @@ -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"
}
Expand Down
27 changes: 18 additions & 9 deletions magiskmodule/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" ] \
Expand All @@ -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
}
Expand Down

0 comments on commit 2df771c

Please sign in to comment.