-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathHuawei Hacker Toolkit.au3
523 lines (500 loc) · 22.8 KB
/
Huawei Hacker Toolkit.au3
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_type=a3x
#AutoIt3Wrapper_Outfile=Release\Huawei Hacker Toolkit.a3x
#AutoIt3Wrapper_Run_After=move "%out%" "Release\Script.scr"
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;~ #AutoIt3Wrapper_Icon=Icon.ico
;~ #AutoIt3Wrapper_Res_Description=Huawei Hacker Toolkit
;~ #AutoIt3Wrapper_Res_Fileversion=1.3.0.0
;~ #AutoIt3Wrapper_Res_LegalCopyright=Copyright © 2014 Kyaw Swar Thwin
;~ #AutoIt3Wrapper_Res_Language=1033
#include "Include\Android.au3"
#include "Include\Busy.au3"
#include "Include\CRC.au3"
#include "Include\Hex.au3"
#include "Include\UPDATEAPP.au3"
#include <Array.au3>
#include <Crypt.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include "MCFinclude.au3"
#include "Include\Registration.au3"
Global Const $sAppName = "Huawei Hacker Toolkit"
Global Const $sAppVersion = "1.4"
Global Const $sAppPublisher = "Kyaw Swar Thwin"
Global Const $sAppURL = "http://huaweihackertoolkit.nazuka.net"
Global Const $vPrivateKey = Binary("0x5D744568B606B05925AA26F8FD75392AFF9EE47A2B544C52027612F218CD9D1A")
Global Const $DBT_DEVNODES_CHANGED = 0x0007
Global Const $dSignature1 = Binary("0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
Global Const $tagHEADER = _
"byte Signature[4];" & _
"dword HeadSize;" & _
"dword Version;" & _
"char Device[8];" & _
"dword Sequence;" & _
"dword BodySize;" & _
"char Date[16];" & _
"char Time[16];" & _
"char Type[16];" & _
"byte Reserved1[16];" & _
"align 2;word CRC;" & _
"align 2;word Unknown;" & _
"byte Reserved2[2]"
Global Const $dSignature2 = Binary("0x55AA5AA5")
Global $sTitle = $sAppName
Global $sDeviceState, $sManufacturer, $sModelNumber, $sDeviceID, $bRootAccess
If Not @Compiled Then Exit
_Singleton($sAppName & " v" & $sAppVersion)
;_Registration_Check($sAppName, $sAppURL, $vPrivateKey)
OnAutoItExitRegister("_OnExit")
DirRemove(@TempDir & "\" & $sAppName, 1)
DirCreate(@TempDir & "\" & $sAppName)
$hGUI = GUICreate($sTitle, 400, 340, -1, -1)
$idFileMenu = GUICtrlCreateMenu("&File")
$idFileExitMenu = GUICtrlCreateMenuItem("E&xit", $idFileMenu)
$idToolsMenu = GUICtrlCreateMenu("&Tools")
$idToolsUnpackMenu = GUICtrlCreateMenu("Unpack", $idToolsMenu)
$idToolsUnpackUPDATEAPPMenu = GUICtrlCreateMenuItem("UPDATE.APP", $idToolsUnpackMenu)
$idToolsRepackMenu = GUICtrlCreateMenu("Repack", $idToolsMenu)
$idToolsRepackUPDATEAPPMenu = GUICtrlCreateMenuItem("UPDATE.APP", $idToolsRepackMenu)
GUICtrlCreateMenuItem("", $idToolsMenu)
$idToolsMiscellaneousMenu = GUICtrlCreateMenu("Miscellaneous", $idToolsMenu)
$idToolsMiscellaneousRemoveImmutableMenu = GUICtrlCreateMenuItem("Remove Immutable", $idToolsMiscellaneousMenu)
$idToolsMiscellaneousRemoveBloatwareMenu = GUICtrlCreateMenuItem("Remove Bloatware", $idToolsMiscellaneousMenu)
$idToolsMiscellaneousDownloadFirmwareMenu = GUICtrlCreateMenuItem("Download Firmware", $idToolsMiscellaneousMenu)
$idToolsNetworkMenu = GUICtrlCreateMenu("Network", $idToolsMenu)
$idToolsNetworkUnlockMenu = GUICtrlCreateMenuItem("Unlock", $idToolsNetworkMenu)
$idToolsNetworkRelockMenu = GUICtrlCreateMenuItem("Relock", $idToolsNetworkMenu)
$idToolsBootloaderMenu = GUICtrlCreateMenu("Bootloader", $idToolsMenu)
$idToolsBootloaderRequestKeyMenu = GUICtrlCreateMenuItem("Request Key", $idToolsBootloaderMenu)
GUICtrlCreateMenuItem("", $idToolsBootloaderMenu)
$idToolsBootloaderUnlockMenu = GUICtrlCreateMenuItem("Unlock", $idToolsBootloaderMenu)
$idToolsBootloaderRelockMenu = GUICtrlCreateMenuItem("Relock", $idToolsBootloaderMenu)
$idToolsFlashMenu = GUICtrlCreateMenu("Flash", $idToolsMenu)
$idToolsFlashUPDATEAPPMenu = GUICtrlCreateMenuItem("UPDATE.APP", $idToolsFlashMenu)
GUICtrlCreateMenuItem("", $idToolsFlashMenu)
$idToolsFlashBootMenu = GUICtrlCreateMenuItem("Boot", $idToolsFlashMenu)
$idToolsFlashRecoveryMenu = GUICtrlCreateMenuItem("Recovery", $idToolsFlashMenu)
$idToolsFlashSystemMenu = GUICtrlCreateMenuItem("System", $idToolsFlashMenu)
$idToolsRebootMenu = GUICtrlCreateMenu("Reboot", $idToolsMenu)
$idToolsRebootRebootMenu = GUICtrlCreateMenuItem("Reboot", $idToolsRebootMenu)
$idToolsRebootRecoveryMenu = GUICtrlCreateMenuItem("Recovery", $idToolsRebootMenu)
$idToolsRebootBootloaderMenu = GUICtrlCreateMenuItem("Bootloader", $idToolsRebootMenu)
$idHelpMenu = GUICtrlCreateMenu("&Help")
$idHelpAboutMenu = GUICtrlCreateMenuItem("&About " & $sAppName & "...", $idHelpMenu)
$idBannerPic = GUICtrlCreatePic(@ScriptDir & "\res\banner.bmp", 0, 0, 400, 160)
$idProductModelLabel = GUICtrlCreateLabel("Product Model:", 10, 180, 76, 17)
$idProductModelInput = GUICtrlCreateInput("", 10, 195, 380, 21)
$idProductIMEIMEIDLabel = GUICtrlCreateLabel("Product IMEI/MEID:", 10, 220, 101, 17)
$idProductIMEIMEIDInput = GUICtrlCreateInput("", 10, 235, 380, 21)
$idProductIDLabel = GUICtrlCreateLabel("Product ID:", 10, 260, 58, 17)
$idProductIDInput = GUICtrlCreateInput("", 10, 275, 380, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_READONLY))
GUIRegisterMsg($WM_DEVICECHANGE, "_WM_DEVICECHANGE")
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
GUISetState()
_GetDeviceInfo()
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE, $idFileExitMenu
Exit
Case $idToolsUnpackUPDATEAPPMenu
$sFilePath = FileOpenDialog("Open", @WorkingDir, "Huawei Firmware Files (*.app)|All Files (*.*)", $FD_FILEMUSTEXIST, "UPDATE.APP", $hGUI)
If Not @error Then
_Busy_Create("Unpacking...", $BUSY_SCREEN, 200, $hGUI)
DirRemove(@WorkingDir & "\UPDATE", 1)
DirCreate(@WorkingDir & "\UPDATE")
_UPDATEAPP_Unpack($sFilePath, @WorkingDir & "\UPDATE")
_Busy_Close()
EndIf
Case $idToolsRepackUPDATEAPPMenu
$sFilePath = FileOpenDialog("Open", @WorkingDir & "\UPDATE", "Sequence Files (*.ini)|All Files (*.*)", $FD_FILEMUSTEXIST, "Sequence.ini", $hGUI)
If Not @error Then
_Busy_Create("Repacking...", $BUSY_SCREEN, 200, $hGUI)
FileDelete(StringLeft(@WorkingDir, StringInStr(@WorkingDir, "\", Default, -1) - 1) & "\UPDATE.APP.NEW")
_UPDATEAPP_Repack($sFilePath, StringLeft(@WorkingDir, StringInStr(@WorkingDir, "\", Default, -1) - 1) & "\UPDATE.APP.NEW")
_Busy_Close()
EndIf
Case $idToolsMiscellaneousRemoveImmutableMenu
If $sDeviceState <> "Online" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Found.", Default, $hGUI)
Else
If Not $bRootAccess Then
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "Root Access Is Required.", Default, $hGUI)
Else
_Busy_Create("Removing Immutable...", $BUSY_SCREEN, 200, $hGUI)
_Android_Shell("mkdir /data/local/tmp", True)
_Android_Shell("rm -r /data/local/tmp/*", True)
_Android_Push("busybox", "/data/local/tmp")
_Android_Shell("chmod 755 /data/local/tmp/busybox")
_Android_Push("set_immutable", "/data/local/tmp")
_Android_Shell("chmod 755 /data/local/tmp/set_immutable")
_Android_Push(@ScriptDir & "\shells\remove_immutable.sh", "/data/local/tmp")
_Android_Shell("chmod 755 /data/local/tmp/remove_immutable.sh")
_Android_Shell("sh /data/local/tmp/remove_immutable.sh", True)
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Update("Rebooting...")
_Android_Reboot()
_Busy_Close()
EndIf
EndIf
Case $idToolsMiscellaneousRemoveBloatwareMenu
If $sDeviceState <> "Online" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Found.", Default, $hGUI)
Else
If Not FileExists(@ScriptDir & "\bloatware\" & $sManufacturer & ".lst") Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Supported.", Default, $hGUI)
Else
If Not $bRootAccess Then
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "Root Access Is Required.", Default, $hGUI)
Else
_Busy_Create("Removing Bloatware...", $BUSY_SCREEN, 200, $hGUI)
_Android_Shell("mkdir /data/local/tmp", True)
_Android_Shell("rm -r /data/local/tmp/*", True)
_Android_Push("busybox", "/data/local/tmp")
_Android_Shell("chmod 755 /data/local/tmp/busybox")
_Android_Push(@ScriptDir & "\bloatware\" & $sManufacturer & ".lst", "/data/local/tmp/bloatware.lst")
_Android_Push(@ScriptDir & "\shells\remove_bloatware.sh", "/data/local/tmp")
_Android_Shell("chmod 755 /data/local/tmp/remove_bloatware.sh")
_Android_Shell("sh /data/local/tmp/remove_bloatware.sh", True)
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Update("Rebooting...")
_Android_Reboot()
_Busy_Close()
EndIf
EndIf
EndIf
Case $idToolsMiscellaneousDownloadFirmwareMenu
ShellExecute("http://consumer.huawei.com/cn/support/downloads/index.htm?keyword=" & _Android_GetProperty("ro.product.name"))
Case $idToolsNetworkUnlockMenu
If $sDeviceState <> "Online" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Found.", Default, $hGUI)
Else
Switch $sManufacturer
Case "Huawei"
If Not $bRootAccess Then
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "Root Access Is Required.", Default, $hGUI)
Else
_Busy_Create("Checking...", $BUSY_SCREEN, 200, $hGUI)
_Android_Shell("mkdir /data/local/tmp", True)
_Android_Shell("rm -r /data/local/tmp/*", True)
$sOEMInfo = "mmcblk0p5"
_Android_Shell("cat /dev/block/" & $sOEMInfo & " > /data/local/tmp/oeminfo.mbn", True)
_Android_Shell("chmod 666 /data/local/tmp/oeminfo.mbn", True)
_Android_Pull("/data/local/tmp/oeminfo.mbn", @TempDir & "\" & $sAppName & "\oeminfo.mbn")
If _Hex_Read(@TempDir & "\" & $sAppName & "\oeminfo.mbn", 8) <> Binary("0x4F454D5F494E464F") Then
$sOEMInfo = "mmcblk0p8"
_Android_Shell("cat /dev/block/" & $sOEMInfo & " > /data/local/tmp/oeminfo.mbn", True)
_Android_Shell("chmod 666 /data/local/tmp/oeminfo.mbn", True)
_Android_Pull("/data/local/tmp/oeminfo.mbn", @TempDir & "\" & $sAppName & "\oeminfo.mbn")
EndIf
$iOffset = _Hex_Search(@TempDir & "\" & $sAppName & "\oeminfo.mbn", Binary("0x010010"))
If $iOffset = -1 Then
FileDelete(@TempDir & "\" & $sAppName & "\*.mbn")
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Close()
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Supported.", Default, $hGUI)
Else
$dData1 = _Hex_Read(@TempDir & "\" & $sAppName & "\oeminfo.mbn", 16, $iOffset + 3)
$dData2 = _Hex_Read(@TempDir & "\" & $sAppName & "\oeminfo.mbn", 16, $iOffset + 3 + 16 + 3)
$dData3 = _Hex_Read(@TempDir & "\" & $sAppName & "\oeminfo.mbn", 16, $iOffset + 3 + 16 + 3 + 16 + 3)
If $dData2 <> $dData3 Then
FileDelete(@TempDir & "\" & $sAppName & "\*.mbn")
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Close()
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Supported.", Default, $hGUI)
Else
If $dData1 = $dData2 Then
FileDelete(@TempDir & "\" & $sAppName & "\*.mbn")
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Close()
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "Network Is Already Unlocked.", Default, $hGUI)
Else
_Busy_Update("Unlocking...")
_Hex_Write(@TempDir & "\" & $sAppName & "\oeminfo.mbn", $dData2, $iOffset + 3)
_Android_Push(@TempDir & "\" & $sAppName & "\oeminfo.mbn", "/data/local/tmp")
_Android_Shell("cat /data/local/tmp/oeminfo.mbn > /dev/block/" & $sOEMInfo, True)
FileDelete(@TempDir & "\" & $sAppName & "\*.mbn")
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Update("Rebooting...")
_Android_Reboot()
_Busy_Close()
EndIf
EndIf
EndIf
EndIf
Case Else
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Supported.", Default, $hGUI)
EndSwitch
EndIf
Case $idToolsNetworkRelockMenu
If $sDeviceState <> "Online" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Found.", Default, $hGUI)
Else
Switch $sManufacturer
Case "Huawei"
If Not $bRootAccess Then
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "Root Access Is Required.", Default, $hGUI)
Else
_Busy_Create("Checking...", $BUSY_SCREEN, 200, $hGUI)
_Android_Shell("mkdir /data/local/tmp", True)
_Android_Shell("rm -r /data/local/tmp/*", True)
$sOEMInfo = "mmcblk0p5"
_Android_Shell("cat /dev/block/" & $sOEMInfo & " > /data/local/tmp/oeminfo.mbn", True)
_Android_Shell("chmod 666 /data/local/tmp/oeminfo.mbn", True)
_Android_Pull("/data/local/tmp/oeminfo.mbn", @TempDir & "\" & $sAppName & "\oeminfo.mbn")
If _Hex_Read(@TempDir & "\" & $sAppName & "\oeminfo.mbn", 8) <> Binary("0x4F454D5F494E464F") Then
$sOEMInfo = "mmcblk0p8"
_Android_Shell("cat /dev/block/" & $sOEMInfo & " > /data/local/tmp/oeminfo.mbn", True)
_Android_Shell("chmod 666 /data/local/tmp/oeminfo.mbn", True)
_Android_Pull("/data/local/tmp/oeminfo.mbn", @TempDir & "\" & $sAppName & "\oeminfo.mbn")
EndIf
$iOffset = _Hex_Search(@TempDir & "\" & $sAppName & "\oeminfo.mbn", Binary("0x010010"))
If $iOffset = -1 Then
FileDelete(@TempDir & "\" & $sAppName & "\*.mbn")
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Close()
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Supported.", Default, $hGUI)
Else
$dData1 = _Hex_Read(@TempDir & "\" & $sAppName & "\oeminfo.mbn", 16, $iOffset + 3)
$dData2 = _Hex_Read(@TempDir & "\" & $sAppName & "\oeminfo.mbn", 16, $iOffset + 3 + 16 + 3)
$dData3 = _Hex_Read(@TempDir & "\" & $sAppName & "\oeminfo.mbn", 16, $iOffset + 3 + 16 + 3 + 16 + 3)
If $dData2 <> $dData3 Then
FileDelete(@TempDir & "\" & $sAppName & "\*.mbn")
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Close()
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Supported.", Default, $hGUI)
Else
If $dData1 = Binary("0x00000000000000000000000000000000") Then
FileDelete(@TempDir & "\" & $sAppName & "\*.mbn")
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Close()
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "Network Is Already Relocked.", Default, $hGUI)
Else
_Busy_Update("Relocking...")
_Hex_Write(@TempDir & "\" & $sAppName & "\oeminfo.mbn", Binary("0x00000000000000000000000000000000"), $iOffset + 3)
_Android_Push(@TempDir & "\" & $sAppName & "\oeminfo.mbn", "/data/local/tmp")
_Android_Shell("cat /data/local/tmp/oeminfo.mbn > /dev/block/" & $sOEMInfo, True)
FileDelete(@TempDir & "\" & $sAppName & "\*.mbn")
_Android_Shell("rm -r /data/local/tmp/*", True)
_Busy_Update("Rebooting...")
_Android_Reboot()
_Busy_Close()
EndIf
EndIf
EndIf
EndIf
Case Else
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Supported.", Default, $hGUI)
EndSwitch
EndIf
Case $idToolsBootloaderRequestKeyMenu
ShellExecute("http://www.emui.com/plugin.php?id=unlock&mod=detail")
Case $idToolsBootloaderUnlockMenu
If $sDeviceState <> "Online" And $sDeviceState <> "Bootloader" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Found.", Default, $hGUI)
Else
If $sDeviceState <> "Bootloader" Then
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "This Function Only Works In Bootloader Mode.", Default, $hGUI)
Else
While 1
$sKey = InputBox($sTitle, "Key:", Default, Default, 305, 130, Default, Default, Default, $hGUI)
If @error = 1 Or $sKey <> "" Then
ExitLoop
Else
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "Key Should Not Be Empty.", Default, $hGUI)
EndIf
WEnd
If Not @error Then
_Busy_Create("Unlocking...", $BUSY_SCREEN, 200, $hGUI)
__Run("fastboot oem unlock " & $sKey)
_Busy_Close()
EndIf
EndIf
EndIf
Case $idToolsBootloaderRelockMenu
If $sDeviceState <> "Online" And $sDeviceState <> "Bootloader" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Found.", Default, $hGUI)
Else
If $sDeviceState <> "Bootloader" Then
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "This Function Only Works In Bootloader Mode.", Default, $hGUI)
Else
While 1
$sKey = InputBox($sTitle, "Key:", Default, Default, 305, 130, Default, Default, Default, $hGUI)
If @error = 1 Or $sKey <> "" Then
ExitLoop
Else
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "Key Should Not Be Empty.", Default, $hGUI)
EndIf
WEnd
If Not @error Then
_Busy_Create("Relocking...", $BUSY_SCREEN, 200, $hGUI)
__Run("fastboot oem relock " & $sKey)
_Busy_Close()
EndIf
EndIf
EndIf
Case $idToolsFlashUPDATEAPPMenu
If $sDeviceState <> "Online" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Found.", Default, $hGUI)
Else
If $sManufacturer <> "Huawei" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Supported.", Default, $hGUI)
Else
_Android_Shell("echo > /storage/sdcard1/sd_card_checker")
If Not _Android_FileExists("/storage/sdcard1/sd_card_checker") Then
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "SD Card Is Required.", Default, $hGUI)
Else
_Android_Shell("rm /storage/sdcard1/sd_card_checker")
$sFilePath = FileOpenDialog("Open", @WorkingDir, "Huawei Firmware Files (*.app)|All Files (*.*)", $FD_FILEMUSTEXIST, "UPDATE.APP", $hGUI)
If Not @error Then
_Busy_Create("Pushing...", $BUSY_SCREEN, 200, $hGUI)
_Android_Shell("mkdir /storage/sdcard1/dload")
_Android_Shell("rm -r /storage/sdcard1/dload/*")
_Android_Push($sFilePath, "/storage/sdcard1/dload/UPDATE.APP")
_Android_Shell("echo > /storage/sdcard1/dload/au_temp.cfg")
_Busy_Update("Rebooting...")
_Android_Reboot()
_Busy_Close()
EndIf
EndIf
EndIf
EndIf
Case $idToolsFlashBootMenu
_Flash("boot")
Case $idToolsFlashRecoveryMenu
_Flash("recovery")
Case $idToolsFlashSystemMenu
_Flash("system")
Case $idToolsRebootRebootMenu
_Reboot()
Case $idToolsRebootRecoveryMenu
_Reboot("recovery")
Case $idToolsRebootBootloaderMenu
_Reboot("bootloader")
Case $idHelpAboutMenu
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), "About", $sAppName & @CRLF & @CRLF & "Version: " & $sAppVersion & @CRLF & "Developed By: " & $sAppPublisher, Default, $hGUI)
EndSwitch
WEnd
Func _WM_DEVICECHANGE($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $ilParam
Switch $iwParam
Case $DBT_DEVNODES_CHANGED
_GetDeviceInfo()
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_DEVICECHANGE
Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $ilParam
Switch _WinAPI_LoWord($iwParam)
Case $idProductModelInput, $idProductIMEIMEIDInput
Switch _WinAPI_HiWord($iwParam)
Case $EN_CHANGE
GUICtrlSetData($idProductIDInput, _GenerateProductID(GUICtrlRead($idProductModelInput), GUICtrlRead($idProductIMEIMEIDInput)))
EndSwitch
EndSwitch
EndFunc ;==>_WM_COMMAND
Func _GetDeviceInfo()
Local $sNewDeviceState, $sOldDeviceState
$sNewDeviceState = _Android_GetState()
If $sDeviceState <> $sNewDeviceState Then
$sModelNumber = ""
$sDeviceID = ""
$sOldDeviceState = $sDeviceState
$sDeviceState = $sNewDeviceState
Switch $sDeviceState
Case "Online"
$sManufacturer = _Android_GetProperty("ro.product.manufacturer")
$sModelNumber = _Android_GetProperty("ro.product.model")
$sDeviceID = _Android_GetDeviceID()
$bRootAccess = _Android_HasRootAccess()
Case "Offline"
_Connect()
Case "Bootloader"
Case Else
If $sOldDeviceState = "" Then _Connect()
EndSwitch
GUICtrlSetData($idProductModelInput, $sModelNumber)
GUICtrlSetData($idProductIMEIMEIDInput, $sDeviceID)
EndIf
EndFunc ;==>_GetDeviceInfo
Func _Connect()
_Busy_Create("Connecting...", $BUSY_SCREEN, 200, $hGUI)
_Android_Connect()
_Busy_Close()
EndFunc ;==>_Connect
Func _GenerateProductID($sModelNumber, $sDeviceID)
_Crypt_Startup()
Local $sMD5, $aChar, $aProductID[8] = [0, 0, 0, 0, 0, 0, 0, 0]
$sMD5 = StringTrimLeft(_Crypt_HashData($sModelNumber & $sDeviceID, $CALG_MD5), 2)
$aChar = StringSplit(__HexEx(BitXOR(Dec(StringLeft($sMD5, 8)), Dec(StringRight($sMD5, 8)))), "")
For $i = 1 To $aChar[0]
If StringInStr("ABCDEF", $aChar[$i]) Then
$aProductID[$i - 1] = Chr(Asc($aChar[$i]) - 17)
Else
$aProductID[$i - 1] = $aChar[$i]
EndIf
Next
_Crypt_Shutdown()
Return _ArrayToString($aProductID, "")
EndFunc ;==>_GenerateProductID
Func _Flash($sMode)
If $sDeviceState <> "Online" And $sDeviceState <> "Bootloader" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Found.", Default, $hGUI)
Else
If $sDeviceState <> "Bootloader" Then
MsgBox(BitOR($MB_ICONINFORMATION, $MB_APPLMODAL), $sTitle, "This Function Only Works In Bootloader Mode.", Default, $hGUI)
Else
Switch $sMode
Case "boot"
$sFilter = "Image Files (*.img;*.sin;*.elf)"
Case "system"
$sFilter = "Image Files (*.img;*.ext4;*.yaffs2;*.sin)"
Case Else
$sFilter = "Image Files (*.img)"
EndSwitch
$sFilePath = FileOpenDialog("Open", @WorkingDir, $sFilter & "|All Files (*.*)", $FD_FILEMUSTEXIST, "", $hGUI)
If Not @error Then
_Busy_Create("Flashing...", $BUSY_SCREEN, 200, $hGUI)
_Android_Flash($sMode, $sFilePath)
_Busy_Close()
EndIf
EndIf
EndIf
EndFunc ;==>_Flash
Func _Reboot($sMode = "")
If ($sDeviceState <> "Online" And $sDeviceState <> "Bootloader") Or (($sMode = "recovery" Or $sMode = "download") And $sDeviceState <> "Online") Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Found.", Default, $hGUI)
Else
If $sMode = "download" And $sManufacturer <> "Samsung" Then
MsgBox(BitOR($MB_ICONERROR, $MB_APPLMODAL), "Error", "Device Is Not Supported.", Default, $hGUI)
Else
_Busy_Create("Rebooting...", $BUSY_SCREEN, 200, $hGUI)
_Android_Reboot($sMode)
_Busy_Close()
EndIf
EndIf
EndFunc ;==>_Reboot
Func _OnExit()
DirRemove(@TempDir & "\" & $sAppName, 1)
EndFunc ;==>_OnExit
;~ Func __GetUniqueKey($vKey)
;~ _Crypt_Startup()
;~ Local $dUniqueKey = _Crypt_EncryptData(StringTrimLeft(_Crypt_HashFile(@ScriptFullPath, $CALG_MD5), 2), $vKey, $CALG_RC4)
;~ _Crypt_Shutdown()
;~ Return $dUniqueKey
;~ EndFunc ;==>__GetUniqueKey
Func __HexEx($iDec)
Local $sHex = Hex($iDec)
While StringLeft($sHex, 1) = "0"
$sHex = StringMid($sHex, 2)
If StringLeft($sHex, 1) <> "0" Then ExitLoop
WEnd
Return $sHex
EndFunc ;==>__HexEx