From a041a4033c78338285527e26e4b00fdbbcef6fad Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Mon, 8 Jan 2024 19:22:00 +0100 Subject: [PATCH] Additional fixes --- mtkclient/Library/DA/daconfig.py | 14 ++--- mtkclient/Library/DA/legacy/dalegacy_lib.py | 2 +- .../Library/DA/xflash/extension/xflash.py | 5 ++ mtkclient/Library/DA/xflash/xflash_lib.py | 51 +++++++++++-------- 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/mtkclient/Library/DA/daconfig.py b/mtkclient/Library/DA/daconfig.py index 8eab7f4..9cf2219 100755 --- a/mtkclient/Library/DA/daconfig.py +++ b/mtkclient/Library/DA/daconfig.py @@ -157,13 +157,13 @@ class DAconfig(metaclass=LogBase): loaders.append(os.path.join(root, file)) loaders = sorted(loaders)[::-1] for loader in loaders: - self.parse_da_loader(loader) + self.parse_da_loader(loader, self.dasetup) else: if not os.path.exists(loader): self.warning("Couldn't open " + loader) else: self.info("Using custom loader: " + loader) - self.parse_da_loader(loader) + self.parse_da_loader(loader, self.dasetup) def m_extract_emi(self, data): idx = data.find(b"\x4D\x4D\x4D\x01\x38\x00\x00\x00") @@ -211,7 +211,7 @@ class DAconfig(metaclass=LogBase): self.emiver = 0 self.emi = None - def parse_da_loader(self, loader): + def parse_da_loader(self, loader:str, dasetup:dict): try: with open(loader, 'rb') as bootldr: # data = bootldr.read() @@ -229,11 +229,11 @@ class DAconfig(metaclass=LogBase): da.v6 = v6 # if da.hw_code == 0x8127 and "5.1824" not in loader: # continue - if da.hw_code not in self.dasetup: + if da.hw_code not in dasetup: if da.hw_code != 0: - self.dasetup[da.hw_code] = [da] + dasetup[da.hw_code] = [da] else: - for ldr in self.dasetup[da.hw_code]: + for ldr in dasetup[da.hw_code]: found = False if da.hw_version == ldr.hw_version: if da.sw_version == ldr.sw_version: @@ -242,7 +242,7 @@ class DAconfig(metaclass=LogBase): break if not found: if da.hw_code != 0: - self.dasetup[da.hw_code].append(da) + dasetup[da.hw_code].append(da) return True except Exception as e: self.error("Couldn't open loader: " + loader + ". Reason: " + str(e)) diff --git a/mtkclient/Library/DA/legacy/dalegacy_lib.py b/mtkclient/Library/DA/legacy/dalegacy_lib.py index 5a3ae74..4c77f76 100755 --- a/mtkclient/Library/DA/legacy/dalegacy_lib.py +++ b/mtkclient/Library/DA/legacy/dalegacy_lib.py @@ -1117,7 +1117,7 @@ class DALegacy(metaclass=LogBase): self.mtk.daloader.progress.show_progress("Read", length, length, display) rq.put(None) worker.join(60) - return b"" + return True else: buffer = bytearray() bytestoread = length diff --git a/mtkclient/Library/DA/xflash/extension/xflash.py b/mtkclient/Library/DA/xflash/extension/xflash.py index 1fb1a27..da79d76 100755 --- a/mtkclient/Library/DA/xflash/extension/xflash.py +++ b/mtkclient/Library/DA/xflash/extension/xflash.py @@ -195,6 +195,11 @@ class xflashext(metaclass=LogBase): self.info("Patching da2 ...") # open("da2.bin","wb").write(da2) da2patched = bytearray(da2) + # Patch huawei security, rma state + pos = 0 + huawei = find_binary(da2, b"\x01\x2B\x03\xD1\x01\x23", pos) + if huawei is not None: + da2patched[huawei:huawei + 4] = b"\x00\x00\x00\x00" # Patch oppo security oppo = 0 pos = 0 diff --git a/mtkclient/Library/DA/xflash/xflash_lib.py b/mtkclient/Library/DA/xflash/xflash_lib.py index 34c603d..51d8a84 100755 --- a/mtkclient/Library/DA/xflash/xflash_lib.py +++ b/mtkclient/Library/DA/xflash/xflash_lib.py @@ -419,13 +419,15 @@ class DAXFlash(metaclass=LogBase): def get_da_version(self): data = self.send_devctrl(self.Cmd.GET_DA_VERSION) - status = self.status() - if status == 0: - self.info(f"DA-VERSION : {data.decode('utf-8')}") - return data - else: - self.error(f"Error on getting chip id: {self.eh.status(status)}") - return None + if data != b"": + status = self.status() + if status == 0: + self.info(f"DA-VERSION : {data.decode('utf-8')}") + return data + else: + self.error(f"Error on getting chip id: {self.eh.status(status)}") + return None + return None def get_chip_id(self): class Chipid: @@ -437,19 +439,20 @@ class DAXFlash(metaclass=LogBase): chipid = Chipid data = self.send_devctrl(self.Cmd.GET_CHIP_ID) - chipid.hw_code, chipid.hw_sub_code, chipid.hw_version, chipid.sw_version, chipid.chip_evolution = unpack( + if data != b"": + chipid.hw_code, chipid.hw_sub_code, chipid.hw_version, chipid.sw_version, chipid.chip_evolution = unpack( " bytes: global rq partinfo = self.getstorage(parttype, length) - if not partinfo: + if not partinfo and not filename: return b"" + elif not partinfo: + return False self.mtk.daloader.progress.clear() storage, parttype, length = partinfo self.get_packet_length() @@ -823,10 +828,10 @@ class DAXFlash(metaclass=LogBase): self.mtk.daloader.progress.show_progress("Read", total, total, display) rq.put(None) worker.join(60) - return b"" + return True rq.put(None) worker.join(60) - return b"ACK" + return True else: buffer = bytearray() while length > 0: @@ -841,7 +846,9 @@ class DAXFlash(metaclass=LogBase): if display: self.mtk.daloader.progress.show_progress("Read", total, total, display) return buffer - return b"" + if not filename: + return b"" + return False class ShutDownModes: NORMAL = 0