diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f6d1a34 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.jar +*.apk +*.zip +*.keystore + +!base-v17.24.34.apk diff --git a/README.md b/README.md index 7c71679..7093d9b 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,10 @@ -# ReVanced Documentation +# Building the Magisk Module -Instructions to build and install ReVanced. +This repo includes the base.apk of the stock YouTube app (v17.24.34) and a simple script that +download all necessary prebuilt revanced tools and creates a magisk module -# Wiki +# Usage -- [Prerequisites](https://github.com/revanced/revanced-documentation/wiki/Prerequisites) - - [Downloading prebuilt packages](https://github.com/revanced/revanced-documentation/wiki/Downloading-prebuilt-packages) - - [Building from source](https://github.com/revanced/revanced-documentation/wiki/Building-from-source) - - [1. Building the ReVanced patcher](https://github.com/revanced/revanced-documentation/wiki/Building-the-ReVanced-patcher) - - [2. Building the ReVanced patches](https://github.com/revanced/revanced-documentation/wiki/Building-the-ReVanced-patches) - - [3. Building the ReVanced integrations](https://github.com/revanced/revanced-documentation/wiki/Building-the-ReVanced-integrations) - - [4. Building the ReVanced CLI](https://github.com/revanced/revanced-documentation/wiki/Building-the-ReVanced-CLI) -- [Using the ReVanced CLI and installing ReVanced](https://github.com/revanced/revanced-documentation/wiki/Using-the-ReVanced-CLI-and-installing-ReVanced) +```bash +$ ./build-module.sh +``` \ No newline at end of file diff --git a/base-v17.24.34.apk.REMOVED.git-id b/base-v17.24.34.apk.REMOVED.git-id new file mode 100644 index 0000000..7db1a73 --- /dev/null +++ b/base-v17.24.34.apk.REMOVED.git-id @@ -0,0 +1 @@ +dc5ef207bb934e9f91ce06b8d00ddde9738be756 \ No newline at end of file diff --git a/build-module.sh b/build-module.sh new file mode 100755 index 0000000..812e5a2 --- /dev/null +++ b/build-module.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +echo "All necessary files (revanced cli, patches and integrations) will be downloaded, Youtube apk will be patched and zipped into a Magisk module" +read -p "Continue? (y/n): " confirm + +if [[ ! $confirm == [yY] ]]; then + exit 0 +fi + +# CURRENT VERSION +YTBASE="base-v17.24.34.apk" +OUTPUT="revanced-magisk-v17.24.34.zip" + +function dl() { + wget -q --show-progress $1 || { + echo "Download Failed" + exit 1 + } +} + +if [[ ! -f "$YTBASE" ]]; then + echo "$YTBASE not found in the current directory" +fi + +RV_CLI_URL=$(wget -nv -O - https://api.github.com/repos/revanced/revanced-cli/releases/latest | sed -n 's/.*"browser_download_url": "\(.*jar\)".*/\1/p') +RV_CLI_JAR=$(echo $RV_CLI_URL | awk -F/ '{ print $NF }') + +RV_INTEGRATIONS_URL=$(wget -nv -O - https://api.github.com/repos/revanced/revanced-integrations/releases/latest | sed -n 's/.*"browser_download_url": "\(.*apk\)".*/\1/p') +RV_INTEGRATIONS_APK=$(echo $RV_INTEGRATIONS_URL | awk -F/ '{ print $NF }') + +RV_PATCHES_URL=$(wget -nv -O - https://api.github.com/repos/revanced/revanced-patches/releases/latest | sed -n 's/.*"browser_download_url": "\(.*jar\)".*/\1/p') +RV_PATCHES_JAR=$(echo $RV_PATCHES_URL | awk -F/ '{ print $NF }') + +if [[ ! -f RV_CLI_JAR ]]; then + dl $RV_CLI_URL +fi +if [[ ! -f RV_INTEGRATIONS_APK ]]; then + dl $RV_INTEGRATIONS_URL +fi +if [[ ! -f RV_PATCHES_JAR ]]; then + dl $RV_PATCHES_URL +fi + +java -jar $RV_CLI_JAR -a $YTBASE -c -o revanced-base.apk -b $RV_PATCHES_JAR -e microg-support -m $RV_INTEGRATIONS_APK || + { + echo "Building failed" + exit 1 + } + +mv revanced-base.apk ./revanced-magisk/revanced-base.apk + +echo "Creating the magisk module..." +zip -r $OUTPUT ./revanced-magisk + +echo "Created the magisk module '$OUTPUT'" diff --git a/revanced-magisk/android/update-binary b/revanced-magisk/android/update-binary new file mode 100644 index 0000000..29240cd --- /dev/null +++ b/revanced-magisk/android/update-binary @@ -0,0 +1,173 @@ +#!/sbin/sh + +################# +# Initialization +################# + +umask 022 + +# Global vars +TMPDIR=/dev/tmp +PERSISTDIR=/sbin/.magisk/mirror/persist + +rm -rf $TMPDIR 2>/dev/null +mkdir -p $TMPDIR + +# echo before loading util_functions +ui_print() { echo "$1"; } + +require_new_magisk() { + ui_print "*******************************" + ui_print " Please install Magisk v19.0+! " + ui_print "*******************************" + exit 1 +} + +is_legacy_script() { + unzip -l "$ZIPFILE" install.sh | grep -q install.sh + return $? +} + +print_modname() { + local len + len=`echo -n $MODNAME | wc -c` + len=$((len + 2)) + local pounds=`printf "%${len}s" | tr ' ' '*'` + ui_print "$pounds" + ui_print " $MODNAME " + ui_print "$pounds" + ui_print "*******************" + ui_print " Powered by Magisk " + ui_print "*******************" +} + +############## +# Environment +############## + +OUTFD=$2 +ZIPFILE=$3 + +mount /data 2>/dev/null + +# Load utility functions +[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk +. /data/adb/magisk/util_functions.sh +[ $MAGISK_VER_CODE -gt 18100 ] || require_new_magisk + +# Preperation for flashable zips +setup_flashable + +# Mount partitions +mount_partitions + +# Detect version and architecture +api_level_arch_detect + +# Setup busybox and binaries +$BOOTMODE && boot_actions || recovery_actions + +############## +# Preparation +############## + +# Extract prop file +unzip -o "$ZIPFILE" module.prop -d $TMPDIR >&2 +[ ! -f $TMPDIR/module.prop ] && abort "! Unable to extract zip file!" + +$BOOTMODE && MODDIRNAME=modules_update || MODDIRNAME=modules +MODULEROOT=$NVBASE/$MODDIRNAME +MODID=`grep_prop id $TMPDIR/module.prop` +MODPATH=$MODULEROOT/$MODID +MODNAME=`grep_prop name $TMPDIR/module.prop` + +# Create mod paths +rm -rf $MODPATH 2>/dev/null +mkdir -p $MODPATH + +########## +# Install +########## + +if is_legacy_script; then + unzip -oj "$ZIPFILE" module.prop install.sh uninstall.sh 'common/*' -d $TMPDIR >&2 + + # Load install script + . $TMPDIR/install.sh + + # Callbacks + print_modname + on_install + + # Custom uninstaller + [ -f $TMPDIR/uninstall.sh ] && cp -af $TMPDIR/uninstall.sh $MODPATH/uninstall.sh + + # Skip mount + $SKIPMOUNT && touch $MODPATH/skip_mount + + # prop file + $PROPFILE && cp -af $TMPDIR/system.prop $MODPATH/system.prop + + # Module info + cp -af $TMPDIR/module.prop $MODPATH/module.prop + + # post-fs-data scripts + $POSTFSDATA && cp -af $TMPDIR/post-fs-data.sh $MODPATH/post-fs-data.sh + + # service scripts + $LATESTARTSERVICE && cp -af $TMPDIR/service.sh $MODPATH/service.sh + + ui_print "- Setting permissions" + set_permissions +else + print_modname + + unzip -o "$ZIPFILE" customize.sh -d $MODPATH >&2 + + if ! grep -q '^SKIPUNZIP=1$' $MODPATH/customize.sh 2>/dev/null; then + ui_print "- Extracting module files" + unzip -o "$ZIPFILE" -x 'META-INF/*' -d $MODPATH >&2 + + # Default permissions + set_perm_recursive $MODPATH 0 0 0755 0644 + fi + + # Load customization script + [ -f $MODPATH/customize.sh ] && . $MODPATH/customize.sh +fi + +# Handle replace folders +for TARGET in $REPLACE; do + ui_print "- Replace target: $TARGET" + mktouch $MODPATH$TARGET/.replace +done + +if $BOOTMODE; then + # Update info for Magisk Manager + mktouch $NVBASE/modules/$MODID/update + cp -af $MODPATH/module.prop $NVBASE/modules/$MODID/module.prop +fi + +# Copy over custom sepolicy rules +if [ -f $MODPATH/sepolicy.rule -a -e $PERSISTDIR ]; then + ui_print "- Installing custom sepolicy patch" + PERSISTMOD=$PERSISTDIR/magisk/$MODID + mkdir -p $PERSISTMOD + cp -af $MODPATH/sepolicy.rule $PERSISTMOD/sepolicy.rule +fi + +# Remove stuffs that don't belong to modules +rm -rf \ +$MODPATH/system/placeholder $MODPATH/customize.sh \ +$MODPATH/README.md $MODPATH/.git* 2>/dev/null + +############## +# Finalizing +############## + +cd / +$BOOTMODE || recovery_cleanup +rm -rf $TMPDIR + +ui_print "- Done" +exit 0 diff --git a/revanced-magisk/android/updater-script b/revanced-magisk/android/updater-script new file mode 100644 index 0000000..11d5c96 --- /dev/null +++ b/revanced-magisk/android/updater-script @@ -0,0 +1 @@ +#MAGISK diff --git a/revanced-magisk/common/addon/placeholder b/revanced-magisk/common/addon/placeholder new file mode 100644 index 0000000..e69de29 diff --git a/revanced-magisk/common/functions.sh b/revanced-magisk/common/functions.sh new file mode 100644 index 0000000..5e65e12 --- /dev/null +++ b/revanced-magisk/common/functions.sh @@ -0,0 +1,252 @@ +########################################################################################## +# +# MMT Extended Utility Functions +# +########################################################################################## + +abort() { + ui_print "$1" + rm -rf $MODPATH 2>/dev/null + cleanup + rm -rf $TMPDIR 2>/dev/null + exit 1 +} + +cleanup() { + rm -rf $MODPATH/common 2>/dev/null + ui_print " " + ui_print " ***************************************" + ui_print " * MMT Extended by Zackptg5 @ XDA *" + ui_print " ***************************************" + ui_print "" + ui_print " ***************************************" + ui_print " * YouTube Vanced Magisk Installer *" + ui_print " ***************************************" + ui_print "" + ui_print " +YOU MAY NEED TO REMOVE THE PREVIOUS MODULE +AND REBOOT PRIOR TO INSTALLING ANY UPDATES. + +For more installation and troubleshooting +info, please visit: +https://forum.xda-Developers.com/showpost.php?p=83741225&postcount=17198 + +Huge thanks to: 73sydney, ipdev, Eselter, majicmazo + and the YouTube Vanced team +" + +} + +device_check() { + local opt=`getopt -o dm -- "$@"` type=device + eval set -- "$opt" + while true; do + case "$1" in + -d) local type=device; shift;; + -m) local type=manufacturer; shift;; + --) shift; break;; + *) abort "Invalid device_check argument $1! Aborting!";; + esac + done + local prop=$(echo "$1" | tr '[:upper:]' '[:lower:]') + for i in /system /vendor /odm /product; do + if [ -f $i/build.prop ]; then + for j in "ro.product.$type" "ro.build.$type" "ro.product.vendor.$type" "ro.vendor.product.$type"; do + [ "$(sed -n "s/^$j=//p" $i/build.prop 2>/dev/null | head -n 1 | tr '[:upper:]' '[:lower:]')" == "$prop" ] && return 0 + done + fi + done + return 1 +} + +cp_ch() { + local opt=`getopt -o nr -- "$@"` BAK=true UBAK=true FOL=false + eval set -- "$opt" + while true; do + case "$1" in + -n) UBAK=false; shift;; + -r) FOL=true; shift;; + --) shift; break;; + *) abort "Invalid cp_ch argument $1! Aborting!";; + esac + done + local SRC="$1" DEST="$2" OFILES="$1" + $FOL && local OFILES=$(find $SRC -type f 2>/dev/null) + [ -z $3 ] && PERM=0644 || PERM=$3 + case "$DEST" in + $TMPDIR/*|$MODULEROOT/*|$NVBASE/modules/$MODID/*) BAK=false;; + esac + for OFILE in ${OFILES}; do + if $FOL; then + if [ "$(basename $SRC)" == "$(basename $DEST)" ]; then + local FILE=$(echo $OFILE | sed "s|$SRC|$DEST|") + else + local FILE=$(echo $OFILE | sed "s|$SRC|$DEST/$(basename $SRC)|") + fi + else + [ -d "$DEST" ] && local FILE="$DEST/$(basename $SRC)" || local FILE="$DEST" + fi + if $BAK && $UBAK; then + [ ! "$(grep "$FILE$" $INFO 2>/dev/null)" ] && echo "$FILE" >> $INFO + [ -f "$FILE" -a ! -f "$FILE~" ] && { mv -f $FILE $FILE~; echo "$FILE~" >> $INFO; } + elif $BAK; then + [ ! "$(grep "$FILE$" $INFO 2>/dev/null)" ] && echo "$FILE" >> $INFO + fi + install -D -m $PERM "$OFILE" "$FILE" + done +} + +install_script() { + case "$1" in + -l) shift; local INPATH=$NVBASE/service.d;; + -p) shift; local INPATH=$NVBASE/post-fs-data.d;; + *) local INPATH=$NVBASE/service.d;; + esac + [ "$(grep "#!/system/bin/sh" $1)" ] || sed -i "1i #!/system/bin/sh" $1 + local i; for i in "MODPATH" "LIBDIR" "MODID" "INFO" "MODDIR"; do + case $i in + "MODPATH") sed -i "1a $i=$NVBASE/modules/$MODID" $1;; + "MODDIR") sed -i "1a $i=\${0%/*}" $1;; + *) sed -i "1a $i=$(eval echo \$$i)" $1;; + esac + done + [ "$1" == "$MODPATH/uninstall.sh" ] && return 0 + case $(basename $1) in + post-fs-data.sh|service.sh) ;; + *) cp_ch -n $1 $INPATH/$(basename $1) 0755;; + esac +} + +prop_process() { + sed -i -e "/^#/d" -e "/^ *$/d" $1 + [ -f $MODPATH/system.prop ] || mktouch $MODPATH/system.prop + while read LINE; do + echo "$LINE" >> $MODPATH/system.prop + done < $1 +} + +# Check for min/max api version +[ -z $MINAPI ] || { [ $API -lt $MINAPI ] && abort "! Your system API of $API is less than the minimum api of $MINAPI! Aborting!"; } +[ -z $MAXAPI ] || { [ $API -gt $MAXAPI ] && abort "! Your system API of $API is greater than the maximum api of $MAXAPI! Aborting!"; } + +# Set variables +[ $API -lt 26 ] && DYNLIB=false +[ -z $DYNLIB ] && DYNLIB=false +[ -z $DEBUG ] && DEBUG=false +[ -e "$PERSISTDIR" ] && PERSISTMOD=$PERSISTDIR/magisk/$MODID +INFO=$NVBASE/modules/.$MODID-files +ORIGDIR="$MAGISKTMP/mirror" +if $DYNLIB; then + LIBPATCH="\/vendor" + LIBDIR=/system/vendor +else + LIBPATCH="\/system" + LIBDIR=/system +fi +if ! $BOOTMODE; then + ui_print "- Only uninstall is supported in recovery" + ui_print " Uninstalling!" + touch $MODPATH/remove + [ -s $INFO ] && install_script $MODPATH/uninstall.sh || rm -f $INFO $MODPATH/uninstall.sh + recovery_cleanup + cleanup + rm -rf $NVBASE/modules_update/$MODID $TMPDIR 2>/dev/null + exit 0 +fi + +# Debug +if $DEBUG; then + ui_print "- Debug mode" + ui_print " Module install log will include debug info" + ui_print " Be sure to save it after module install" + set -x +fi + +# Extract files +ui_print "- Extracting module files" +unzip -o "$ZIPFILE" -x 'META-INF/*' 'common/functions.sh' -d $MODPATH >&2 +[ -f "$MODPATH/common/addon.tar.xz" ] && tar -xf $MODPATH/common/addon.tar.xz -C $MODPATH/common 2>/dev/null + +# Run addons +if [ "$(ls -A $MODPATH/common/addon/*/install.sh 2>/dev/null)" ]; then + ui_print " "; ui_print "- Running Addons -" + for i in $MODPATH/common/addon/*/install.sh; do + ui_print " Running $(echo $i | sed -r "s|$MODPATH/common/addon/(.*)/install.sh|\1|")..." + . $i + done +fi + +# Remove files outside of module directory +ui_print "- Removing old files" + +if [ -f $INFO ]; then + while read LINE; do + if [ "$(echo -n $LINE | tail -c 1)" == "~" ]; then + continue + elif [ -f "$LINE~" ]; then + mv -f $LINE~ $LINE + else + rm -f $LINE + while true; do + LINE=$(dirname $LINE) + [ "$(ls -A $LINE 2>/dev/null)" ] && break 1 || rm -rf $LINE + done + fi + done < $INFO + rm -f $INFO +fi + +### Install +ui_print "- Installing" + +[ -f "$MODPATH/common/install.sh" ] && . $MODPATH/common/install.sh + +ui_print " Installing for $ARCH SDK $API device..." +# Remove comments from files and place them, add blank line to end if not already present +for i in $(find $MODPATH -type f -name "*.sh" -o -name "*.prop" -o -name "*.rule"); do + [ -f $i ] && { sed -i -e "/^#/d" -e "/^ *$/d" $i; [ "$(tail -1 $i)" ] && echo "" >> $i; } || continue + case $i in + "$MODPATH/service.sh") install_script -l $i;; + "$MODPATH/post-fs-data.sh") install_script -p $i;; + "$MODPATH/uninstall.sh") if [ -s $INFO ] || [ "$(head -n1 $MODPATH/uninstall.sh)" != "# Don't modify anything after this" ]; then + install_script $MODPATH/uninstall.sh + else + rm -f $INFO $MODPATH/uninstall.sh + fi;; + esac +done + +$IS64BIT || for i in $(find $MODPATH/system -type d -name "lib64"); do rm -rf $i 2>/dev/null; done +[ -d "/system/priv-app" ] || mv -f $MODPATH/system/priv-app $MODPATH/system/app 2>/dev/null +[ -d "/system/xbin" ] || mv -f $MODPATH/system/xbin $MODPATH/system/bin 2>/dev/null +if $DYNLIB; then + for FILE in $(find $MODPATH/system/lib* -type f 2>/dev/null | sed "s|$MODPATH/system/||"); do + [ -s $MODPATH/system/$FILE ] || continue + case $FILE in + lib*/modules/*) continue;; + esac + mkdir -p $(dirname $MODPATH/system/vendor/$FILE) + mv -f $MODPATH/system/$FILE $MODPATH/system/vendor/$FILE + [ "$(ls -A `dirname $MODPATH/system/$FILE`)" ] || rm -rf `dirname $MODPATH/system/$FILE` + done + # Delete empty lib folders (busybox find doesn't have this capability) + toybox find $MODPATH/system/lib* -type d -empty -delete >/dev/null 2>&1 +fi + +# Set permissions +ui_print " " +ui_print "- Setting Permissions" +set_perm_recursive $MODPATH 0 0 0755 0644 +if [ -d $MODPATH/system/vendor ]; then + set_perm_recursive $MODPATH/system/vendor 0 0 0755 0644 u:object_r:vendor_file:s0 + [ -d $MODPATH/system/vendor/app ] && set_perm_recursive $MODPATH/system/vendor/app 0 0 0755 0644 u:object_r:vendor_app_file:s0 + [ -d $MODPATH/system/vendor/etc ] && set_perm_recursive $MODPATH/system/vendor/etc 0 0 0755 0644 u:object_r:vendor_configs_file:s0 + [ -d $MODPATH/system/vendor/overlay ] && set_perm_recursive $MODPATH/system/vendor/overlay 0 0 0755 0644 u:object_r:vendor_overlay_file:s0 + for FILE in $(find $MODPATH/system/vendor -type f -name *".apk"); do + [ -f $FILE ] && chcon u:object_r:vendor_app_file:s0 $FILE + done +fi +set_permissions + +# Complete install +cleanup diff --git a/revanced-magisk/common/install.sh b/revanced-magisk/common/install.sh new file mode 100644 index 0000000..e69de29 diff --git a/revanced-magisk/customize.sh b/revanced-magisk/customize.sh new file mode 100644 index 0000000..89f775b --- /dev/null +++ b/revanced-magisk/customize.sh @@ -0,0 +1,25 @@ +########################################################################################## +# +# MMT Extended Config Script +# +########################################################################################## + +########################################################################################## +# Config Flags +########################################################################################## + +# Uncomment and change 'MINAPI' and 'MAXAPI' to the minimum and maximum android version for your mod +# Uncomment DYNLIB if you want libs installed to vendor for oreo+ and system for anything older +# Uncomment DEBUG if you want full debug logs (saved to /sdcard) +MINAPI=21 +#MAXAPI=25 +#DYNLIB=true +#DEBUG=true + +########################################################################################## +# MMT Extended Logic - Don't modify anything after this +########################################################################################## + +SKIPUNZIP=1 +unzip -qjo "$ZIPFILE" 'common/functions.sh' -d $TMPDIR >&2 +. $TMPDIR/functions.sh diff --git a/revanced-magisk/module.prop b/revanced-magisk/module.prop new file mode 100644 index 0000000..4d337cb --- /dev/null +++ b/revanced-magisk/module.prop @@ -0,0 +1,6 @@ +id=ytrvi +name=YouTube ReVanced v17.24.34 +version=v17.24.34 +versionCode=1 +author=j-hc +description=mounts base.apk for YouTube ReVanced \ No newline at end of file diff --git a/revanced-magisk/service.sh b/revanced-magisk/service.sh new file mode 100644 index 0000000..bea4c33 --- /dev/null +++ b/revanced-magisk/service.sh @@ -0,0 +1,19 @@ +while [ "$(getprop sys.boot_completed)" != 1 ]; +do sleep 1; +done; + +# >A11 +YTPATH=$(readlink -f /data/app/*/com.google.android.youtube*/oat | sed 's/\/oat//g') + +if [ ! -z "$YTPATH" ] +then + su -c mount $MODDIR/revanced-base.apk $YTPATH/base.apk +else + # /dev/null)" ] && break 1 || rm -rf $LINE + done + fi + done < $INFO + rm -f $INFO +fi