@echo off
echo.
echo **************************************************
echo Automated root for LG Optimus G, G2, G Pro, G Flex
echo Original idea by IOMonster (thecubed on XDA)
echo http://tinyw.in/mXhw
echo Original linux script and Sprint root by Shelnutt2

echo Original LG root backdoor idea by giantpune

echo Current IOroot by autoprime
echo **************************************************
echo.
echo.
echo.
echo.
echo **************************************************
echo Unlock phone and lock screen.
echo Turn on airplane mode.
echo Set USB mode to charge only mode.
echo Verizon users must use ethernet mode instead!
echo **************************************************
pause
echo.
echo.
echo.
echo.
echo.
echo.
echo Looking for device... 
echo Make sure drivers are installed. Check Windows Device Manager.
echo Make sure proper USB Debugging mode is enabled.
echo Verizon users make sure ethernet mode is selected.
echo Did you check phone screen for Yes/No prompt?

echo (select checkbox to always remember then hit yes)
echo ...sometimes you need to unplug the USB cable then re-plug.
.\adb.exe wait-for-device
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo Determining device model...
for /f %%i in ('.\adb.exe shell getprop ro.product.model') do set MODEL=%%i
if %MODEL%==LG-LS980 GOTO SPRRoot
if %MODEL%==LG-D800 GOTO ATTRoot
if %MODEL%==LG-D801 GOTO D801Carrier
if %MODEL%==LG-D802 GOTO D802Root
if %MODEL%==LG-D803 GOTO D803Root
if %MODEL%==LG-D805 GOTO D802Root
if %MODEL%==LG-D806 GOTO D802Root
if %MODEL%==LG-F320K GOTO KTRoot
if %MODEL%==LG-F320L GOTO LGURoot
if %MODEL%==LG-F320S GOTO SKTRoot
if %MODEL%==LG-VS980 GOTO VZWRoot
if %MODEL%==VS980 4G GOTO VZWRoot
if %MODEL%==VS980 GOTO VZWRoot
if %MODEL%=="VS980 4G" GOTO VZWRoot
if %MODEL%==LG-F340K GOTO F340JBRoot
if %MODEL%==LG-F340L GOTO F340JBRoot
if %MODEL%==LG-F340S GOTO F340JBRoot
if %MODEL%==LG-D958 GOTO GFlexJBRoot
if %MODEL%==LG-D959 GOTO D959Root
if %MODEL%==LG-D955 GOTO GFlexJBRoot
if %MODEL%==LG-D950 GOTO D950Root
if %MODEL%==LG-LS995 GOTO LS995Root
if %MODEL%==LG-LS970 GOTO LGOGRoot
if %MODEL%==LG-E970 GOTO LGOGRoot
if %MODEL%==LG-LS971 GOTO LGOGRoot
if %MODEL%==LG-LS973 GOTO LGOGRoot
if %MODEL%==LG-LS975 GOTO LGOGRoot
if %MODEL%==LG-LS975R GOTO LGOGRoot
if %MODEL%==LG-LS975T GOTO LGOGRoot
if %MODEL%==LG-LS975S GOTO LGOGRoot
if %MODEL%==LG-LS976 GOTO LGOGRoot
if %MODEL%==LG-LS977 GOTO LGOGRoot
if %MODEL%==LG-F180K GOTO LGOGRoot
if %MODEL%==LG-F180L GOTO LGOGRoot
if %MODEL%==LG-F180S GOTO LGOGRoot
echo.
echo No matching phone found. 
echo Please post model version mentioned above in main XDA thread..
.\adb shell "getprop ro.product.model"

.\adb shell "getprop ro.build.target_operator"

.\adb shell "getprop ro.lge.swversion"

.\adb shell "getprop ro.build.fingerprint"
echo along with current firmware version.
pause

:D801Carrier
echo Determining carrier...
for /f %%i in ('.\adb.exe shell getprop ro.build.target_operator') do set RESULT=%%i
if %RESULT%==CLR GOTO D803Root
if %RESULT%==TMO GOTO TMORoot
if %RESULT%==OPEN GOTO D802Root
if %RESULT%==SCA GOTO D802Root
if %RESULT%==VDF GOTO StockJBRoot
if %RESULT%==VTR GOTO D803Root
if %RESULT%==WND GOTO D803Root
echo.
echo.
echo No matching carrier found. Got %RESULT% from ADB.
echo Please post carrier code mentioned above in main XDA thread..
echo along with current firmware version. 
pause

