Skip to content

Commit

Permalink
more beautiful
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdWindScholar committed May 31, 2024
1 parent 27982d4 commit 857cc10
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 34 deletions.
5 changes: 1 addition & 4 deletions mtkclient/Library/DA/legacy/dalegacy_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 6 additions & 12 deletions mtkclient/Library/DA/xml/xml_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion mtkclient/Library/Port.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions mtkclient/Library/cryptutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mtkclient/Tools/da_parser
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions mtkclient/Tools/preloader_emu_mmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions stage2
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 857cc10

Please sign in to comment.