diff --git a/.gitignore b/.gitignore index 3d259af..c58c479 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ magiskmodule/README.md magiskmodule/module.prop magiskmodule/version.sh -magiskmodule/aapt2 +magiskmodule/aapt2lib +magiskmodule/packageversions +magiskmodule/supportedversions.md diff --git a/0001-Load-classes-in-dex-mode.patch b/0001-Load-classes-in-dex-mode.patch deleted file mode 100644 index fd2b0ac..0000000 --- a/0001-Load-classes-in-dex-mode.patch +++ /dev/null @@ -1,35 +0,0 @@ -From ff0b5b70d9db4816757e8261f59dc4f451afc9e1 Mon Sep 17 00:00:00 2001 -From: programminghoch10 <16062290+programminghoch10@users.noreply.github.com> -Date: Mon, 29 May 2023 15:33:36 +0200 -Subject: [PATCH] Load classes in dex mode - -Required for loading patches on android ---- - .../kotlin/app/revanced/cli/command/MainCommand.kt | 10 +++++++++- - 1 file changed, 9 insertions(+), 1 deletion(-) - -diff --git a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt -index 0d3b954..2fbaa52 100644 ---- a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt -+++ b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt -@@ -138,8 +138,16 @@ internal object MainCommand : Runnable { - val pArgs = this.args.patchArgs?.patchingArgs ?: return - val outputFile = File(pArgs.outputPath) // the file to write to - -+ val DexClassLoaderClass = Class.forName("dalvik.system.DexClassLoader") - val allPatches = args.patchArgs!!.patchBundles.flatMap { bundle -> -- PatchBundle.Jar(bundle).loadPatches() -+ PatchBundle.Dex(bundle, -+ DexClassLoaderClass.getConstructor( -+ String::class.java, -+ String::class.java, -+ String::class.java, -+ ClassLoader::class.java -+ ).newInstance(bundle, null, null, javaClass.classLoader) as ClassLoader -+ ).loadPatches() - } - - args.patchArgs!!.optionsFile.let { --- -2.39.2 - diff --git a/README.md b/README.md index 3180beb..2491111 100644 --- a/README.md +++ b/README.md @@ -7,24 +7,24 @@ contains only the ReVanced Patcher. It will patch the installed YouTube app right on your device during installation. -![GitHub Latest Release (by date)](https://img.shields.io/github/v/release/programminghoch10/ReVancedRepackaged?label=latest&logo=github&display_name=release) -![GitHub Latest Release Date](https://img.shields.io/github/release-date/programminghoch10/ReVancedRepackaged?logo=github) \ -![GitHub Global Download Counter](https://img.shields.io/github/downloads/programminghoch10/ReVancedRepackaged/total?logo=github) -![GitHub Latest Download Counter](https://img.shields.io/github/downloads/programminghoch10/ReVancedRepackaged/latest/total?logo=github) \ -![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/programminghoch10/ReVancedRepackaged/build.yml?logo=github%20actions&logoColor=white) -![GitHub commits since last release](https://img.shields.io/github/commits-since/programminghoch10/ReVancedRepackaged/latest?logo=git&logoColor=white) -![GitHub last commit](https://img.shields.io/github/last-commit/programminghoch10/ReVancedRepackaged?logo=git&logoColor=white) \ -![GitHub Repo stars](https://img.shields.io/github/stars/programminghoch10/ReVancedRepackaged?style=social) \ +[![GitHub Latest Release (by date)](https://img.shields.io/github/v/release/programminghoch10/ReVancedRepackaged?label=latest&logo=github&display_name=release)](https://github.com/programminghoch10/ReVancedRepackaged/releases/latest) +[![GitHub Latest Release Date](https://img.shields.io/github/release-date/programminghoch10/ReVancedRepackaged?logo=github)](https://github.com/programminghoch10/ReVancedRepackaged/releases/latest) \ +[![GitHub Global Download Counter](https://img.shields.io/github/downloads/programminghoch10/ReVancedRepackaged/total?logo=github)](https://github.com/programminghoch10/ReVancedRepackaged/releases) +[![GitHub Latest Download Counter](https://img.shields.io/github/downloads/programminghoch10/ReVancedRepackaged/latest/total?logo=github)](https://github.com/programminghoch10/ReVancedRepackaged/releases/latest) \ +[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/programminghoch10/ReVancedRepackaged/build.yml?logo=github%20actions&logoColor=white)](https://github.com/programminghoch10/ReVancedRepackaged/actions/workflows/build.yml) +[![GitHub commits since last release](https://img.shields.io/github/commits-since/programminghoch10/ReVancedRepackaged/latest?logo=git&logoColor=white)](https://github.com/programminghoch10/ReVancedRepackaged/compare/) +[![GitHub last commit](https://img.shields.io/github/last-commit/programminghoch10/ReVancedRepackaged?logo=git&logoColor=white)](https://github.com/programminghoch10/ReVancedRepackaged/commits/main) \ +[![GitHub Repo stars](https://img.shields.io/github/stars/programminghoch10/ReVancedRepackaged?style=social)](https://github.com/programminghoch10/ReVancedRepackaged/stargazers) \ [![GitHub followers](https://img.shields.io/github/followers/programminghoch10?style=social)](https://github.com/programminghoch10) ## Installation -1. Install the original stock YouTube app. - *Make sure you have the correct version installed before proceeding.* -1. Install the module and wait for it to patch the YouTube app. - *This might take a while.* +1. Install the original variants of the apps you want to be patched. + *Make sure you have the correct versions installed before proceeding.* +1. Install the module and wait for it to patch every compatible app. + *This will take very long.* *Please refrain from doing anything else on your device in the meantime.* -1. Go into the Google Play Store and disable automatic app updates for YouTube. +1. Go into the Google Play Store and disable automatic app updates for all patched apps. 1. Reboot ## Concept diff --git a/compile.sh b/compile.sh index dea8238..50d24e3 100755 --- a/compile.sh +++ b/compile.sh @@ -1,11 +1,15 @@ #!/bin/bash set -e +for cmd in git wget zip java; do + [ -z "$(command -v "$cmd")" ] && echo "missing $cmd" && exit 1 +done + [ -f .gitauth ] && source .gitauth [ -z "$GITHUB_ACTOR" ] && echo "missing GITHUB_ACTOR" && exit 1 [ -z "$GITHUB_TOKEN" ] && echo "missing GITHUB_TOKEN" && exit 1 -declare -x GITHUB_ACTOR GITHUB_TOKEN +declare -x GITHUB_ACTOR GITHUB_TOKEN REVANCED_INTEGRATIONS_URL="https://github.com/revanced/revanced-integrations/releases/download/v%s/revanced-integrations-%s.apk" REVANCED_PATCHES_URL="https://github.com/revanced/revanced-patches/releases/download/v%s/revanced-patches-%s.jar" @@ -25,10 +29,12 @@ executeGradle() { ( cd revanced-cli - git am ../0001-Load-classes-in-dex-mode.patch + for patch in $(ls ../revanced-cli-patches/*.patch); do + git am "$patch" + done ) -executeGradle assemble +executeGradle assemble :revancedcli:shadowJar git submodule update --checkout @@ -44,10 +50,30 @@ for dlurl in "$REVANCED_INTEGRATIONS_DL" "$REVANCED_PATCHES_DL"; do [ ! -f "$dlfile" ] && wget -c -O "$dlfile" "$dlurl" done -cp -v revanced-android/revancedcliwrapper/build/outputs/apk/release/revancedcliwrapper-release.apk magiskmodule/wrapper.apk +REVANCED_CLI=$(sed -e 's/^v//' <<< "$REVANCED_CLI") +ln -v -s -f "revanced-cli/build/libs/revancedcli-$REVANCED_CLI-all.jar" "revanced-cli.jar" + +PATCHES_LIST=$(java -jar revanced-cli.jar \ + -b "$(basename "$REVANCED_PATCHES_DL")" \ + -a dummy.apk \ + --list \ + --with-versions \ + --with-packages \ +| sed 's/^INFORMATION: \s*//') +rm -r magiskmodule/packageversions +mkdir magiskmodule/packageversions +echo '## Supported Packages and Versions' > magiskmodule/supportedversions.md +for package in $(cut -d$'\t' -f1 <<< "$PATCHES_LIST" | sort -u); do + cut -d$'\t' -f1,4 <<< "$PATCHES_LIST" | grep "^$package" | cut -d$'\t' -f2 | tr ',' '\n' | sed -e 's/^ //' -e 's/ $//' -e '/^$/d' | sort -u > magiskmodule/packageversions/"$package" + echo "- **\`$package\`**" >> magiskmodule/supportedversions.md + sed 's/^\(.*\)$/`\1`/' < magiskmodule/packageversions/"$package" | tr '\n' '#' | sed -e '/^$/d' -e 's/#$//' -e 's/#/\n/g' | sed -e 's/^/ - /' >> magiskmodule/supportedversions.md + [ $(wc -l < magiskmodule/packageversions/"$package") -gt 0 ] && echo >> magiskmodule/supportedversions.md +done + +cp -v revanced-android/revancedcliwrapper/build/outputs/apk/release/revancedcliwrapper-release.apk magiskmodule/revancedandroidcli.apk cp -v "$(basename "$REVANCED_INTEGRATIONS_DL")" magiskmodule/integrations.apk cp -v "$(basename "$REVANCED_PATCHES_DL")" magiskmodule/patches.jar -cp -r -v aapt2 magiskmodule/ +cp -r -v aapt2 magiskmodule/aapt2lib cp README.md magiskmodule/README.md [ -n "$(git status --porcelain)" ] && CHANGES="+" || CHANGES="-" diff --git a/magiskmodule/customize.sh b/magiskmodule/customize.sh index ce84db1..7e3f2fc 100644 --- a/magiskmodule/customize.sh +++ b/magiskmodule/customize.sh @@ -9,66 +9,79 @@ cd "$MODPATH" [ ! -f ./version.sh ] && abort "Missing version.sh" source ./version.sh -[ -z "$(pm list packages "$YOUTUBE_PACKAGE")" ] && { - ui_print "YouTube not found." - abort "Please install YouTube $YOUTUBE_VERSION manually before installing this module." -} - -installedyoutubeversion="$(pm dump $YOUTUBE_PACKAGE | grep -E '^ *versionName=.*$' | cut -d'=' -f2)" - -[ "$installedyoutubeversion" != "$YOUTUBE_VERSION" ] && { - ui_print "YouTube version mismatch!" - ui_print " Found: $installedyoutubeversion" - ui_print " Expected: $YOUTUBE_VERSION" - abort "Please install the correct YouTube version before installing this module." -} -ui_print "- Found YouTube $installedyoutubeversion" - -youtubeapkpath=$(pm path "$YOUTUBE_PACKAGE" | grep -E 'package:.*/base\.apk' | cut -d':' -f2) -ui_print "- Found YouTube APK at $youtubeapkpath" - MAGISKTMP="$(magisk --path)" || MAGISKTMP=/sbin MIRROR="$MAGISKTMP"/.magisk/mirror ui_print "- Found Magisk mirror at $MIRROR" -youtubeapkpath="$MIRROR"/"$youtubeapkpath" ui_print "- Preparing Patching Process" -cp -v wrapper.apk patches.jar integrations.apk "$TMPDIR" +[ ! -f aapt2lib/$ARCH/libaapt2.so ] && abort "Failed to locate libaapt2.so for $ARCH" +mv -v aapt2lib/$ARCH/libaapt2.so aapt2 +rm -r aapt2lib +chmod -v +x aapt2 -[ ! -f aapt2/$ARCH/libaapt2.so ] && abort "Failed to locate libaapt2.so for $ARCH" -cp -v aapt2/$ARCH/libaapt2.so "$TMPDIR"/aapt2 -chmod -v +x "$TMPDIR"/aapt2 +chmod -v +x system/bin/revancedcli -cd "$TMPDIR" -ui_print " TMPDIR=$TMPDIR" +mkdir overlay -ui_print " Increase Heap Growth limit from $(getprop dalvik.vm.heapgrowthlimit) to 4096m" -resetprop dalvik.vm.heapgrowthlimit 4096m +processPackage() { + local packagename="$1" -ui_print "- Patching YouTube APK" + [ -z "$(pm list packages "$packagename")" ] && { + #ui_print "- $packagename not found" + return + } -app_process \ - -cp wrapper.apk \ - $(pwd) \ - com.programminghoch10.revancedandroidcli.MainCommand \ - -a "$youtubeapkpath" \ - -c \ - -o revanced.apk \ - -b patches.jar \ - -m integrations.apk \ - -e vanced-microg-support \ - --custom-aapt2-binary=$(pwd)/aapt2 \ -2>&1 || abort "Patching failed! $?" + ui_print "- Processing $packagename" -[ ! -f revanced.apk ] && abort "Patching failed!" + installedpackageversion="$(pm dump $packagename | grep -E '^ *versionName=.*$' | cut -d'=' -f2)" -mv -v revanced.apk "$MODPATH"/revanced.apk -rm aapt2 + grep -q -F "$installedpackageversion" < packageversions/"$packagename" || { + ui_print "- $packagename $installedpackageversion is not supported." + return + } -cd "$MODPATH" + ui_print "- Found $packagename $installedpackageversion" + + apkpath=$(pm path "$packagename" | grep -E 'package:.*/base\.apk' | cut -d':' -f2) + ui_print "- Found YouTube APK at $apkpath" + + apkpath="$MIRROR"/"$apkpath" + + patchAPK "$packagename" "$apkpath" + + [ ! -f overlay/"$packagename".apk ] && abort "Couldn't locate patched file!" + + chcon u:object_r:apk_data_file:s0 overlay/"$packagename".apk +} + +patchAPK() { + local packagename="$1" + local apkpath="$2" + cd "$TMPDIR" + + ui_print "- Patching $packagename" + + export MODPATH + "$MODPATH"/system/bin/revancedcli \ + -a "$apkpath" \ + -c \ + -o out.apk \ + -b "$MODPATH"/patches.jar \ + -m "$MODPATH"/integrations.apk \ + -e vanced-microg-support \ + 2>&1 || abort "Patching failed! $?" + + [ ! -f out.apk ] && abort "Patching failed!" + + mv -v out.apk "$MODPATH"/overlay/"$packagename".apk + + cd "$MODPATH" +} -chcon u:object_r:apk_data_file:s0 revanced.apk +for packagename in packageversions/*; do + packagename="$(basename "$packagename")" + processPackage "$packagename" +done -rm wrapper.apk integrations.apk patches.jar -rm -r aapt2 +[ -z "$(ls overlay)" ] && abort "No compatible packages have been found." diff --git a/magiskmodule/service.sh b/magiskmodule/service.sh index 9e26da3..738cda1 100644 --- a/magiskmodule/service.sh +++ b/magiskmodule/service.sh @@ -3,16 +3,13 @@ cd $(dirname $0) source ./version.sh -err() { +logi() { local msg="ReVancedRepackaged: $1" log -t Magisk "$msg" echo "$msg" >> /cache/magisk.log - touch disable - exit 1 } -REVANCEDAPK="$(pwd)"/revanced.apk -[ ! -f "$REVANCEDAPK" ] && err "Missing $REVANCEDAPK" +[ -z "$(ls overlay)" ] && logi "No overlays found!" && touch remove && exit 1 while [ "$(getprop sys.boot_completed)" != "1" ]; do sleep 1 @@ -21,18 +18,34 @@ done MAGISKTMP="$(magisk --path)" || MAGISKTMP=/sbin MIRROR="$MAGISKTMP"/.magisk/mirror -youtubeapkpath=$(pm path "$YOUTUBE_PACKAGE" \ - | grep -E 'package:.*/base\.apk' \ - | cut -d':' -f2) +overlayPackage() { + local packagename="$1" + logi "Overlaying $packagename" -[ -z "$youtubeapkpath" ] && \ - youtubeapkpath=$(find -H \ - "$MIRROR"/data/app \ - -wholename "*${YOUTUBE_PACKAGE}*/base.apk") + overlayapk=$(pwd)/overlay/"$packagename".apk -[ -z "$youtubeapkpath" ] && err "Couldn't locate YouTube base.apk" + apkpath=$(pm path "$packagename" \ + | grep -E 'package:.*/base\.apk' \ + | cut -d':' -f2) -mount -o bind "$MIRROR"/"$REVANCEDAPK" "$youtubeapkpath" \ - || err "Failed to mount $REVANCEDAPK on $youtubeapkpath" + [ -z "$apkpath" ] && \ + apkpath=$(find -H \ + "$MIRROR"/data/app \ + -wholename "*${packagename}*/base.apk") -am force-stop "$YOUTUBE_PACKAGE" + [ -z "$apkpath" ] \ + && logi "Couldn't locate $packagename base.apk" \ + && return 1 + + mount -o bind "$MIRROR"/"$overlayapk" "$apkpath" || { + logi "Failed to mount $overlayapk on $apkpath" + return 1 + } + + am force-stop "$packagename" +} + +for packagename in overlay/*; do + packagename="$(basename "$packagename" | sed -e 's/\.apk$//')" + overlayPackage "$packagename" +done diff --git a/magiskmodule/system/bin/revancedcli b/magiskmodule/system/bin/revancedcli new file mode 100644 index 0000000..7eece75 --- /dev/null +++ b/magiskmodule/system/bin/revancedcli @@ -0,0 +1,14 @@ +#!/system/bin/sh + +[ -z "$MODPATH" ] && MODPATH=/data/adb/modules/revancedrepackaged +echo "modpath = $MODPATH" >&2 + +#echo " Increase Heap Growth limit from $(getprop dalvik.vm.heapgrowthlimit) to 4096m" >&2 +resetprop dalvik.vm.heapgrowthlimit 4096m + +app_process \ + -cp "$MODPATH"/revancedandroidcli.apk \ + $(pwd) \ + com.programminghoch10.revancedandroidcli.MainCommand \ + --custom-aapt2-binary="$MODPATH"/aapt2 \ + "$@" diff --git a/revanced-cli-patches/0001-Load-classes-in-dex-mode.patch b/revanced-cli-patches/0001-Load-classes-in-dex-mode.patch new file mode 100644 index 0000000..ca29794 --- /dev/null +++ b/revanced-cli-patches/0001-Load-classes-in-dex-mode.patch @@ -0,0 +1,58 @@ +From c84645e7f8849c9661ab3032169e35df04a27663 Mon Sep 17 00:00:00 2001 +From: programminghoch10 <16062290+programminghoch10@users.noreply.github.com> +Date: Mon, 29 May 2023 15:33:36 +0200 +Subject: [PATCH] Load classes in dex mode + +Required for loading patches on android +--- + .../app/revanced/cli/command/MainCommand.kt | 20 ++++++++++++++++--- + 1 file changed, 17 insertions(+), 3 deletions(-) + +diff --git a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt +index 0d3b954..95e1cfe 100644 +--- a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt ++++ b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt +@@ -139,7 +139,7 @@ internal object MainCommand : Runnable { + val outputFile = File(pArgs.outputPath) // the file to write to + + val allPatches = args.patchArgs!!.patchBundles.flatMap { bundle -> +- PatchBundle.Jar(bundle).loadPatches() ++ loadPatches(bundle) + } + + args.patchArgs!!.optionsFile.let { +@@ -206,6 +206,21 @@ internal object MainCommand : Runnable { + logger.info("Finished") + } + ++ private fun loadPatches(bundle: String) = try { ++ val DexClassLoaderClass = Class.forName("dalvik.system.DexClassLoader") ++ PatchBundle.Dex( ++ bundle, ++ DexClassLoaderClass.getConstructor( ++ String::class.java, ++ String::class.java, ++ String::class.java, ++ ClassLoader::class.java ++ ).newInstance(bundle, null, null, javaClass.classLoader) as ClassLoader ++ ).loadPatches() ++ } catch (_: ClassNotFoundException) { ++ PatchBundle.Jar(bundle).loadPatches() ++ } ++ + private fun cleanUp(cacheDirectory: String) { + val result = if (File(cacheDirectory).deleteRecursively()) + "Cleaned up cache directory" +@@ -228,8 +243,7 @@ internal object MainCommand : Runnable { + + private fun printListOfPatches() { + val logged = mutableListOf() +- for (patchBundlePath in args.patchArgs?.patchBundles!!) for (patch in PatchBundle.Jar(patchBundlePath) +- .loadPatches()) { ++ for (patchBundlePath in args.patchArgs?.patchBundles!!) for (patch in loadPatches(patchBundlePath)) { + if (patch.patchName in logged) continue + for (compatiblePackage in patch.compatiblePackages ?: continue) { + val packageEntryStr = buildString { +-- +2.39.2 + diff --git a/revanced-cli-patches/0002-Show-full-package-name-in-patch-list.patch b/revanced-cli-patches/0002-Show-full-package-name-in-patch-list.patch new file mode 100644 index 0000000..b37d0c9 --- /dev/null +++ b/revanced-cli-patches/0002-Show-full-package-name-in-patch-list.patch @@ -0,0 +1,25 @@ +From e0b76ba9acc6d99066f284818db05907dc3b616c Mon Sep 17 00:00:00 2001 +From: programminghoch10 <16062290+programminghoch10@users.noreply.github.com> +Date: Sat, 17 Jun 2023 16:30:30 +0200 +Subject: [PATCH 2/2] Show full package name in patch list + +--- + src/main/kotlin/app/revanced/cli/command/MainCommand.kt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt +index ffccc36..22b6e9d 100644 +--- a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt ++++ b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt +@@ -248,7 +248,7 @@ internal object MainCommand : Runnable { + val packageEntryStr = buildString { + // Add package if flag is set + if (args.patchArgs?.listingArgs?.withPackages == true) { +- val packageName = compatiblePackage.name.substringAfterLast(".").padStart(10) ++ val packageName = compatiblePackage.name.padStart(25) + append(packageName) + append("\t") + } +-- +2.39.2 + diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..f129d42 --- /dev/null +++ b/update.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +[ -f .gitauth ] && source .gitauth + +for cmd in jq curl; do + [ -z "$(command -v $cmd)" ] && echo "missing $cmd" && exit 1 +done + +REVANCED_PATCHES_TAG=$(curl -s https://api.github.com/repos/revanced/revanced-patches/releases/latest | jq -r '.tag_name') +REVANCED_INTEGRATIONS_TAG=$(curl -s https://api.github.com/repos/revanced/revanced-integrations/releases/latest | jq -r '.tag_name') +REVANCED_CLI_TAG=$(curl -s https://api.github.com/repos/revanced/revanced-cli/releases/latest | jq -r '.tag_name') + +( + cd revanced-cli + git submodule update --checkout + git checkout "$REVANCED_CLI_TAG" +) + +sed -i "s/^REVANCED_PATCHES=.*$/REVANCED_PATCHES=\"$REVANCED_PATCHES_TAG\"/" version.sh +sed -i "s/^REVANCED_INTEGRATIONS=.*$/REVANCED_INTEGRATIONS=\"$REVANCED_INTEGRATIONS_TAG\"/" version.sh +sed -i "s/^REVANCED_CLI=.*$/REVANCED_CLI=\"$REVANCED_CLI_TAG\"/" version.sh diff --git a/version.sh b/version.sh index ba847a3..1f729d7 100644 --- a/version.sh +++ b/version.sh @@ -1,7 +1,5 @@ #!/bin/bash -YOUTUBE_PACKAGE="com.google.android.youtube" -YOUTUBE_VERSION="18.19.35" - REVANCED_INTEGRATIONS="v0.110.0" REVANCED_PATCHES="v2.177.0" +REVANCED_CLI="v2.21.3"