@ECHO OFF
mode con cols=66
TITLE 维酷刷机工具箱 加载中...


:RESTART
CLS
ECHO.检查程序定位是否正确...
cd /D %~dp0\bin
if not exist driver_fastbootd.exe COLOR 4F & ECHO. & ECHO.程序定位错误！请将程序完全解压后运行！ & pause>nul & EXIT
ECHO.检查路径...
echo.%cd%>log\programpath.log
for /f "tokens=1 delims= " %%i in ('findstr "bin" log\programpath.log') do set programpath=%%i
del log\programpath.log 1>nul 2>nul
if not exist %programpath%\chkconnect_syxz.bat COLOR 4F & ECHO. & ECHO.工具箱路径中有特殊字符（如空格、英文括号等）。请将工具箱放置在没有特殊字符的路径中，否则无法正常运行。 & pause>nul & EXIT
CLS & type logo.txt
ECHO.检查电脑系统能否执行FINDSTR指令...
for /f "tokens=2 delims= " %%i in ('findstr "@ECHO" chkconnect_syxz.bat') do set target=%%i
if not "%target%"=="OFF" COLOR 4F & ECHO. & ECHO.你的电脑系统不能执行FINDSTR指令，无法继续。 & pause>nul & EXIT
CLS & type logo.txt
ECHO.检查电脑系统能否执行MSG指令...
msg 1>nul 2>nul
if not "%errorlevel%"=="0" COLOR 0C & ECHO. & ECHO.你的电脑系统不能执行MSG指令，这将导致你无法收到程序的部分通知，比如升级提示等。但你仍然可以使用工具箱。按任意键继续。 & pause>nul
COLOR 0E
CLS & type logo.txt
ECHO.加载配置...
if not exist log\model_sel.txt echo.blank>log\model_sel.txt
for /f %%i in (log\model_sel.txt) do set model=%%i>nul
call viqoo_config.bat
TITLE 维酷刷机工具箱 %program_ver% by 酷安@某贼
CLS & type logo.txt
ECHO.启动后台检查更新...
start chkupdate.vbs
goto START

:START
CLS
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHOC {0E}                   维酷刷机工具箱 by 酷安@某贼{\n}
ECHOC {0E}                                                        %program_ver%{\n}
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHOC {0E}                     欢迎使用维酷刷机工具箱！{\n}
ECHO.
ECHOC {0E}     工具箱永久免费，禁止商用，禁止未经许可的二改、打包、加密。{\n}
ECHO. 
ECHO. 
if not "%model%"=="blank" ECHOC {0E}  【%model%】{\n}
if "%model%"=="blank" ECHOC {0C} 你尚未选择型号！建议先选择型号以获得最佳体验。{\n}
ECHO.
ECHO.
ECHOC {0F}
ECHOC {0E} 1.{0F}开始解锁BL{\n}
ECHO.
ECHO. 2.Root系统
ECHO.
ECHO. 3.移除Root
ECHO.
ECHO. 4.刷入自定义分区
ECHO.
ECHO. 5.实用工具
ECHO.
ECHO. 6.选择/更改你的型号
ECHO.
ECHO. 7.检查更新
ECHO.
ECHO. 8.讨论反馈群
ECHO.
ECHO. 9.清理使用记录
ECHO.
ECHO.
ECHOC {0E}
set choice=0
set /p choice= 输入序号按Enter继续：
if "%choice%"=="1" goto UNLOCK
if "%choice%"=="2" set command=root& goto ROOT
if "%choice%"=="3" set command=unroot& goto ROOT
if "%choice%"=="4" goto FLASHIMG
if "%choice%"=="5" goto TOOLS
if "%choice%"=="6" goto CHOOSEDEV
if "%choice%"=="7" goto CHKUPDATE
if "%choice%"=="8" ECHO. & ECHO.群号：735532054 & ECHO. & ECHO.按任意键返回。 & pause>nul
if "%choice%"=="9" goto CLEAN
goto START


