diff --git a/edlclient/Library/Modules/oneplus.py b/edlclient/Library/Modules/oneplus.py index d4b4baf..c87daa7 100755 --- a/edlclient/Library/Modules/oneplus.py +++ b/edlclient/Library/Modules/oneplus.py @@ -1,4 +1,4 @@ -v#!/usr/bin/env python3 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # (c) B.Kerler 2018-2023 under GPLv3 license # If you use my code, make sure you refer to my name @@ -24,7 +24,7 @@ import random from struct import pack import logging from edlclient.Library.utils import LogBase - +from edlclient.Library.Modules.oneplus_param import paramtools try: from edlclient.Library.cryptutils import cryptutils except Exception as e: @@ -128,7 +128,7 @@ deviceconfig = { class oneplus(metaclass=LogBase): - def __init__(self, fh, projid="18825", serial=123456, ATOBuild=0, Flash_Mode=0, cf=0, supported_functions=None, + def __init__(self, fh, projid:str="18825", serial=123456, ATOBuild=0, Flash_Mode=0, cf=0, supported_functions=None, args=None, loglevel=logging.INFO): self.fh = fh self.__logger = self.__logger @@ -160,7 +160,6 @@ class oneplus(metaclass=LogBase): filehandler = logging.FileHandler(logfilename) self.__logger.addHandler(filehandler) try: - from edlclient.Library.Modules.oneplus_param import paramtools if projid in deviceconfig: mode = deviceconfig[projid]["param_mode"] self.ops_parm = paramtools(mode=mode, serial=serial) @@ -226,16 +225,16 @@ class oneplus(metaclass=LogBase): if self.ops.setprojmodel_verify: return self.ops.setprojmodel_verify(pk, token) - def setswprojmodel_verify(self, pk, token, device_timestamp): + def setswprojmodel_verify(self, pk, token): if self.ops.setswprojmodel_verify: - return self.ops.setswprojmodel_verify(pk, token, device_timestamp) + return self.ops.setswprojmodel_verify(pk, token) def program_verify(self, pk, token, tokendata): if self.ops.program_verify: return self.ops.program_verify(pk, token, tokendata) - def generatetoken(self, program=False, device_timestamp="123456789"): - return self.ops.generatetoken(program=program, device_timestamp=device_timestamp) + def generatetoken(self, program=False): + return self.ops.generatetoken(program=program) def demacia(self): if self.ops.demacia(): @@ -311,7 +310,7 @@ class oneplus1: data = "\n\n\n" return data - def generatetoken(self, program=False, device_timestamp=None): + def generatetoken(self, program=False): timestamp = str(int(time.time())) ha = cryptutils().hash() h1 = self.prodkey + self.ModelVerifyPrjName + self.random_postfix @@ -430,6 +429,7 @@ class oneplus1: class oneplus2(metaclass=LogBase): def __init__(self, fh, ModelVerifyPrjName="20889", serial=123456, pk="", prodkey="", ATOBuild=0, Flash_Mode=0, cf=0, loglevel=logging.INFO): + self.device_timestamp = None self.ModelVerifyPrjName = ModelVerifyPrjName self.pk = pk self.fh = fh @@ -446,11 +446,10 @@ class oneplus2(metaclass=LogBase): fh = logging.FileHandler(logfilename) self.__logger.addHandler(fh) - def crypt_token(self, data, pk, device_timestamp, decrypt=False): - timestamp = str(int(time.time())) + def crypt_token(self, data, pk, device_timestamp:int, decrypt=False): aes = cryptutils().aes() aeskey = b"\x46\xA5\x97\x30\xBB\x0D\x41\xE8" + bytes(pk, 'utf-8') + \ - pack("\"") # Response should be : - pk, token = op2.generatetoken(False, device_timestamp) + pk, token = op2.generatetoken(False) print( f"./edl.py rawxml \"\" --debugmode") @@ -607,9 +609,10 @@ def main(): projid = args["--projid"][0] device_timestamp = args["--ts"] op = oneplus(None, projid=projid, serial=123456) + op.ops.device_timestamp = int(device_timestamp) token = args[""] pk = args[""] - op.setswprojmodel_verify(pk, token, device_timestamp) + op.setswprojmodel_verify(pk, token) def test_setswprojmodel_verify(): @@ -619,8 +622,9 @@ def test_setswprojmodel_verify(): op = oneplus(None, projid=projid, serial=123456) data = deviceresp.decode('utf-8') device_timestamp = data[data.rfind("device_timestamp"):].split("\"")[1] - pk, token = op.generatetoken(False, device_timestamp) - if not op.setswprojmodel_verify(pk, token, device_timestamp): + op.ops.device_timestamp = int(device_timestamp) + pk, token = op.generatetoken(False) + if not op.setswprojmodel_verify(pk, token): assert "Setswprojmodel error"