diff --git a/mtkclient/Library/Port.py b/mtkclient/Library/Port.py index e222488..58f7841 100755 --- a/mtkclient/Library/Port.py +++ b/mtkclient/Library/Port.py @@ -116,7 +116,7 @@ class Port(metaclass=LogBase): sys.stdout.flush() except Exception as serr: - print("Handshake: " + str(serr)) + print(f"Handshake: {str(serr)}") if "access denied" in str(serr): self.warning(str(serr)) self.debug(str(serr)) @@ -194,13 +194,13 @@ class Port(metaclass=LogBase): else: cmdrsp = self.usbread(dlen) if cmdrsp[0] is not value[0]: - self.error("Cmd error :" + hexlify(cmdrsp).decode('utf-8')) + self.error(f"Cmd error :{hexlify(cmdrsp).decode('utf-8')}") return -1 if bytestoread > 0: resp = self.usbread(bytestoread) return resp else: - self.warning("Couldn't send :" + hexlify(value).decode('utf-8')) + self.warning(f"Couldn't send :{hexlify(value).decode('utf-8')}") return resp def echo(self, data): diff --git a/mtkclient/Library/gpt.py b/mtkclient/Library/gpt.py index 7b61c4b..4a585fb 100755 --- a/mtkclient/Library/gpt.py +++ b/mtkclient/Library/gpt.py @@ -328,9 +328,8 @@ class gpt(metaclass=LogBase): def print_gptfile(self, filename): try: - filesize = os.stat(filename).st_size with open(filename, "rb") as rf: - size = min(32 * 4096, filesize) + size = min(32 * 4096, os.stat(filename).st_size) data = rf.read(size) for sectorsize in [512, 4096]: result = self.parse(data, sectorsize) diff --git a/mtkclient/Library/pltools.py b/mtkclient/Library/pltools.py index 4bbe045..39a90d8 100755 --- a/mtkclient/Library/pltools.py +++ b/mtkclient/Library/pltools.py @@ -76,7 +76,7 @@ class PLTools(metaclass=LogBase): ack = self.exploit.runpayload(payload, ack, addr, dontack) if ack == ack: - self.info("Successfully sent payload: " + filename) + self.info(f"Successfully sent payload: {filename}") self.mtk.daloader.patch = True return True elif ack == b"\xc1\xc2\xc3\xc4": @@ -87,20 +87,20 @@ class PLTools(metaclass=LogBase): print_progress(0, 100, prefix='Progress:', suffix='Complete', bar_length=50) for pos in range(0, 0x40000, 64): wf.write(self.mtk.port.usbread(64)) - self.info("Preloader dumped as: " + "preloader.bin") + self.info("Preloader dumped as: preloader.bin") return True else: with open("out.bin", 'wb') as wf: print_progress(0, 100, prefix='Progress:', suffix='Complete', bar_length=50) for pos in range(0, 0x20000, 64): wf.write(self.mtk.port.usbread(64)) - self.info("Bootrom dumped as: " + "out.bin") + self.info("Bootrom dumped as: out.bin") return True - self.error("Error on sending payload: " + filename) + self.error(f"Error on sending payload: {filename}") return False else: - self.error("Error on sending payload: " + filename) - self.error("Error, payload answered instead: " + hexlify(ack).decode('utf-8')) + self.error(f"Error on sending payload: {filename}") + self.error(f"Error, payload answered instead: {hexlify(ack).decode('utf-8')}") return False def runbrute(self, args): @@ -138,16 +138,16 @@ class PLTools(metaclass=LogBase): self.info("Kamakiri / DA Run") if self.runpayload(filename=pfilename, ack=0xC1C2C3C4, offset=0): if self.exploit.dump_brom(filename): - self.info("Dumped as: " + filename) + self.info(f"Dumped as:{filename} ") return True else: - self.error("Error on sending payload: " + filename) + self.error(f"Error on sending payload: {filename}") else: if self.exploit.dump_brom(filename, length=length): - self.info("Dumped as: " + filename) + self.info(f"Dumped as: {filename}") return True else: - self.error("Error on sending payload: " + pfilename) + self.error(f"Error on sending payload: {pfilename}") return False def run_dump_preloader(self, filename): @@ -158,11 +158,11 @@ class PLTools(metaclass=LogBase): data, filename = self.exploit.dump_preloader() return data, filename else: - self.error("Error on sending payload: " + pfilename) + self.error(f"Error on sending payload: {pfilename}") return None, None else: if self.exploit.dump_brom(filename): - self.info("Preloader dumped as: " + filename) + self.info(f"Preloader dumped as: {filename}") return True else: self.error("Error on dumping preloader") diff --git a/mtkclient/Library/utils.py b/mtkclient/Library/utils.py index 19ff42e..8f8e646 100755 --- a/mtkclient/Library/utils.py +++ b/mtkclient/Library/utils.py @@ -323,17 +323,13 @@ def do_tcp_server(client, arguments, handler): for line in lines: if ":" in line: cmd = line.split(":")[0] - marguments = line.split(":")[1] try: - opts = parse_args(cmd, marguments, arguments) + opts = parse_args(cmd, line.split(":")[1], arguments) except Exception: response = "Wrong arguments\n\n" opts = None if opts is not None: - if handler(cmd, opts): - response = "\n" - else: - response = "\n" + response = "\n" if handler(cmd, opts) else "\n" connection.sendall(bytes(response, 'utf-8')) finally: connection.close() @@ -341,11 +337,7 @@ def do_tcp_server(client, arguments, handler): def parse_args(cmd, args, mainargs): options = {} - opts = None - if "," in args: - opts = args.split(",") - else: - opts = [args] + opts = args.split(",") if "," in args else [args] for arg in mainargs: if "--" in arg: options[arg] = mainargs[arg] @@ -605,7 +597,7 @@ class elf: elif self.elfclass == 2: # 64Bit start = 0x34 else: - print("Error on parsing " + self.filename) + print(f"Error on parsing {self.filename}") return ['', ''] elfheadersize, programheaderentrysize, programheaderentrycount = struct.unpack("