:ATTRoot
echo Found ATT phone!
echo.
echo Checking OTA version...
for /f %%i in ('.\adb.exe shell getprop ro.lge.swversion') do set OTAVER=%%i
if %OTAVER%==D80010d GOTO ATTstockRoot
if %OTAVER%==D80010o GOTO ATTOTARoot
GOTO ATTNoMatch

:ATTstockRoot
echo Found ATT 10d!
echo Pushing g2_security...
echo.
.\adb.exe push g2_security /sdcard/g2_security
GOTO RootStep2

:ATTOTARoot
echo Found ATT w/10o OTA!
echo Pushing g2_security...
echo.
.\adb.exe push ytiruces_1a_att /sdcard/ytiruces_1a
GOTO RootStep2

:ATTNoMatch
echo.
echo.
echo We don't have an unlock for this OTA version yet.
echo Your phone is running %OTAVER% .
echo.
echo Please try the manual root method or

echo post your full device info in the thread
echo This program will now exit.
pause
exit

:TMORoot
echo Found TMO phone!
echo.
echo Checking OTA version...
for /f %%i in ('.\adb.exe shell getprop ro.lge.swversion') do set OTAVER=%%i
if %OTAVER%==D80110c GOTO TMOstockRoot
if %OTAVER%==D80110g GOTO TMOOTARoot
GOTO TMONoMatch

:TMOstockRoot
echo Found TMO 10c phone!
echo Pushing g2_security...
echo.
.\adb.exe push g2_security /sdcard/g2_security
GOTO RootStep2

:TMOOTARoot
echo Found TMO 10g phone!
echo Pushing ytiruces_1a...
echo.
.\adb.exe push ytiruces_1a_tmo /sdcard/ytiruces_1a
GOTO RootStep2

:TMONoMatch
echo.
echo.
echo We don't have an unlock for this ATT OTA version yet.
echo Your phone is running %OTAVER% .
echo.
echo Please try the manual root method or

echo post your full device info in the thread
echo This program will now exit.
pause
exit

:LGURoot
echo Found LGU phone!
echo.
echo Checking OTA version...
for /f %%i in ('.\adb.exe shell getprop ro.lge.swversion') do set OTAVER=%%i
if %OTAVER%==F320L10k GOTO LGUstockRoot
if %OTAVER%==F320L11g GOTO LGUOTARoot
if %OTAVER%==F320L11k GOTO LGUOTARoot
if %OTAVER%==F320L20b GOTO LGUKKRoot
if %OTAVER%==F320L20e GOTO LGUKKRoot
GOTO LGUNoMatch

:LGUstockRoot
echo Found F320l phone!
echo Pushing g2_security...
echo.
.\adb.exe push g2_security /sdcard/g2_security
GOTO RootStep2

:LGUOTARoot
echo Found LGU F320l phone!
echo Pushing ytiruces_1a ...
.\adb.exe push ytiruces_1a /sdcard/ytiruces_1a
GOTO RootStep2

:LGUKKRoot
echo Found LGU F320l phone!
echo Pushing ytiruces_1a ...
.\adb.exe push ytiruces_1a_kk /mnt/shell/emulated/0/ytiruces_1a
GOTO RootStep2

:LGUNoMatch
echo.
echo.
echo We don't have an unlock for this LGU OTA version yet.
echo Your phone is running %OTAVER% .
echo.
echo Please try the manual root method or

echo post your full device info in the thread
echo This program will now exit.
pause
exit

:SKTRoot
echo Found SKT phone!
echo.
echo Checking OTA version...
for /f %%i in ('.\adb.exe shell getprop ro.lge.swversion') do set OTAVER=%%i
if %OTAVER%==F320S10k GOTO SKTstockRoot
if %OTAVER%==F320S11g GOTO SKTOTARoot
if %OTAVER%==F320S11k GOTO SKTOTARoot
if %OTAVER%==F320S20a GOTO SKTKKRoot
if %OTAVER%==F320S20g GOTO SKTKKRoot
GOTO SKTNoMatch

:SKTstockRoot
echo Found SKT phone!
echo Pushing g2_security...
echo.
.\adb.exe push g2_security /sdcard/g2_security
GOTO RootStep2

