前言之前在玩VIVO的老手机,其中涉及到了一些VIVO对fastboot的魔改通过修改fastboot本身的源码,目的就是为了添加两个指令,感觉不是很优雅。还是使用Libusb来解决为好,也省得需要配置编译器再编译可执行文件的麻烦事儿了。同时也挖掘出了一个新的指令,可以快速切换设备去下载模式同时,为了使用方便,使用TK实现了一个UI。

依赖项Libusb Win32 Filter下载PyUSBPython3

截图

功能支持新老平台的FASTBOOT解锁和上锁,支持特定机种的引导到下载模式

代码import usb.core

import usb.util

import traceback

from tkinter import *

from tkinter import messagebox

FB_VID = 0x18d1

FB_PID = 0xd00d

def initUsb():

dev = usb.core.find(idVendor=FB_VID, idProduct=FB_PID)

if not dev:

messagebox.showerror("Error", 'NOT FOUND WEIWO FASTBOOT DEVICES')

exit(-1)

intf = dev[0][(0, 0)]

usb.util.claim_interface(dev, intf)

messagebox.showinfo("Info", 'Init phone: finished')

return dev, intf, intf[0], intf[1]

def clearHalt(phone, in_end, out_end):

phone.clear_halt(in_end)

phone.clear_halt(out_end)

messagebox.showinfo("Info", 'Clear halt: finished')

def sendBulk(phone, in_end, out_end, cmd):

assert phone.write(out_end, cmd) == len(cmd)

ret = phone.read(in_end, 100)

sret = ''.join([chr(x) for x in ret])

messagebox.showinfo("Response", f'RESP>> {sret}')

return sret

def unlockBlOld(phone, in_end, out_end):

cmd = 'bbk unlock_vivo'

sendBulk(phone, in_end, out_end, cmd)

cmd = 'reboot-bootloader'

sendBulk(phone, in_end, out_end, cmd)

def lockBlOld(phone, in_end, out_end):

cmd = 'bbk lock_vivo'

sendBulk(phone, in_end, out_end, cmd)

def changeDloadOld(phone, in_end, out_end):

cmd = 'bbk change_dload_vivo'

sendBulk(phone, in_end, out_end, cmd)

def unlockBlNew(phone, in_end, out_end):

cmd = 'vivo_bsp unlock_vivo'

sendBulk(phone, in_end, out_end, cmd)

cmd = 'reboot-bootloader'

sendBulk(phone, in_end, out_end, cmd)

def lockBlNew(phone, in_end, out_end):

cmd = 'vivo_bsp lock_vivo'

sendBulk(phone, in_end, out_end, cmd)

try:

phone, interface, in_end, out_end = initUsb()

def performAction(action):

try:

{'1': unlockBlOld, '2': lockBlOld, '3': changeDloadOld, '4': unlockBlNew, '5': lockBlNew}[action](phone, in_end, out_end)

except KeyError:

messagebox.showerror("Error", 'Invalid operation')

except:

traceback.print_exc()

finally:

usb.util.release_interface(phone, interface)

root = Tk()

root.title("WWTool")

Label(root, text="WeiWo Tool").pack()

Button(root, text="Unlock Bootloader (Old)", command=lambda: performAction('1')).pack()

Button(root, text="Lock Bootloader (Old)", command=lambda: performAction('2')).pack()

Button(root, text="Dload Mode (Old)", command=lambda: performAction('3')).pack()

Button(root, text="Unlock Bootloader (New)", command=lambda: performAction('4')).pack()

Button(root, text="Lock Bootloader (New)", command=lambda: performAction('5')).pack()

root.mainloop()

except:

traceback.print_exc()