:FLASHIMG
CLS
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHOC {0E}                          刷入自定义分区{\n}
ECHO.
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHO.
ECHO. 1.刷入Boot
ECHO.
ECHO. 2.刷入Recovery
ECHO.
ECHO. 3.刷入System
ECHO.
ECHO. 4.刷入Vendor
ECHO.
ECHO. 5.刷入其他
ECHO.
ECHO. A.返回主菜单（默认）
ECHO.
ECHO.
ECHOC {0E}
set choice=A
set /p choice= 输入序号按Enter继续：
if "%choice%"=="A" goto START
if "%choice%"=="a" goto START
if "%choice%"=="1" set target=boot& goto FLASHIMG-START
if "%choice%"=="2" set target=recovery& goto FLASHIMG-START
if "%choice%"=="3" set target=system& goto FLASHIMG-START
if "%choice%"=="4" set target=vendor& goto FLASHIMG-START
if "%choice%"=="5" goto FLASHIMG-CUSTOM
goto FLASHIMG
:FLASHIMG-CUSTOM
ECHOC {0E}
ECHO.
set target=blank
set /p target= 请输入你想刷入的分区名（必须准确）：
if "%target%"=="blank" goto FLASHIMG-CUSTOM
goto FLASHIMG-START
:FLASHIMG-START
ECHOC {0E}
ECHO.
set /p imgpath= 请将分区img文件拖到此处，然后按Enter继续：
echo.%imgpath%>log\pathchk.log
find ".img" "log\pathchk.log" 1>nul 2>nul
if not "%errorlevel%"=="0" ECHOC {0C}你选择的不是img文件！{\n} & goto FLASHIMG-START
ECHO.
ECHOC {0E}请长按电源键和音量加，将手机进入Fastboot模式。{\n}
ECHOC {0F}检查Fastboot连接...{\n}
set choice_syxz=Fastboot
call chkconnect_syxz.bat %choice_syxz%
if "%result_syxz%"=="0" ECHO.设备已连接！
if "%result_syxz%"=="1" ECHOC {0C}检查设备连接失败！ & pause>nul & goto FLASHIMG
if "%result_syxz%"=="2" ECHOC {0C}有多个设备连接！请断开其他设备！ & pause>nul & goto FLASHIMG
if "%result_syxz%"=="3" ECHOC {0C}未知错误！ & pause>nul & goto FLASHIMG
ECHOC {07}
fastboot flash %target% %imgpath%
ECHO.
ECHOC {0E}刷入完成，请自行查验是否成功。按任意键回主菜单。
pause>nul
goto START


:CHKUPDATE
ECHOC {07}
del log\update.txt
cd ..
copy bin\update.bat .\ 1>nul
start update.bat
cd /D %~dp0\bin
goto START
CLS


:TOOLS
CLS
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHOC {0E}                             实用工具{\n}
ECHO.
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHO.
ECHO. 1.AFTool（vivo售后刷机工具，此版本亲测可用）
ECHO.
ECHO. 2.vivo系统降级工具
ECHO.
ECHO. 3.校正指纹APP
ECHO.
ECHO. 4.回主菜单
ECHO.
ECHO.
ECHOC {0E}
set choice=
set /p choice= 输入序号按Enter继续：
if "%choice%"=="1" start https://share666-my.sharepoint.com/:f:/g/personal/share666_share666_onmicrosoft_com/EnycEZAcvEFPtvVqVf18PsYBMuf2NtQ7orqzmuKbh0N-LA?e=7t3ub7
if "%choice%"=="2" start https://share666-my.sharepoint.com/:f:/g/personal/share666_share666_onmicrosoft_com/EnycEZAcvEFPtvVqVf18PsYBMuf2NtQ7orqzmuKbh0N-LA?e=7t3ub7
if "%choice%"=="3" goto FPFIX
if "%choice%"=="4" goto START
goto TOOLS


:FPFIX
CLS
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHOC {0E}                           校正指纹{\n}
ECHO.
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHO.
ECHOC {0E}将向手机推送指纹校正APP安装包。请将手机开机连接电脑，开启USB调试。{\n}
ECHO.
ECHOC {0F}正在等待设备连接(系统)...{\n}
set choice_syxz=系统
call chkconnect_syxz.bat %choice_syxz%
if "%result_syxz%"=="0" ECHO.设备已连接！
if "%result_syxz%"=="1" ECHOC {0C}检查设备连接失败！ & pause>nul & goto START
if "%result_syxz%"=="2" ECHOC {0C}有多个设备连接！请断开其他设备！ & pause>nul & goto START
if "%result_syxz%"=="3" ECHOC {0C}未知错误！ & pause>nul & goto START
ECHOC {0F}正在推送APK...{\n}
ECHOC {07}
adb push FingerprintEngineer.apk ./sdcard/ 1>nul 2>log\adbpush.log
ECHO.
if not "%errorlevel%"=="0" start log\adbpush.log & ECHOC {0C}推送失败！按任意键返回主菜单。 & pause>nul & goto START
ECHOC {0E}APK已推送到内部存储根目录！请打开文件管理找到并安装。按任意键返回主菜单。
pause>nul
goto START


