@echo off
cd "%~dp0"
echo ---        Samsung Galaxy S4 Android 4.3 Root         ---
echo --- Based on the CVE-2013-6282 exploit by cubeundcube ---
echo.
if not exist files (
    echo Fixing the folder structure
    mkdir files
    if exist adb.exe move adb.exe files
    if exist AdbWinApi.dll move AdbWinApi.dll files
    if exist AdbWinUsbApi.dll move AdbWinUsbApi.dll files
    if exist busybox move busybox files
    if exist getroot move getroot files
    if exist install-recovery.sh move install-recovery.sh files
    if exist su move su files
    if exist Superuser.apk move Superuser.apk files
    echo.
)
echo Testing adb usability
echo.
echo | set /p dummy="Plug in your phone and "
pause
for /f "delims=" %%a in ('files\adb get-state ^| findstr /v "foobar"') do @set pstate=%%a
if not %pstate%==device (
    echo.
    echo Watch your phone. If you see the "Allow USB debugging?" prompt
    echo Tap on the "Always allow from this computer" checkbox
    echo then tap OK
    echo.
    echo If this script appears to be stuck at "Waiting for your phone to appear",
    echo then you should tap on the USB icon in the notifications that says
    echo "Connected as a media device". On the"USB computer connection"
    echo page, switch between "Camera" and "Media Device" to see if the
    echo device appears.
)
echo.
echo Waiting for your phone to appear
files\adb wait-for-device
files\adb shell echo "Your phone is detected and ready for rooting."
echo.
echo Sending files to your device...
files\adb push files\getroot /data/local/tmp/
files\adb push files\su /data/local/tmp/
files\adb push files\Superuser.apk /data/local/tmp/
files\adb push files\busybox /data/local/tmp/
files\adb push files\install-recovery.sh /data/local/tmp/
files\adb shell "chmod 0755 /data/local/tmp/getroot"
files\adb shell "chmod 0755 /data/local/tmp/busybox"
echo.
echo Starting rooting program.
files\adb shell "/data/local/tmp/getroot"
echo.
echo Removing temporary files...
files\adb shell "rm /data/local/tmp/getroot"
files\adb shell "rm /data/local/tmp/su"
files\adb shell "rm /data/local/tmp/Superuser.apk"
files\adb shell "rm /data/local/tmp/busybox"
files\adb shell "rm /data/local/tmp/install-recovery.sh"
echo.
echo Rebooting... Please wait.
files\adb reboot
echo Waiting for device to re-appear...
files\adb wait-for-device
echo | set /p dummy="Wait until your phone reboots, then unlock it and "
pause
echo On your phone, give SuperSU permission for ADB shell to run
files\adb wait-for-device
files\adb shell "su -c sleep 1"
files\adb wait-for-device
files\adb shell "su -c sleep 1"
files\adb wait-for-device
files\adb shell "su -c sleep 1"
files\adb wait-for-device
files\adb shell "su -c sleep 1"
files\adb wait-for-device
files\adb shell "su -c sleep 1"
echo.
echo Installing busybox
files\adb shell "su -c mount -o remount,rw /system"
files\adb shell "su -c chmod 6755 /system/xbin/su"
files\adb shell "su -c chmod 6755 /system/xbin/daemonsu"
files\adb wait-for-device
files\adb shell "su -c /system/xbin/busybox --install -s /system/xbin"
files\adb wait-for-device
files\adb shell sleep 15
files\adb wait-for-device
files\adb shell "su -c mount -o remount,ro /system"
echo.
echo --- All Finished ---
pause
