From 857cc10f731faa39a0e1265bca9ee3dfb6263c36 Mon Sep 17 00:00:00 2001 From: ColdWindScholar <3590361911@qq.com> Date: Sat, 1 Jun 2024 07:52:55 +0800 Subject: [PATCH] more beautiful --- mtkclient/Library/DA/legacy/dalegacy_lib.py | 5 +---- mtkclient/Library/DA/xml/xml_lib.py | 18 ++++++------------ mtkclient/Library/Port.py | 1 - mtkclient/Library/cryptutils.py | 10 ++-------- mtkclient/Tools/da_parser | 2 +- mtkclient/Tools/preloader_emu_mmc.py | 5 +---- stage2 | 5 +---- 7 files changed, 12 insertions(+), 34 deletions(-) diff --git a/mtkclient/Library/DA/legacy/dalegacy_lib.py b/mtkclient/Library/DA/legacy/dalegacy_lib.py index 32ba78b2..277412b3 100755 --- a/mtkclient/Library/DA/legacy/dalegacy_lib.py +++ b/mtkclient/Library/DA/legacy/dalegacy_lib.py @@ -203,10 +203,7 @@ def sdmmc_switch_partition(self, partition): if ack == self.Rsp.ACK: self.usbwrite(pack(">B", partition)) res = self.usbread(1) - if res < 0: - return False - else: - return True + return not res < 0 return False def check_security(self): diff --git a/mtkclient/Library/DA/xml/xml_lib.py b/mtkclient/Library/DA/xml/xml_lib.py index 9c09cb4f..a1d705f3 100755 --- a/mtkclient/Library/DA/xml/xml_lib.py +++ b/mtkclient/Library/DA/xml/xml_lib.py @@ -614,8 +614,8 @@ def __init__(self, storagetype, data): self.lua1_size = int(get_field(data, "lua1_size"), 16) self.lua2_size = int(get_field(data, "lua2_size"), 16) self.lua3_size = int(get_field(data, "lua3_size"), 16) - self.cid = get_field(data, "id") # this doesn't exists in Xiaomi DA - if self.cid == "": + self.cid = get_field(data, "id") # this doesn't exists in Xiaomi DA + if not self.cid: self.cid = get_field(data, "ufs_cid") elif self.storagetype == "EMMC": self.block_size = int(get_field(data, "block_size"), 16) @@ -627,8 +627,8 @@ def __init__(self, storagetype, data): self.gp2_size = int(get_field(data, "gp2_size"), 16) self.gp3_size = int(get_field(data, "gp3_size"), 16) self.gp4_size = int(get_field(data, "gp4_size"), 16) - self.cid = get_field(data, "id") # this doesn't exists in Xiaomi DA - if self.cid == "": + self.cid = get_field(data, "id") # this doesn't exists in Xiaomi DA + if not self.cid: self.cid = get_field(data, "emmc_cid") elif self.storagetype == "NAND": self.block_size = int(get_field(data, "block_size"), 16) @@ -704,10 +704,7 @@ def check_sla(self): if "item key=" in data: tmp = data[data.find("item key=") + 8:] res = tmp[tmp.find(">") + 1:tmp.find("<")] - if res == "DISABLED": - return False - else: - return True + return res != "DISABLED" else: self.error("Couldn't find item key") return data @@ -918,10 +915,7 @@ def check_lifecycle(self): if sresult == "OK": tcmd, tresult = self.get_command_result() if tresult == "START": - if data == b"OK\x00": - return True - else: - return False + return data == b"OK\x00" return False def reinit(self, display=False): diff --git a/mtkclient/Library/Port.py b/mtkclient/Library/Port.py index 58f78415..fa3cae13 100755 --- a/mtkclient/Library/Port.py +++ b/mtkclient/Library/Port.py @@ -49,7 +49,6 @@ def __init__(self, mtk, portconfig, serialportname: str = None, loglevel=logging self.__logger.setLevel(logging.INFO) def run_serial_handshake(self): - EP_OUT = None try: # Support for serial port where EP_OUT is unknown if hasattr(self.cdc, 'EP_OUT'): EP_OUT = self.cdc.EP_OUT.write diff --git a/mtkclient/Library/cryptutils.py b/mtkclient/Library/cryptutils.py index 70ce3f31..b69f8e03 100755 --- a/mtkclient/Library/cryptutils.py +++ b/mtkclient/Library/cryptutils.py @@ -486,18 +486,12 @@ def pss_verify(self, e, N, msghash, signature, emBits=1024, salt=None): if salt is not None: inBlock = b"\x00" * 8 + msghash + salt mhash = self.hash(inBlock) - if mhash == hash: - return True - else: - return False + return mhash == hash else: salt = TS[-self.digestLen:] inBlock = b"\x00" * 8 + msghash + salt mhash = self.hash(inBlock) - if mhash == hash: - return True - else: - return False + return mhash == hash return maskedDB @staticmethod diff --git a/mtkclient/Tools/da_parser b/mtkclient/Tools/da_parser index 5fe40676..1ccdb537 100755 --- a/mtkclient/Tools/da_parser +++ b/mtkclient/Tools/da_parser @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -#(c) B.Kerler 2021 MIT License +# (c) B.Kerler 2021 MIT License import os import sys from struct import unpack diff --git a/mtkclient/Tools/preloader_emu_mmc.py b/mtkclient/Tools/preloader_emu_mmc.py index 51d97c5b..f9378f26 100755 --- a/mtkclient/Tools/preloader_emu_mmc.py +++ b/mtkclient/Tools/preloader_emu_mmc.py @@ -163,10 +163,7 @@ def memwrite(self, start, data): bytestowrite -= size pos += size ack = self.cdc.usbread(4) - if ack == b"\xD0\xD0\xD0\xD0": - return True - else: - return False + return ack == b"\xD0\xD0\xD0\xD0" def rpmb(self, start, length, filename): if start == 0: diff --git a/stage2 b/stage2 index 5606c301..f42ee15a 100755 --- a/stage2 +++ b/stage2 @@ -303,10 +303,7 @@ class Stage2(metaclass=LogBase): if filename is not None: rf.close() ack = self.usbread(4) - if ack == b"\xD0\xD0\xD0\xD0": - return True - else: - return False + return ack == b"\xD0\xD0\xD0\xD0" def rpmb(self, start, length, filename, reverse=False): pg = progress(pagesize=0x100)