#!/bin/bash

# Always Apple FTD Passra1n Bypass Script
# iOS 12.0 to 14.8.1 Untethered iCloud Bypass
# Make the bypass untethered

# Remove known_hosts file so we don't run into ssh key issue
rm -rf ~/.ssh/known_hosts

# Change to the current dir
cd "`dirname "$0"`"

echo ""

echo "Starting iproxy..."

# Run iproxy in the background
#./iproxy 2222:44 > /dev/null 2>&1 &
iproxy 2222:44 > /dev/null 2>&1 &

sleep 2

# Mount the filesystem to make modifications 
echo "Mounting Filesystems as Read-write..."
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p 2222 "root@localhost" 'mount -o rw,union,update /'
echo "Mounted!"

sleep 2

echo "Adding bypass files part 1..."
sleep 1
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "dd of=/Library/MobileSubstrate/DynamicLibraries/untetheredbp1.dylib" < patches/untetheredbp1.dylib
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "dd of=/Library/MobileSubstrate/DynamicLibraries/untetheredbp1.plist" < patches/untetheredbp1.plist

echo "Killing CommCenter and CommCenterMobileHelper"
./tools/sshpass -p alpine ssh -o StrictHostKeyChecking=no root@localhost -p 2222 killall CommCenter && ./tools/sshpass -p alpine ssh -o StrictHostKeyChecking=no root@localhost -p 2222 killall CommCenterMobileHelper

sleep 5

echo "Re-adding files for bypass..."
sleep 1
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "dd of=/Library/MobileSubstrate/DynamicLibraries/untetheredbp1.dylib" < patches/untetheredbp1.dylib
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "dd of=/Library/MobileSubstrate/DynamicLibraries/untetheredbp1.plist" < patches/untetheredbp1.plist
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "dd of=/Library/MobileSubstrate/DynamicLibraries/untetheredbp2.dylib" < patches/untetheredbp2.dylib
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "dd of=/Library/MobileSubstrate/DynamicLibraries/untetheredbp2.plist" < patches/untetheredbp2.plist

sleep 4

echo "Respringing device..."
sleep 1
./tools/sshpass -p alpine ssh -o StrictHostKeyChecking=no root@localhost -p 2222 ldrestart

sleep 32

#read -p "Run ideviceactivation now with epicstuff.php"

echo "Attempting to fake activation. This is needed to temporarily deactivate the device."
sleep 1
./tools/ideviceactivation activate -s https://appletech752.com/server/epicstuff.php -d

#/usr/local/bin/ideviceactivation activate -s https://appletech752.com/server/epicstuff.php && sleep 5

echo "Removing untetheredbp2.dylib and untetheredbp2.plist..."
sleep 1
./tools/sshpass -p alpine ssh -o StrictHostKeyChecking=no root@localhost -p 2222 rm /Library/MobileSubstrate/DynamicLibraries/untetheredbp2.dylib
./tools/sshpass -p alpine ssh -o StrictHostKeyChecking=no root@localhost -p 2222 rm /Library/MobileSubstrate/DynamicLibraries/untetheredbp2.plist
./tools/sshpass -p alpine ssh -o StrictHostKeyChecking=no root@localhost -p 2222 ldrestart

sleep 32

#read -p "Run ideviceactivation now with epicstuff.php"

echo "Activating Untethered!"
sleep 1
./tools/ideviceactivation activate -s https://appletech752.com/server/epicstuff.php -d

#/usr/local/bin/ideviceactivation activate -s https://appletech752.com/server/epicstuff.php -d

# Kill iproxy
killall iproxy

echo "Activated! Insert a PIN-locked SIM"