:ROOT
rd/s/q "boot" 1>nul 2>nul
md boot
CLS
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
if "%command%"=="root" ECHOC {0E}                             Root系统{\n}
if "%command%"=="unroot" ECHOC {0E}                             移除Root{\n}
ECHO.
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHO.
if "%model%"=="blank" ECHOC {0C} 请先选择型号再使用此功能。按任意键返回主菜单。 & pause>nul & goto START
if "%command%"=="root" ECHOC {0E} 刷入面具修补过的Boot.img以Root系统。{\n}
if "%command%"=="unroot" ECHOC {0E} 刷入官方原版Boot.img以移除Root。{\n}
ECHO.
ECHOC {0F} 你选择的型号为【{0E}%model%{0F}】。{\n}
ECHO.
ECHOC {0F} 请准确输入你的系统版本号，比如2.8.4。{\n}
ECHO.
ECHOC {0E}
set sysver=blank
set /p sysver= 版本号：
if "%sysver%"=="blank" goto ROOT
ECHO.
ECHOC {0F}正在联网获取【{0E}%model%{0F}】{0E}%sysver%{0F} 版本的Boot...{\n}
if "%command%"=="root" aria2c.exe --max-concurrent-downloads=16 --max-connection-per-server=16 --split=16 --dir=boot %dlsource%/boot/%model%/%sysver%.7z | find "download completed." 1>nul 2>nul
if "%command%"=="unroot" aria2c.exe --max-concurrent-downloads=16 --max-connection-per-server=16 --split=16 --dir=boot %dlsource%/boot/%model%/%sysver%-official.7z | find "download completed." 1>nul 2>nul
if "%command%"=="unroot" ren boot\%sysver%-official.7z %sysver%.7z 1>nul 2>nul
if not exist boot\%sysver%.7z ECHOC {0C}下载失败！按任意键返回。 & pause>nul & goto START
find "found" "boot\%sysver%.7z" | find ":500," 1>nul 2>nul
if "%errorlevel%"=="0" ECHO. & ECHOC {0C}找不到该版本的Boot！按任意键返回。 & pause>nul & goto ROOT
ECHOC {0F}解压中...{\n}
md boot\%sysver% 1>nul 2>nul
ECHOC {0C}
move boot\%sysver%.7z boot\%sysver% 1>nul
copy 7z.exe boot\%sysver% 1>nul
copy 7z.dll boot\%sysver% 1>nul
cd boot\%sysver%
7z.exe e "%sysver%.7z" 1>nul 2>nul
if not "%errorlevel%"=="0" ECHOC {0C}解压出错！按任意键返回。 & pause>nul & goto ROOT
cd /D %~dp0\bin
for /f %%i in (boot\%sysver%\magiskver.txt) do set magiskver=%%i>nul
if "%command%"=="root" ECHOC {0F}面具版本：{0E}%magiskver%{0F}。{\n}
ECHO.
ECHOC {0E}请将手机关机连接电脑，长按电源键和音量加进入Fastboot模式。{\n}
ECHOC {0F}正在检查设备连接...{\n}
set choice_syxz=Fastboot
call chkconnect_syxz.bat %choice_syxz%
if "%result_syxz%"=="0" ECHO.设备已连接！
if "%result_syxz%"=="1" ECHOC {0C}检查设备连接失败！ & pause>nul & goto ROOT
if "%result_syxz%"=="2" ECHOC {0C}有多个设备连接！请断开其他设备！ & pause>nul & goto ROOT
if "%result_syxz%"=="3" ECHOC {0C}未知错误！ & pause>nul & goto ROOT
ECHOC {0F}检查解锁状态...{\n}
fastboot getvar all 1>nul 2>log\fbgetvar.log
find "bootloader" "log\fbgetvar.log" 1>nul 2>nul
if not "%errorlevel%"=="0" ECHOC {0C}Fastboot读取设备信息失败！请检查连接或进群反馈。 & pause>nul & goto START
find "unlocked:yes" "log\fbgetvar.log" 1>nul 2>nul
if not "%errorlevel%"=="0" ECHOC {0C}你的设备尚未解锁！请先解锁再使用此功能。按任意键回主菜单。 & pause>nul & goto START
ECHOC {0F}刷入Boot...{\n}
fastboot flash boot boot/%sysver%/boot.img 1>nul 2>log\flashboot.log
find "FAILED" "log\flashboot.log" 1>nul 2>nul
if "%errorlevel%"=="0" start log\flashboot.log & ECHOC {0C}刷入失败！按任意键返回。 & pause>nul & goto ROOT
if "%command%"=="root" ECHOC 刷入成功！开机后自行安装Magisk软件即可获取Root权限。按任意键返回主菜单。
if "%command%"=="unroot" ECHO.刷入成功！开机后自行卸载Magisk软件即可彻底移除Root。按任意键返回主菜单。
pause>nul
rd/s/q "boot" 1>nul 2>nul
md boot
goto START


:CHOOSEDEV
del log\model.*
CLS
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHOC {0E}                          选择/更改型号{\n}
ECHO.
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHO.
ECHOC {0E}正在联网获取支持的型号列表...{\n}
aria2c.exe --max-concurrent-downloads=16 --max-connection-per-server=16 --split=16 --dir=log %dlsource%/model.txt | find "download completed." 1>nul 2>nul
if not "%errorlevel%"=="0" ECHOC {0C}下载失败！按任意键返回主菜单。 & pause>nul & goto START
find "found" "log\model.txt" | find ":500," 1>nul 2>nul
if "%errorlevel%"=="0" ECHOC {0C}找不到云端文件！请联系开发者（QQ1330250642）。按任意键返回主菜单。 & pause>nul & goto START
CLS
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHOC {0E}                          选择/更改型号{\n}
ECHO.
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHO.
ECHOC {0E} 不同型号使用的资源不同，请务必认真选择。{\n}
ECHOC {0F} 注：iQOO1不等于iQOOZ1，X60ProPlus不等于X60TProPlus。{\n}
ECHO. 
ECHO. 
ECHOC {0F}
set num1=1
:CHOOSEDEV-1
find "【设备%num1%】" "log\model.txt" 1>nul 2>nul
if not "%errorlevel%"=="0" goto CHOOSEDEV-2
for /f "tokens=2 delims= " %%i in ('findstr "【设备%num1%】" log\model.txt') do set name1=%%i
ECHO.%num1%.%name1%
set /a num1+=1
goto CHOOSEDEV-1
:CHOOSEDEV-2
ECHO.
ECHOC {0F}A.保持现状返回主菜单（默认）{\n}
ECHO.
ECHOC {0E}
set choice=A
set /p choice= 输入数字按Enter继续：
if "%choice%"=="A" goto START
if "%choice%"=="a" goto START
find "【设备%choice%】" "log\model.txt" 1>nul 2>nul
if not "%errorlevel%"=="0" goto CHOOSEDEV
for /f "tokens=2 delims= " %%i in ('findstr "【设备%choice%】" log\model.txt') do set model=%%i
echo.%model%>log\model_sel.txt
goto START


