commit 9b8e15654bcc31ec3521a13f96b1ebba8a316123 Author: Vitaliy Filippov Date: Mon Mar 6 00:00:45 2023 +0300 Patched multidisabler for Galaxy A73 - initial commit diff --git a/multidisabler b/multidisabler new file mode 100755 index 0000000..866f5fc --- /dev/null +++ b/multidisabler @@ -0,0 +1,254 @@ +#!/system/bin/sh +# +# A simple Samsung services disabler by Ian Macdonald. +# Enhanced by afaneh92 for Galaxy S22 - https://github.com/mohammad92/android_device_samsung_g0s +# Then enhanced by vitalif for Galaxy A73 - https://yourcmc.ru/git/vitalif/multidisabler-a73 :-) +# With F2FS and "SUPER" partition support. +# +# Use this _JUST_ after installing TWRP to prime your device! +# +# What does it do: +# - Makes /vendor and /system read-write +# - Disables file-based encryption on /data +# - Disables full-disk encryption on /data +# - Disables stock recovery restoration +# + +set -e + +md5() { + md5sum -b "$1" +} + +file_changed() { + local file="$1" + local old_md5="$2" + local new_md5=$( md5 "$file" ) + + if [ $new_md5 != $old_md5 ]; then + echo " - ...modified." + else + echo " - ...unchanged." + fi +} + +resize_fs() { + local path=$1 + local label=$2 + local partname=$3 + local percent=$4 + local dm_block_ext4=$(df -t ext4 | grep "$path"'$' | cut -DF1) + local dm_block_f2fs=$(df -t f2fs | grep "$path"'$' | cut -DF1) + + if [ "$dm_block_ext4" ]; then + echo " - Unmounting $path..." + umount $path + echo " - Checking $path block partition before resizing..." + e2fsck -f $dm_block_ext4 + echo " - Resizing the filesystem on $dm_block_ext4..." + resize2fs $dm_block_ext4 + echo " - Make the $path partition R/W by unsharing its blocks..." + e2fsck -E unshare_blocks $dm_block_ext4 + elif [ "$dm_block_f2fs" ]; then + fs_size_mb=$(du -sm $path | cut -f1) + super_free_mb=`lptools free | grep Free | awk '{print int($3 / 1048576)}'` + new_fs_size_mb=`echo $fs_size_mb $super_free_mb $percent | awk '{print int($1 + $2 * $3 / 100)}'` + uuid=$(toybox blkid $dm_block_f2fs | egrep '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}' -o) + echo " - Create R/W $partname image..." + truncate -s ${new_fs_size_mb}M /data/new-rw.img + make_f2fs -g android -O project_quota,extra_attr,inode_checksum,sb_checksum,compression,flexible_inline_xattr,verity,inode_crtime -U $uuid -f -l $label /data/new-rw.img + mkdir -p /data/new-rw + mount /data/new-rw.img /data/new-rw + echo " - Copy old R/O $partname files to our new created image..." + cp -a --preserve=all $path/* /data/new-rw + umount $path + umount /data/new-rw + echo " - Checking $partname image before flashing..." + fsck.f2fs -f /data/new-rw.img + echo " - Resizing partition $partname inside 'super' to $new_fs_size_mb MB using lptools" + lptools resize $partname $(stat -c '%s' /data/new-rw.img) + lptools unmap $partname + lptools map $partname + echo " - Writing our new R/W $partname image, please wait..." + dd if=/data/new-rw.img of=/dev/block/bootdevice/by-name/$partname bs=1M + rm -rf /data/new-rw* + fi + echo " - Remounting $path..." + mount $path + mount -o remount,rw $path +} + +fs_free_size_check() { + local path=$1 + local label=$2 + local partname=$3 + local percent=$4 + echo " - Checking $path free space..." + if dd if=/dev/zero of=$path/test bs=1 count=1 2>/dev/null; then + echo " - ...succeeded." + rm -f $path/test + else + echo " - ...No free space on $path, attempting to resize it..." + echo " " + rm -f $path/test + resize_fs "$path" "$label" "$partname" "$percent" + fi +} + +disable_fbe() { + local md5 + local i + fstab_files=`grep -lr 'fileencryption' vendor/etc` + + # + # Exynos devices = fstab.exynos*. + # MediaTek devices = fstab.mt*. + # Snapdragon devices = fstab.qcom, fstab.emmc, fstab.default + # + for i in $fstab_files; do + if [ -f $i ]; then + echo " - Disabling file-based encryption (FBE) for /data..." + echo " - Found $i." + md5=$( md5 $i ) + # This comments out the offending line and adds an edited one. + sed -i -e 's/^\([^#].*\)fileencryption=[^,]*\(.*\)$/# &\n\1encryptable\2/g' $i + file_changed $i $md5 + fi + done +} + +disable_fde() { + local md5 + local i + fstab_files=`grep -lr 'forceencrypt' vendor/etc` + + # + # Exynos devices = fstab.exynos*. + # MediaTek devices = fstab.mt*. + # Snapdragon devices = fstab.qcom, fstab.emmc, fstab.default + # + for i in $fstab_files; do + if [ -f $i ]; then + echo " - Disabling full-disk encryption (FDE) for /data..." + echo " - Found $i." + md5=$( md5 $i ) + # This comments out the offending line and adds an edited one. + sed -i -e 's/^\([^#].*\)forceencrypt=[^,]*\(.*\)$/# &\n\1encryptable\2/g' $i + file_changed $i $md5 + fi + done +} + +disable_recovery_restoration() { + local r=recovery-from-boot.p + local found + local i + + echo " - Disabling restoration of stock recovery..." + + for i in $ANDROID_ROOT $ANDROID_ROOT/system /vendor; do + if [ -f $i/$r~ ]; then + echo " - ...already disabled." + found=true + break + fi + + if [ -f $i/$r ]; then + echo " - Found $i/$r. Disabling..." + mv $i/$r $i/$r~ + + if [ -f $i/$r~ ]; then + echo " - ...succeeded." + else + echo " - ...failed." + fi + + found=true + break + fi + + done + + [ -z "$found" ] && echo " - Found no stock recovery. Pfft." +} + +echo " " +echo "Multi-disabler for Samsung devices" +echo "running Android 9 or later." +echo "by Ian Macdonald, enhanced by afaneh92" +echo "patched for Galaxy A73 by vitalif" +echo " " + +os=$(getprop ro.build.version.release) +major=${os%%.*} +bl=$(getprop ro.boot.bootloader) +dp=$(getprop ro.boot.dynamic_partitions) + +# Firmware version starts at either 8th or 9th character, depending on length +# of bootloader string (12 or 13). +# +fw=${bl:$((${#bl} - 4)):4} + +# Device is first 5 characters of bootloader string. +# +device=${bl:0:$((${#bl} - 8))} +mft=$(getprop ro.product.manufacturer | tr '[A-Z]' '[a-z]') + +if [ "$mft" != samsung ]; then + echo " - Device appears not to be made by Samsung." + fatal=true +elif [ -z "$device" ]; then + echo " - Could not determine device model." + fatal=true +elif [ $major -lt 9 ]; then + echo " - This software is incompatible with Android $major." + fatal=true +fi +if [ -n "$fatal" ]; then + echo " - Installation aborted." + echo " " + exit 1 +fi + +echo " - Detected a $device device with a $fw bootloader." +echo " - The environment appears to be Android $major." +echo " " + +echo " - Mounting $ANDROID_ROOT..." +if ! mount | grep "$ANDROID_ROOT " >/dev/null; then + mount -o rw $ANDROID_ROOT 2>/dev/null || true + if ! mount | grep "$ANDROID_ROOT " >/dev/null; then + ANDROID_ROOT=/system_root + echo " - Attempt failed. Mounting at $ANDROID_ROOT..." + if ! mount | grep "$ANDROID_ROOT " >/dev/null; then + mount -o rw $ANDROID_ROOT + if ! mount | grep "$ANDROID_ROOT " >/dev/null; then + echo " - Even that attempt failed. Aborting..." + exit 2 + fi + fi + fi +fi + +echo " - Mounting /vendor..." +mount /vendor || true +mount -o remount,rw /vendor || true +if ! mount | grep '/vendor ' >/dev/null; then + echo " - Mount failed. Aborting..." + exit 3 +fi + +fs_free_size_check $ANDROID_ROOT "/" system 70 +fs_free_size_check /vendor vendor vendor 50 +disable_fbe +disable_fde +disable_recovery_restoration + +echo " - Unmounting /vendor..." +umount /vendor +echo " - Unmounting $ANDROID_ROOT..." +umount $ANDROID_ROOT + +echo " " +echo " - Finished." +echo " "