This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path小米845免受权9008工具.py
327 lines (290 loc) · 13.1 KB
/
小米845免受权9008工具.py
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
import subprocess
import sys
import tkinter as tk
from os import getcwd, name as osname, sep, system, path as ospath
from threading import Thread
from tkinter import filedialog
from tkinter import messagebox
from tkinter import ttk, Tk, Text
from tkinter.ttk import Label, Entry, Button
from PIL import Image, ImageTk
from ttkbootstrap.constants import *
class StdoutRedirector(object):
def __init__(self, text_widget):
self.text_space = text_widget
def write(self, string):
self.text_space.insert(END, string)
self.text_space.yview('end')
@staticmethod
def flush():
pass
def __exit__(self):
pass
def call(exe, kz='Y', out=0, shstate=False, sp=0):
if kz == "Y":
cmd = f'{getcwd()}{sep}{exe}'
else:
cmd = exe
if osname != 'posix':
conf = subprocess.CREATE_NO_WINDOW
else:
if sp == 0:
cmd = cmd.split()
conf = 0
try:
ret = subprocess.Popen(cmd, shell=shstate, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, creationflags=conf)
for i in iter(ret.stdout.readline, b""):
if out == 0:
print(i.decode("utf-8", "ignore").strip())
except subprocess.CalledProcessError as e:
for i in iter(e.stdout.readline, b""):
if out == 0:
print(e.decode("utf-8", "ignore").strip())
ret.wait()
return ret.returncode
def cz(func, *args):
Thread(target=func, args=args, daemon=True).start()
def unlock_miacc():
print("请将手机连接到TWRP模式")
lines = ['adb wait-for-device',
'adb push rec/miacc_unlock.zip /sdcard/miacc_unlock.zip'
'adb shell twrp install /sdcard/miacc_unlock.zip'
'adb shell mke2fs -t ext4 /dev/block/by-name/userdata',
'adb shell reboot system'
]
for cmd in lines:
if cmd.split()[0] == 'choice':
call(cmd, kz='N')
else:
if call(cmd) != 0:
print(f"运行{cmd}出现了错误")
else:
print(f'[{cmd.split()[0]}] 成功.')
print('解锁MI账号成功!')
def end():
print('正在关闭进程...')
for t in [1, 2, 3]:
call('taskkill /im fastboot.exe /f', kz='N')
call('taskkill /im adb.exe /f', kz='N')
root.destroy()
class MyTool(Tk):
def __init__(self):
super().__init__()
self.title('MEDL845 V3.2')
self.protocol("WM_DELETE_WINDOW", end)
self.resizable(False, False)
self.folder_path = tk.StringVar()
self.number = tk.StringVar()
self.subwin = ttk.LabelFrame(self, text='功能')
self.logwin = ttk.LabelFrame(self, text='日志')
self.init_log()
self.logwin.pack(fill=BOTH, side=LEFT, expand=True, pady=5)
self.subwin.pack(fill=BOTH, side=LEFT, expand=True, padx=5)
self.notepad = ttk.Notebook(self.subwin)
self.notepad.pack(fill=BOTH)
self.tab = ttk.Frame(self.notepad)
self.tab1 = ttk.Frame(self.notepad)
self.flash = ttk.Frame(self.notepad)
self.djt = ttk.Frame(self.notepad)
self.about = ttk.Frame(self.notepad)
self.notepad.add(self.tab, text="刷机救砖")
self.notepad.add(self.flash, text="线刷工具箱")
self.notepad.add(self.djt, text="短接图")
self.notepad.add(self.tab1, text="其他")
self.notepad.add(self.about, text="关于")
self.init_tab()
self.init_tab1()
self.init_flash()
self.init_djt()
self.init_about()
print("欢迎使用MEDL845。\n本工具永久免费,禁止倒卖!\n开发者: ColdWindScholar & XEKNICE & "
"AGXMX\n开源地址:https://github.com/ColdWindScholar/MEDL845")
def init_tab(self):
# ----
Frame = ttk.Frame(self.tab)
self.folder_label = Label(Frame, text='救砖包文件夹:')
self.folder_label.pack(side=LEFT, padx=5, pady=5)
self.folder_entry = Entry(Frame, textvariable=self.folder_path)
self.folder_entry.pack(side=LEFT, padx=5, pady=5)
self.folder_button = Button(Frame, text='浏览', command=self.select_folder)
self.folder_button.pack(side=LEFT, padx=5, pady=5)
Frame.pack(fill=X)
# -----
# -----
Frame = ttk.Frame(self.tab)
self.number_label = Label(Frame, text='9008端口号:')
self.number_label.pack(side=LEFT, padx=5, pady=5)
self.number_entry = Entry(Frame, textvariable=self.number)
self.number_entry.pack(side=LEFT, padx=5, pady=5)
Frame.pack(fill=X)
# -----
self.start_button = Button(self.tab, text='开始刷入', command=lambda: cz(self.start_running))
self.start_button.pack(padx=5, pady=5)
self.start_edl = Button(self.tab, text='进入9008模式', command=lambda: cz(self.edl))
self.start_edl.pack()
self.close_button = Button(self.tab, text='关闭此程序', command=end)
self.close_button.pack(side=BOTTOM)
def init_tab1(self):
if not ospath.exists('res' + sep + 'lite'):
self.fix_button = Button(self.tab1, text='安装/修复驱动', command=self.FIX, width=20)
self.fix_button.pack(padx=5, pady=5)
self.fix_button = Button(self.tab1, text='绕MIUI账号锁', command=lambda: cz(self.ZHS), width=20)
self.fix_button.pack(padx=5, pady=5)
self.fix_button = Button(self.tab1, text='强解bootloader锁', command=self.BL, width=20)
self.fix_button.pack(padx=5, pady=5)
else:
Label(self.tab1, text='MEDL845精简版', font=(None, 15)).pack(side=TOP, padx=5, pady=10)
def init_flash(self):
def disable():
self.file_entry.configure(state='disabled')
self.flash_reboot.configure(state='disabled')
self.flash_run.configure(state='disabled')
def able():
self.file_entry.configure(state='normal')
self.flash_reboot.configure(state='normal')
self.flash_run.configure(state='normal')
def set_img():
if path := self.select_file():
self.file_entry.delete(0, END)
self.file_entry.insert(0, path)
def run():
if not self.file_entry.get():
print("请输入镜像路径")
return
self.flash_run.configure(text='正在执行')
disable()
if self.flash_cz.get() == 1:
if call(f'fastboot flash {self.part.get()} {self.file_entry.get()}') != 0: print("操作失败!")
elif self.flash_cz.get() == 2:
if call(f'fastboot erase {self.part.get()}') != 0: print("操作失败!")
elif self.flash_cz.get() == 3:
if call(f'fastboot boot {self.file_entry.get()}') != 0:
print("操作失败!")
self.flash_run.configure(text='执行')
able()
def reboot():
self.flash_reboot.configure(text='正在重启')
disable()
call('fastboot reboot')
self.flash_reboot.configure(text='重启')
able()
Label(self.flash, text='线刷工具箱', font=(None, 15)).pack(side=TOP, padx=5, pady=5)
# ----
Frame = ttk.Frame(self.flash)
Label(Frame, text='镜像文件:').pack(side=LEFT, padx=5, pady=5)
self.file_entry = Entry(Frame)
self.file_entry.pack(side=LEFT, padx=5, pady=5)
self.file_button = Button(Frame, text='浏览', command=set_img)
self.file_button.pack(side=LEFT, padx=5, pady=5)
Frame.pack(fill=X, padx=5, pady=5)
# -----
# ---
Frame = ttk.Frame(self.flash)
Label(Frame, text='操作分区:').pack(side=LEFT, padx=5, pady=5)
self.part = ttk.Combobox(Frame, values=['recovery', 'boot', 'system', 'vendor'])
self.part.current(0)
self.part.pack(side=LEFT)
Frame.pack(fill=X, padx=5, pady=5)
# ---
Frame = ttk.Frame(self.flash)
Label(Frame, text='操作:').pack(side=LEFT, padx=5, pady=5)
self.flash_cz = tk.IntVar()
self.flash_cz.set(1)
cs = 0
for v in ['刷入', '擦除', '临时启动']:
cs += 1
ttk.Radiobutton(Frame, text=v, variable=self.flash_cz, value=cs).pack(side=LEFT, padx=2, pady=2)
Frame.pack(fill=X, padx=5, pady=5)
self.flash_run = Button(self.flash, text='执行', command=lambda: cz(run))
self.flash_run.pack(fill=X, padx=5, pady=5)
self.flash_reboot = Button(self.flash, text='重启手机', command=lambda: cz(reboot))
self.flash_reboot.pack(fill=X, padx=5, pady=5)
def init_djt(self):
def next(name):
pics = {
'MI MIX2S': 'res/MIX2S.jpeg',
'MI MIX3': 'res/MIX3.png',
'MI 8': 'res/MI8.jpg',
'MI8探索/屏幕指纹版': 'res/MI8EE.jpg'
}
global img
try:
img = Image.open(pics[self.qh.get()]).resize((400, 450))
except:
img = Image.open(pics['MI MIX2S']).resize((400, 450))
global photo
photo = ImageTk.PhotoImage(img)
self.djt_.configure(image=photo)
self.djt_ = Label(self.djt, width=200)
self.djt_.pack(fill=BOTH)
self.qh = ttk.Combobox(self.djt, values=['MI MIX2S', 'MI MIX3', 'MI 8', 'MI8探索/屏幕指纹版'], state='readonly')
self.qh.current(0)
self.qh.bind('<<ComboboxSelected>>', next)
next(self)
self.qh.pack()
def init_about(self):
Label(self.about, text='MEDL845 V3.2', font=(None, 17)).pack(padx=5, pady=5)
self.GY_button = Button(self.about, text='查看说明', command=lambda: cz(system, 'start res/SM.png'),
width=20)
self.GY_button.pack(padx=5, pady=5)
self.number_label = Label(self.about, text='官网链接:miui845.agxmx.top\nAGXMX & ColdWindScholar保留所有权利。')
self.number_label.pack(side=BOTTOM)
def init_log(self):
self.log = Text(self.logwin)
self.log.pack(padx=5, pady=5)
Frame = ttk.Frame(self.logwin)
Button(Frame, text='清空', command=lambda: cz(self.log.delete, 1.0, END)).pack(side=LEFT, padx=5, pady=5)
Frame.pack(fill=X, side=BOTTOM)
sys.stdout = StdoutRedirector(self.log)
sys.stderr = StdoutRedirector(self.log)
def select_folder(self):
if path := filedialog.askdirectory():
self.folder_path.set(path)
def select_file(self):
if path := filedialog.askopenfilename(filetypes=[('bin', '*.bin'), ('image', '*.img')]):
return path
else:
return None
def start_running(self):
if not self.folder_path.get() or not self.number.get().isdigit():
messagebox.showerror('错误', '请确保文件夹路径已选择且端口号为数字')
return None
else:
path = self.folder_path.get()
converted_path = path.replace('/', '\\')
a = ospath.normpath(converted_path)
self.start_button.config(state='disabled')
self.close_button.config(state='disabled')
self.start_edl.config(state='disabled')
self.fix_button.config(state='disabled')
if errorlevel := call(f'MIQC845Flash.exe -P {self.number.get()} {a} exit') == 0:
messagebox.showinfo('刷机结束', '刷机进程结束! 请长按电源键尝试重启?')
else:
messagebox.showerror('刷机错误!', f'很抱歉, 刷机错误!错误代码:{errorlevel}')
self.start_button.config(state='normal')
self.close_button.config(state='normal')
self.start_edl.config(state='normal')
self.fix_button.config(state='normal')
def edl(self):
self.start_edl.config(state='disabled', text="正在等待设备")
call('fastboot.exe oem edl')
system('start devmgmt.msc')
self.start_edl.config(state='normal', text='进入9008模式')
def FIX(self):
messagebox.showinfo('注意', '本功能需要程序拥有管理员权限!\n执行后请将电脑重新启动!')
call('res/FIX.exe')
call('res/USB.bat')
def ZHS(self):
messagebox.showinfo('注意', '此功能仅限于845系列\n手机先进入TWRP模式')
unlock_miacc()
def BL(self):
messagebox.showinfo('注意',
'机型、MIUI版本支持列表\n小米6: MIUI 9.6.3.0 \n小米6X: MIUI 9.6.4.0 \n小米8: MIUI 9.6.6.0 \n小米8SE: MIUI '
'9.5.11.0 \n小米8探索版: MIUI 9.6.7.0 \n小米Note 3: MIUI 9.6.3.0 \n小米MAX 3: MIUI 9.6.9.0 \n小米MIX '
'2: MIUI 9.6.3.0 \n小米MIX 2S: MIUI 9.6.8.0 \n小米平板4: MIUI 9.6.23.0 \n红米Note 5: MIUI 9.6.4.0 '
'\n版本以上系统自行拆机短接9008降级到MIUI9.6以下最好是出厂系统后再用此工具解锁BL')
call('res/BL.exe')
if __name__ == '__main__':
root = MyTool()
root.mainloop()