From 113b329991f4ea65a2e69c41d34eb9ea71b12464 Mon Sep 17 00:00:00 2001 From: Dinolek Date: Sat, 6 Jul 2024 14:00:26 +0200 Subject: [PATCH 1/4] Fix xiaomi edl auth check Signed-off-by: Dinolek --- edlclient/Library/Modules/xiaomi.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/edlclient/Library/Modules/xiaomi.py b/edlclient/Library/Modules/xiaomi.py index cfad5e2..7c3a221 100644 --- a/edlclient/Library/Modules/xiaomi.py +++ b/edlclient/Library/Modules/xiaomi.py @@ -42,8 +42,6 @@ def edl_auth(self): if rsp.resp: rsp = self.fh.xmlsend(self.xiaomi_authdata) if rsp.resp: - if "value" in rsp.resp: - if rsp.resp["value"] == "ACK": - if 'authenticated' in rsp.log[0].lower() and 'true' in rsp.log[0].lower(): - return True + if 'authenticated' in rsp.log[0].lower(): + return True return False From 5c1a562f54fb603e9987b665a123deceda5efa29 Mon Sep 17 00:00:00 2001 From: Dinolek Date: Sat, 6 Jul 2024 14:19:34 +0200 Subject: [PATCH 2/4] Base64 encode xiaomi encrypted token Signed-off-by: Dinolek --- edlclient/Library/Modules/xiaomi.py | 39 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/edlclient/Library/Modules/xiaomi.py b/edlclient/Library/Modules/xiaomi.py index 7c3a221..1eed6d0 100644 --- a/edlclient/Library/Modules/xiaomi.py +++ b/edlclient/Library/Modules/xiaomi.py @@ -6,6 +6,7 @@ # !!!!! If you use this code in commercial products, your product is automatically # GPLv3 and has to be open sourced under GPLv3 as well. !!!!! +import base64 import logging from edlclient.Library.utils import LogBase @@ -14,19 +15,13 @@ class xiaomi(metaclass=LogBase): def __init__(self, fh, projid="18825", serial=123456, ATOBuild=0, Flash_Mode=0, cf=0, supported_functions=None, loglevel=logging.INFO): self.fh = fh - self.xiaomi_authdata = b"\x93\x6E\x3A\x8E\x57\x3C\xAD\x07\xC1\x67\x64\x4B\x61\x21\x78\x35\xD8\x5A\xD4\xFD" + \ - b"\xDB\x7D\x84\x0A\x2B\x72\x25\x43\x2F\xCD\xA1\x3A\x7C\x19\x2C\xFA\x97\x9E\xD1\x65" + \ - b"\x17\xE6\x97\x0B\x1B\x07\xDF\x6C\x51\x6F\xEC\x81\xF6\x96\x8F\xCF\x7F\xFD\xDB\xC3" + \ - b"\x97\xA1\x62\xC2\xCA\x3E\x5D\x76\x12\x4A\xA1\x76\x9F\x1B\x21\x64\xB3\x9B\x76\x93" + \ - b"\x0B\x4C\xC6\x75\x19\xF7\xF3\x39\x87\x76\x77\xF4\xE8\xAF\x25\x82\x86\x82\xBC\xBF" + \ - b"\x4E\x59\x3A\x57\xE7\xE3\x05\x32\x69\x92\x53\xE0\xB1\xCC\x5D\x9D\x0D\x55\x4A\xF2" + \ - b"\xBD\x46\xD5\x6F\x18\xD6\xE5\x29\x0B\xA4\xA0\xCA\xC2\x43\x1F\x9F\x19\xC4\xC1\xA3" + \ - b"\x9D\x76\x64\xFF\xAB\x48\xA9\xE1\x1A\x55\x93\x86\x81\x98\x35\xB8\x4D\xF5\x67\x5E" + \ - b"\x70\xD2\x5F\xDB\x51\x23\xE7\xB0\x40\xFE\x21\x10\x8F\x0A\xE6\xD7\xD9\xD2\x67\xF2" + \ - b"\xC9\xC6\x1A\xD0\x54\xC6\x84\x93\xDC\x4D\x33\xF7\x4D\x0C\xF2\xD4\xAA\xDC\xD4\x30" + \ - b"\x15\x2D\xB6\x7C\x22\xA1\x81\xAD\x6D\x77\x61\x63\x7F\x70\xCB\xDA\x88\x4C\xDC\x11" + \ - b"\x33\x72\x03\x83\x77\x90\xE6\x84\x5C\xA5\xA8\x76\x79\x30\xB9\xC2\x6F\xDA\x71\x27" + \ - b"\x25\x64\xCA\x34\x76\x3D\x35\x2F\x5F\xE4\x2A\xB7\x38\xFB\x38\xA5" + self.xiaomi_authdata = [ + # "QlJORVVnSXVRSTJscjhrU1dDQ3E1dWM3ZnpoRw==" + "k246jlc8rQfBZ2RLYSF4Ndha1P3bfYQKK3IlQy/NoTp8GSz6l57RZRfmlwsbB99sUW/sgfaWj89//dvDl6Fiwso" + "+XXYSSqF2nxshZLObdpMLTMZ1GffzOYd2d/ToryWChoK8v05ZOlfn4wUyaZJT4LHMXZ0NVUryvUbVbxjW5SkLpKDKwkMfnxnEwaOddmT" + "/q0ip4RpVk4aBmDW4TfVnXnDSX9tRI+ewQP4hEI8K5tfZ0mfyycYa0FTGhJPcTTP3TQzy1Krc1DAVLbZ8IqGBrW13YWN" + "/cMvaiEzcETNyA4N3kOaEXKWodnkwucJv2nEnJWTKNHY9NS9f5Cq3OPs4pQ==" + ] self.__logger.setLevel(loglevel) if loglevel == logging.DEBUG: logfilename = "log.txt" @@ -38,10 +33,16 @@ def edl_auth(self): Redmi A1, Poco F1, Redmi 5 Pro, 6 Pro, 7 Pro, 7A, 8, 8A, 8A Dual, 8A Pro, Y2, S2 """ authcmd = b" " - rsp = self.fh.xmlsend(authcmd) - if rsp.resp: - rsp = self.fh.xmlsend(self.xiaomi_authdata) - if rsp.resp: - if 'authenticated' in rsp.log[0].lower(): - return True + for authdata in self.xiaomi_authdata: + rsp = self.fh.xmlsend(authcmd) + if not rsp.resp: + continue + + rsp = self.fh.xmlsend(base64.b64decode(authdata)) + if not rsp.resp: + continue + + if 'authenticated' in rsp.log[0].lower(): + return True + return False From ec43594ccd46111cf873dba8dfca5cac90fb0e0d Mon Sep 17 00:00:00 2001 From: Dinolek Date: Sat, 6 Jul 2024 14:21:07 +0200 Subject: [PATCH 3/4] Add xiaomi empty token(works on --- edlclient/Library/Modules/xiaomi.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/edlclient/Library/Modules/xiaomi.py b/edlclient/Library/Modules/xiaomi.py index 1eed6d0..c9d730d 100644 --- a/edlclient/Library/Modules/xiaomi.py +++ b/edlclient/Library/Modules/xiaomi.py @@ -20,7 +20,14 @@ def __init__(self, fh, projid="18825", serial=123456, ATOBuild=0, Flash_Mode=0, "k246jlc8rQfBZ2RLYSF4Ndha1P3bfYQKK3IlQy/NoTp8GSz6l57RZRfmlwsbB99sUW/sgfaWj89//dvDl6Fiwso" "+XXYSSqF2nxshZLObdpMLTMZ1GffzOYd2d/ToryWChoK8v05ZOlfn4wUyaZJT4LHMXZ0NVUryvUbVbxjW5SkLpKDKwkMfnxnEwaOddmT" "/q0ip4RpVk4aBmDW4TfVnXnDSX9tRI+ewQP4hEI8K5tfZ0mfyycYa0FTGhJPcTTP3TQzy1Krc1DAVLbZ8IqGBrW13YWN" - "/cMvaiEzcETNyA4N3kOaEXKWodnkwucJv2nEnJWTKNHY9NS9f5Cq3OPs4pQ==" + "/cMvaiEzcETNyA4N3kOaEXKWodnkwucJv2nEnJWTKNHY9NS9f5Cq3OPs4pQ==", + + # "\0" + "vzXWATo51hZr4Dh+a5sA/Q4JYoP4Ee3oFZSGbPZ2tBsaMupn" + "+6tPbZDkXJRLUzAqHaMtlPMKaOHrEWZysCkgCJqpOPkUZNaSbEKpPQ6uiOVJpJwA" + "/PmxuJ72inzSPevriMAdhQrNUqgyu4ATTEsOKnoUIuJTDBmzCeuh/34SOjTdO4Pc+s3ORfMD0TX+WImeUx4c9xVdSL/xirPl" + "/BouhfuwFd4qPPyO5RqkU/fevEoJWGHaFjfI302c9k7EpfRUhq1z+wNpZblOHuj0B3/7VOkK8KtSvwLkmVF" + "/t9ECiry6G5iVGEOyqMlktNlIAbr2MMYXn6b4Y3GDCkhPJ5LUkQ==" ] self.__logger.setLevel(loglevel) if loglevel == logging.DEBUG: From f2a04c833c0fc2e96349dc5728f862b81693fb5d Mon Sep 17 00:00:00 2001 From: Dinolek Date: Sun, 7 Jul 2024 13:22:32 +0200 Subject: [PATCH 4/4] Lazy init modules Fixes "ERROR: Only nop and sig tag can be recevied before authentication." message before authentification Signed-off-by: Dinolek --- edlclient/Library/Modules/init.py | 29 ++++++++++++++++++----------- edlclient/Library/firehose.py | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/edlclient/Library/Modules/init.py b/edlclient/Library/Modules/init.py index 619bd8f..6d69c76 100644 --- a/edlclient/Library/Modules/init.py +++ b/edlclient/Library/Modules/init.py @@ -7,6 +7,8 @@ # GPLv3 and has to be open sourced under GPLv3 as well. !!!!! import logging +from functools import cached_property + from edlclient.Library.utils import LogBase try: @@ -52,25 +54,31 @@ def __init__(self, fh, serial: int, supported_functions, loglevel, devicemodel: self.__logger.addHandler(fh) self.options = {} self.devicemodel = devicemodel - self.generic = None + + @cached_property + def generic(self): try: - self.generic = generic(fh=self.fh, serial=self.serial, args=self.args, loglevel=loglevel) + return generic(fh=self.fh, serial=self.serial, args=self.args, loglevel=self.__logger.loglevel) except Exception as e: self.error(e) - pass - self.ops = None + return None + + @cached_property + def ops(self): try: - self.ops = oneplus(fh=self.fh, projid=self.devicemodel, serial=self.serial, - supported_functions=self.supported_functions, args=self.args, loglevel=loglevel) + return oneplus(fh=self.fh, projid=self.devicemodel, serial=self.serial, loglevel=self.__logger.loglevel, + supported_functions=self.supported_functions, args=self.args) except Exception as e: self.error(e) - pass - self.xiaomi = None + return None + + @cached_property + def xiaomi(self): try: - self.xiaomi = xiaomi(fh=self.fh) + return xiaomi(fh=self.fh) except Exception as e: self.error(e) - pass + return None def addpatch(self): if self.ops is not None: @@ -116,7 +124,6 @@ def run(self, command, args): return self.generic.oem_unlock(enable) elif self.ops is not None and command == "ops": if self.devicemodel is not None: - enable = False partition = "param" if "enable" in options: enable = True diff --git a/edlclient/Library/firehose.py b/edlclient/Library/firehose.py index c9ab0f0..c903c3d 100755 --- a/edlclient/Library/firehose.py +++ b/edlclient/Library/firehose.py @@ -915,6 +915,7 @@ def configure(self, lvl): except Exception as err: # pylint: disable=broad-except self.modules = None if self.modules.edlauth(): + self.info("EDL Authenticated successfully.") rsp = self.xmlsend(connectcmd) return rsp.resp else: