-
Notifications
You must be signed in to change notification settings - Fork 12
/
EDLUnlock.cmd
156 lines (141 loc) · 3.85 KB
/
EDLUnlock.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
@ECHO OFF
CD /D "%~dp0" >nul
SET THISBAT=%~0
SET THISPATH=%~dp0
IF "%~1" == "-hex" (
REM Work-around for calling batch-label inside a for loop
CALL :DecToHex "%~2"
EXIT /B %ERRORLEVEL%
)
SETLOCAL enableextensions enabledelayedexpansion
SET ERROR=0
:: Rotate log
IF EXIST log.txt (
IF EXIST log.previous.txt (
DEL log.previous.txt
)
MOVE log.txt log.previous.txt
)
CALL :CLEAR_TITLE
:: load config
ECHO [#] Reading configured COM port...
CALL :READ_CONFIG_INI COMPort CONFIG_COMPORT
ECHO %CONFIG_COMPORT%
ECHO [#] Reading configured Firehose loader binary path...
CALL :READ_CONFIG_INI FirehoseLoader CONFIG_LOADER
ECHO %CONFIG_LOADER%
ECHO [#] Reading configured transfer speed...
CALL :READ_CONFIG_INI TransferSpeed CONFIG_SPEED
ECHO %CONFIG_SPEED%
ECHO.
:MAIN_MENU
ECHO [i] Make your choice:
ECHO.
ECHO 1) Unlock your device
ECHO.
ECHO 2) Reboot (exit EDL mode)
ECHO.
ECHO 3) Quit
ECHO.
ECHO.
SET CHOICE_MAIN=
SET /P CHOICE_MAIN="[#] Enter number: "
ECHO.
IF "%CHOICE_MAIN%"=="1" (
CALL :CHOICE_UNLOCK
) ELSE IF "%CHOICE_MAIN%"=="2" (
CALL :CHOICE_REBOOT
) ELSE IF "%CHOICE_MAIN%"=="3" (
EXIT /B
) ELSE (
ECHO [^^!] Invalid option.
)
:ERROR_END
SET ERROR=0
REM clean the log file
IF EXIST "%THISPATH%\log.txt" (
FINDSTR /V "Sectors remaining " "%THISPATH%\log.txt" > "%THISPATH%\log.clean.txt"
MOVE /Y "%THISPATH%\log.clean.txt" "%THISPATH%\log.txt" >nul
)
ECHO [i] Press any key to return to main menu.
PAUSE>NUL
CALL :CLEAR_TITLE
GOTO :MAIN_MENU
:ERROR
ECHO.
ECHO [^^!] An error occured. %~1. Check device connection and COM port is correct.
ECHO [^^!] See log.txt for details.
ECHO.
GOTO :EOF
:CHOICE_REBOOT
ECHO [#] Press any key to exit EDL mode.
PAUSE>NUL
"%THISPATH%\bin\emmcdl.exe" -p %CONFIG_COMPORT -r
IF ERRORLEVEL 1 (
CALL :ERROR "Unable to exit EDL mode!"
GOTO :ERROR_END
)
ECHO.
ECHO [i] All done^^!
GOTO :EOF
:CHOICE_UNLOCK
SET CHOICE_BACKUPPATH="bin"
CALL :RESTORE_VERIFY_PATH !CHOICE_BACKUPPATH!
IF "!ERROR!"=="1" (
ECHO [^^!] Missing rawprogram0.xml! Did you download correctly everything?
GOTO :ERROR_END
)
REM Verified, go!
ECHO [#] Press any key to start the unlock process.
ECHO [#] This may take some time.
ECHO [#] All output will be in the window [not the log] to show progress.
PAUSE>NUL
CD /D !CHOICE_BACKUPPATH!
"%THISPATH%\bin\emmcdl.exe" -p %CONFIG_COMPORT% -f "%THISPATH%\%CONFIG_LOADER%" -x "!CD!\rawprogram0.xml" -MaxPayloadSizeToTargetInBytes %CONFIG_SPEED%
IF ERRORLEVEL 1 (
CALL :ERROR "Unlock Failed!"
GOTO :ERROR_END
)
ECHO.
ECHO [i] All done^^!
CD /D "%THISPATH%"
GOTO :EOF
:RESTORE_VERIFY_PATH
IF NOT EXIST "bin\rawprogram0.xml" (
SET ERROR=1
GOTO :EOF
)
GOTO :EOF
REM Thanks to emuzychenko for this batch wizardry
:DecToHex
SETLOCAL enabledelayedexpansion
SET DecNum=%~1
SET DigTable=0123456789abcdef
SET HexRes=
:DecToHex_Loop
SET /A DecNumQ=%DecNum% / 16
SET /A DecRmd=%DecNum% - %DecNumQ% * 16
SET DecNum=%DecNumQ%
SET HexDig=!DigTable:~%DecRmd%,1!
SET HexRes=%HexDig%%HexRes%
IF %DecNum% NEQ 0 GOTO :DecToHex_Loop
ECHO %HexRes%
ENDLOCAL
GOTO :EOF
:CLEAR_TITLE
CLS
ECHO --------------------------------------------------------
ECHO - Mi A1 EDL Unlock Tool -
ECHO - -
ECHO - By Giovix92@XDA -
ECHO - Based on CosmicDan's Mi A1 Low-Level Flasher -
ECHO - Based on EMMCDL scripts thanks to @emuzychenko -
ECHO --------------------------------------------------------
ECHO.
ECHO.
GOTO :EOF
:: Credits to emil @ StackOverflow - https://stackoverflow.com/a/4518146/1767892
:: Syntax - CALL :READ_CONFIG_INI [INI_KEYNAME] [BAT_VARNAME]
:READ_CONFIG_INI
FOR /F "tokens=2 delims==" %%k IN ('find "%~1=" config.ini') DO SET %~2=%%k
GOTO :EOF