:SKTOTARoot
echo Found SKT phone!
echo Pushing ytiruces_1a...
echo.
.\adb.exe push ytiruces_1a /sdcard/ytiruces_1a
GOTO RootStep2

:SKTKKRoot
echo Found SKT Kitkat phone!
echo Pushing ytiruces_1a...
echo.
.\adb.exe push ytiruces_1a_kk /mnt/shell/emulated/0/ytiruces_1a
GOTO RootStep2

:SKTNoMatch
echo.
echo.
echo We don't have an unlock for this SKT OTA version yet.
echo Your phone is running %OTAVER% .
echo.
echo Please try the manual root method or

echo post your full device info in the thread
echo This program will now exit.
pause
exit

:D802Root
echo Found D802 phone!
echo Pushing g2_security...
echo.
.\adb.exe push g2_security /sdcard/g2_security
GOTO RootStep2

:D802SCARoot
echo Found D802 phone!
echo Pushing g2_security...
echo.
.\adb.exe push g2_security /sdcard/g2_security
GOTO RootStep2

:SPRROOT
echo Found Sprint LS980 phone!
echo.
echo Checking OTA version...
for /f %%i in ('.\adb.exe shell getprop ro.lge.swversion') do set OTAVER=%%i
if %OTAVER%==LS980ZV7 GOTO SPRstockRoot
if %OTAVER%==LS980ZV8 GOTO SPRstockRoot
if %OTAVER%==LS980ZVA GOTO SPROTARoot
GOTO SPRNoMatch

:SPRstockRoot
echo Found SPR phone!
echo Pushing SPR g2_security...
.\adb.exe push g2_security_spr /sdcard/g2_security
GOTO RootStep2

:SPROTARoot
echo Found Sprint phone!
echo Pushing ls980 ytiruces_1a...
.\adb.exe push ytiruces_1a_ls980 /sdcard/ytiruces_1a
GOTO RootStep2

:SPRNoMatch
echo.
echo.
echo We don't have an unlock for this Sprint OTA version yet.
echo Your phone is running %OTAVER% .
echo.
echo Please try the manual root method or

echo post your full device info in the thread
echo This program will now exit.
pause
exit

:VZWRoot
echo Found VZW phone!
echo.
echo Checking OTA version...
for /f %%i in ('.\adb.exe shell getprop ro.lge.swversion') do set OTAVER=%%i
if %OTAVER%==VS98010B GOTO VZWStockRoot
if %OTAVER%==VS98011A GOTO VZWOTARoot
if %OTAVER%==VS98012B GOTO VZWOTARoot
GOTO VZWNoMatch

:VZWStockRoot
echo Found VS98010B VZW phone!
echo Pushing VZW g2_security...
.\adb.exe push g2_security_vzw /sdcard/g2_security
GOTO RootStep2

:VZWOTARoot
echo Found OTA VZW phone!
echo Pushing VZW ytiruces_1a ...
.\adb.exe push ytiruces_1a_vzw /sdcard/ytiruces_1a
GOTO RootStep2

:VZWNoMatch
echo.
echo.
echo We don't have an unlock for this Verizon OTA version yet.
echo Your phone is running %OTAVER% .
echo.
echo Please try the manual root method or

echo post your full device info in the thread
echo This program will now exit.
pause
exit

:KTRoot
echo Found KT phone!
echo.
echo Checking OTA version...
for /f %%i in ('.\adb.exe shell getprop ro.lge.swversion') do set OTAVER=%%i
if %OTAVER%==F320K10k GOTO KTstockRoot
if %OTAVER%==F320K11g GOTO KTOTARoot
if %OTAVER%==F320K11k GOTO KTOTARoot
if %OTAVER%==F320K20a GOTO KTKKRoot
if %OTAVER%==F320K20f GOTO KTKKRoot
GOTO KTNoMatch

:KTstockRoot
echo Found F320k phone!
echo Pushing g2_security...
echo.
.\adb.exe push g2_security /sdcard/g2_security
GOTO RootStep2

:KTOTARoot
echo Found KT F320k phone!
echo Pushing ytiruces_1a ...
.\adb.exe push ytiruces_1a /sdcard/ytiruces_1a
GOTO RootStep2

:KTKKRoot
echo Found KT F320k phone!
echo Pushing ytiruces_1a ...
.\adb.exe push ytiruces_1a_kk /mnt/shell/emulated/0/ytiruces_1a
GOTO RootStep2