:UNLOCK
CLS
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHOC {0E}                            解锁BL锁{\n}
ECHO.
ECHOC {0F}=---------------------------------------------------------------={\n}
ECHO.
ECHO.
ECHOC {0E}- 确定要解锁BL锁么？解锁刷机可能造成以下影响：{\n}
ECHOC {0F}
ECHO.  手机数据被清空
ECHO.  手机系统损坏无法开机
ECHO.  基带丢失
ECHO.  失去保修
ECHO.  光学指纹失效
ECHO.  ...
ECHOC {0E}  了解以上内容，请按任意键继续。{\n}
pause>nul
ECHO.  
ECHOC {0E}- 解锁BL锁会清空手机内{0C}所有数据{0E}！！！{\n}
ECHOC {0F}  请确认数据已自行备份到手机之外！{\n}
ECHOC {0E}  请退出其他手机管理和刷机软件，然后按任意键开始...{\n}
pause>nul
ECHO.  
ECHOC {0E}- [安装驱动]{\n}
if exist log\drvinstalled.txt ECHOC {07}  已安装过驱动，跳过此步，如需安装请打开bin\driver_fastbootd.exe{\n}& goto CHK
start driver_fastbootd.exe
ECHOC {0F}  驱动安装完成后请按任意键继续...{\n}
pause>nul
echo.已安装驱动>log\drvinstalled.txt
:CHK
ECHOC {0E}- [检查ADB能否运行]{\n}
adb devices 1>log\adb.log 2>nul
find "attached" log\adb.log 1>nul 2>nul
if not "%errorlevel%"=="0" ECHOC {0C}  ADB无法正常运行！ & pause>nul & goto START
ECHOC {0E}- [检查Fastboot能否运行]{\n}
fastboot 1>nul 2>log\fb.log
find "commands" log\fb.log 1>nul 2>nul
if not "%errorlevel%"=="0" ECHOC {0C}  Fastboot无法正常运行！ & pause>nul & goto START
ECHOC {0E}- 请按以下步骤操作：{\n}
ECHOC {0F}
ECHO.  请将手机开机并连接电脑，启用开发者选项
ECHO.  打开【OEM解锁】与【USB调试】开关
ECHO.  如果出现USB调试提示，请勾选一律允许并确认。
ECHO.  完成后按任意键继续...
pause>nul
ECHOC {0E}- [检查设备连接]{\n}
ECHOC {0F}  正在等待设备连接(系统)...{\n}
set choice_syxz=系统
call chkconnect_syxz.bat %choice_syxz%
if "%result_syxz%"=="0" ECHO.  设备已连接！
if "%result_syxz%"=="1" ECHOC {0C}  检查设备连接失败！ & pause>nul & goto START
if "%result_syxz%"=="2" ECHOC {0C}  有多个设备连接！请断开其他设备！ & pause>nul & goto START
if "%result_syxz%"=="3" ECHOC {0C}  未知错误！ & pause>nul & goto START
TIMEOUT /T 1 /NOBREAK>nul
ECHOC {0E}- [重启到Fastboot]{\n}
adb reboot bootloader 1>nul 2>nul
if not "%errorlevel%"=="0" ECHOC {0C}  重启设备失败！请关机后长按电源键和音量加，手动进入Fastboot。{\n}
ECHOC {0E}- [检查设备连接]{\n}
ECHOC {0F}  正在等待设备连接(Fastboot)...{\n}
set choice_syxz=Fastboot
call chkconnect_syxz.bat %choice_syxz%
if "%result_syxz%"=="0" ECHO.  设备已连接！
if "%result_syxz%"=="1" ECHOC {0C}  检查设备连接失败！ & pause>nul & goto START
if "%result_syxz%"=="2" ECHOC {0C}  有多个设备连接！请断开其他设备！ & pause>nul & goto START
if "%result_syxz%"=="3" ECHOC {0C}  未知错误！ & pause>nul & goto START
TIMEOUT /T 1 /NOBREAK>nul
ECHOC {0E}- [检查解锁状态]{\n}
fastboot getvar all 1>nul 2>log\fbgetvar.log
find "bootloader" "log\fbgetvar.log" 1>nul 2>nul
if not "%errorlevel%"=="0" ECHOC {0C}  Fastboot读取设备信息失败！请检查连接。 & pause>nul & goto START
find "unlocked:yes" "log\fbgetvar.log" 1>nul 2>nul
if "%errorlevel%"=="0" ECHOC {0A}  你的设备已经解锁，无需重复解锁。按任意键回主菜单。 & pause>nul & goto START
:FLASHVENDOR
ECHOC {0E}- [刷入Vendor]{\n}
ECHOC {0F}  正在刷入Vendor，这需要一段时间，请稍候...{\n}
fastboot flash vendor vendor.img 1>nul 2>log\flashvendor.log
find "FAILED" "log\flashvendor.log" 1>nul 2>nul
if not "%errorlevel%"=="0" start log\flashvendor.log & ECHOC {0C}  刷入失败！按任意键重试... & pause>nul & goto FLASHVENDOR
:UNLOCK
ECHOC {0E}- [执行解锁指令]{\n}
fastboot vivo_bsp unlock_vivo 1>nul 2>log\unlock.log
find "FAILED" "log\unlock.log" 1>nul 2>nul
if "%errorlevel%"=="0" start log\unlock.log & ECHOC {0C}  解锁失败！按任意键重试... & pause>nul & goto UNLOCK
ECHO.  
ECHOC {0A}  恭喜，解锁成功！{\n}
ECHOC {0F}
ECHO.
ECHO.  稍后开机会提示清除数据，按提示操作即可。
ECHO.  开机后提示系统数据空间损坏属正常现象。
ECHO.  重新上锁BL可能导致严重问题，永远不建议重新上锁。
ECHO.  工具箱由某 贼制作，永久免费，禁止商用。按任意键返回主菜单。
pause>nul
goto START


:CLEAN
ECHOC {07}
taskkill /f /im 7z.exe 1>nul 2>nul
taskkill /f /im aria2c.exe 1>nul 2>nul
taskkill /f /im adb.exe 1>nul 2>nul
taskkill /f /im fastboot.exe 1>nul 2>nul
rd/s/q "boot" 1>nul 2>nul
md boot
rd/s/q "log" 1>nul 2>nul
md log
goto RESTART