#!/bin/bash

# Always Apple FTD Passra1n Bypass Script
# Remove iOS 12.0 to 14.8.1 Untethered iCloud Bypass

# 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 ""

# Kill iproxy in case its already runnning
killall iproxy

echo "Starting iproxy..."

# Run iproxy in the background
./tools/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!"

# Remove old RaptorActivation.pem file
echo "Deleting old RaptorActivation.pem off of device"
sleep 1
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p 2222 "root@localhost" 'rm -rf /System/Library/PrivateFrameworks/MobileActivation.framework/Support/Certificates/RaptorActivation.pem'

sleep 1
echo "Deleting first dylib and plist..."
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p 2222 "root@localhost" 'rm -rf /Library/MobileSubstrate/DynamicLibraries/untetheredbp1.dylib'
sleep 1
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p 2222 "root@localhost" 'rm -rf /Library/MobileSubstrate/DynamicLibraries/untetheredbp1.plist'
echo "Done!"
echo "Deleting second dylib and plist..."
sleep 1
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p 2222 "root@localhost" 'rm -rf /Library/MobileSubstrate/DynamicLibraries/untetheredbp2.dylib'
sleep 1
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p 2222 "root@localhost" 'rm -rf /Library/MobileSubstrate/DynamicLibraries/untetheredbp2.plist'
echo "Done!"
#echo "Injected cert!"

sleep 3

echo "Respringing device..."
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p 2222 "root@localhost" 'killall backboardd'

sleep 32

echo "Deactivating device..."
./tools/ideviceactivation deactivate

sleep 5

echo "Respringing device..."
./tools/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p 2222 "root@localhost" 'killall backboardd'

sleep 32

echo "Done! Device should now be re-locked!"

#./tools/ideviceactivation activate -s aaftd.000webhostapp.com/ -d
#/usr/local/bin/ideviceactivation activate -s aaftd.000webhostapp.com/ -d

# Kill iproxy
killall iproxy

#echo "Activation Payload Ran!"

echo ""