:KTNoMatch
echo.
echo.
echo We don't have an unlock for this KT OTA version yet.
echo Your phone is running %OTAVER% .
echo.
echo Please try the manual root method or

echo post your full device info in the thread
echo This program will now exit.
pause
exit

:D803Root
echo Found D803 phone!
echo Pushing D803 ytiruces_1a ...
.\adb.exe push ytiruces_1a_d803 /sdcard/ytiruces_1a
GOTO RootStep2

:StockJBRoot
echo Found phone!
echo Pushing g2_security...
echo.
.\adb.exe push g2_security /sdcard/g2_security
GOTO RootStep2

:F340JBRoot
echo F340 Found!
echo Pushing ytiruces_1a...
echo.
.\adb.exe push ytiruces_1a_F340JB /sdcard/ytiruces_1a
GOTO RootStep2

:GFlexJBRoot
echo LG G Flex Found!
echo Pushing ytiruces_1a...
echo.
.\adb.exe push ytiruces_1a_kk /sdcard/ytiruces_1a
GOTO RootStep2

:D950Root
echo LG G Flex Found!
echo Pushing ytiruces_1a...
echo.
.\adb.exe push ytiruces_1a_d950 /sdcard/ytiruces_1a
GOTO RootStep2

:D959Root
echo LG D959 G Flex Found!
echo Pushing ytiruces_sumtz...
echo.
.\adb.exe push ytiruces_sumtz /sdcard/ytiruces_sumtz
GOTO RootStep2

:LS995Root
echo LG G Flex Found!
echo Pushing ytiruces_1a...
echo.
.\adb.exe push ytiruces_1a_ls995 /sdcard/ytiruces_1a
GOTO RootStep2

:LGOGRoot
echo Found a LG Optimus G!

echo Creating G_security...
echo.

.\adb.exe shell "echo -en \\\x0d > /sdcard/G_security"
GOTO 8064Part2

:8064Part2
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo ********************************************************

echo This next depends on your computer/phone model...
echo.
echo USB Connection Mode needs to be toggled.
echo Ways to do this are listed below...
echo.
echo 1. Unplug usb cable from phone then re-plug.
echo 2. Toggle USB mode from Charge to MTP back to Charge
echo.
echo.
echo Then press ENTER to confirm ADB root...
echo ********************************************************
pause
echo Waiting for device...
.\adb.exe wait-for-device
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo *******************************************************
.\adb.exe root

.\adb.exe shell "id"

echo.
echo If you do NOT see uid=0(root) gid=0(root) above then 
echo it is likely your device firmware is not supported or 
echo USB mode was not toggled properly. You can try to
echo run the script again or..
echo PRESS CTRL+c to stop this script...
echo.

echo If you DO see uid=0(root) gid=0(root) mentioned above...
echo CONGRATS.. Rooted ADB is now confirmed.
echo You will have a rooted ADB shell but no apps on the
echo phone will
 be able to access root functions.

echo PRESS ENTER to backup EFS and continue with full root.
echo *******************************************************
pause
echo.
echo.
echo Backing up EFS...

.\adb.exe shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/m9kefs1 of=/sdcard/m9kefs1.img"

.\adb.exe shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/m9kefs1 of=/sdcard/m9kefs2.img"

.\adb.exe shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/m9kefs1 of=/sdcard/m9kefs3.img"

.\adb.exe pull /sdcard/m9kefs1.img

.\adb.exe pull /sdcard/m9kefs2.img

.\adb.exe pull /sdcard/m9kefs3.img
echo ***************************************************
echo EFS partitions now in ioroot folder on computer...
echo They're named m9kefs1.img, m9kefs2.img and m9kefs3.img
echo.
echo.
echo They will come in handy in case of an emergency.
echo Store them somewhere you won't lose them.
echo.
echo Press ENTER to continue with full root.
echo ***************************************************
pause
echo.
echo Mounting system, pushing su binary and installing SuperSu...
.\adb.exe push busybox /data/local/tmp/busybox

.\adb.exe shell "chmod 755 /data/local/tmp/busybox"

.\adb.exe shell "/data/local/tmp/busybox mount -o remount,rw /system"

.\adb.exe shell "/data/local/tmp/busybox cp /data/local/tmp/busybox /system/xbin/busybox"

.\adb.exe push su /system/xbin/su

.\adb.exe push Superuser.apk /system/app/Superuser.apk

.\adb.exe shell "chown 0.0 /system/xbin/su && chmod 06755 /system/xbin/su && chmod 655 /system/app/Superuser.apk && chmod 755 /system/xbin/busybox"

echo Rebooting Phone.
.\adb.exe reboot
echo ***************************************************

echo ***************************************************
echo You should hopefully now be fully rooted!!
echo.
echo IOroot complete.
echo.
echo Confirm root with Root Checker app from Play Store.

echo ***************************************************

echo ***************************************************
pause
exit

:RootStep2
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo ********************************************************

echo This next depends on your computer/phone model...
echo.
echo USB Connection Mode needs to be toggled.
echo Ways to do this are listed below...
echo.
echo 1. Unplug usb cable from phone then re-plug.
echo 2. Toggle USB mode from Charge to MTP back to Charge
echo 3. Toggle USB mode from Ethernet to MTP back to Ethernet(VZW users)
echo.
echo.
echo Then press ENTER to confirm ADB root...
echo ********************************************************
pause
echo Waiting for device...
.\adb.exe wait-for-device
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo *******************************************************
.\adb.exe root

.\adb.exe shell "id"

echo.
echo If you do NOT see uid=0(root) gid=0(root) above then 
echo it is likely your device firmware is not supported or 
echo USB mode was not toggled properly. You can try to
echo run the script again or..
echo PRESS CTRL+c to stop this script...
echo.

echo If you DO see uid=0(root) gid=0(root) mentioned above...
echo CONGRATS.. Rooted ADB is now confirmed.
echo You will have a rooted ADB shell but no apps on the
echo phone will
 be able to access root functions.

echo PRESS ENTER to backup EFS and continue with full root.

echo.

echo PLEASE NOTE!

echo Continuing with full root can trip LG's rootchecker.

echo This means your phone will show ROOTED in Download mode.

echo You can remove root flag by flashing stock firmware...

echo .bin .cab .tot or .kdz

echo.

echo If you do not want to possibly invalidate your warranty

echo press CTRL+c to stop this script...
echo *******************************************************
pause
echo.
echo.
echo Backing up EFS...

.\adb.exe shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/modemst1 of=/sdcard/modemst1.img"

.\adb.exe shell "dd if=/dev/block/platform/msm_sdcc.1/by-name/modemst2 of=/sdcard/modemst2.img"

.\adb.exe pull /sdcard/modemst1.img

.\adb.exe pull /sdcard/modemst2.img
echo ***************************************************
echo EFS partitions now in ioroot folder on computer...
echo They are named modemst1.img and modemst2.img
echo.
echo.
echo They will come in handy in case of an emergency.
echo Store them somewhere you won't lose them.
echo.
echo Press ENTER to continue with full root.
echo ***************************************************
pause
echo.
echo Mounting system, pushing su binary and installing SuperSu...
.\adb.exe push busybox /data/local/tmp/busybox

.\adb.exe shell "chmod 755 /data/local/tmp/busybox"

.\adb.exe shell "/data/local/tmp/busybox mount -o remount,rw /system"

.\adb.exe shell "/data/local/tmp/busybox cp /data/local/tmp/busybox /system/xbin/busybox"

.\adb.exe push su /system/xbin/daemonsu

.\adb.exe shell "/data/local/tmp/busybox cp /system/xbin/daemonsu /system/xbin/su"
.\adb.exe push install-recovery.sh /system/etc/install-recovery.sh

.\adb.exe push Superuser.apk /system/app/Superuser.apk

.\adb.exe shell "chown 0.0 /system/xbin/su && chmod 06755 /system/xbin/su && chown 0.0 /system/xbin/daemonsu && chmod 06755 /system/xbin/daemonsu && chown 0.2000 /system/etc/install-recovery.sh && chmod 755 /system/etc/install-recovery.sh && chmod 655 /system/app/Superuser.apk && chmod 755 /system/xbin/busybox"

echo Rebooting Phone.
.\adb.exe reboot
echo ***************************************************

echo ***************************************************
echo You should hopefully now be fully rooted!!
echo.
echo IOroot complete.
echo.
echo Confirm root with Root Checker app from Play Store.

echo ***************************************************

echo ***************************************************
pause
exit