def __init__(self, mtk, portconfig, loglevel=logging.INFO): self.config = mtk.config self.mtk = mtk self.__logger = self.__logger self.cdc = usb_class(portconfig=portconfig, loglevel=loglevel, devclass=10) self.info = self.__logger.info self.error = self.__logger.error self.warning = self.__logger.warning self.debug = self.__logger.debug self.usbread = self.cdc.usbread self.usbwrite = self.cdc.usbwrite self.close = self.cdc.close self.rdword = self.cdc.rdword self.rword = self.cdc.rword self.rbyte = self.cdc.rbyte self.detectusbdevices = self.cdc.detectusbdevices self.usbreadwrite = self.cdc.usbreadwrite if loglevel == logging.DEBUG: logfilename = os.path.join("logs", "log.txt") if os.path.exists(logfilename): os.remove(logfilename) fh = logging.FileHandler(logfilename) self.__logger.addHandler(fh) self.__logger.setLevel(logging.DEBUG) else: self.__logger.setLevel(logging.INFO)
def connect(self): self.cdc = usb_class(portconfig=self.portconfig, loglevel=self.__logger.level) self.hdlc = None if self.cdc.connect(self.ep_in, self.ep_out): self.hdlc = hdlc(self.cdc) data = self.hdlc.receive_reply(1) return True return False
def connect(self): self.cdc = usb_class(self.vidpid, interface=self.interface, log=self.log) self.hdlc = None if self.cdc.connect(self.ep_in, self.ep_out): self.hdlc = hdlc(self.cdc) return True return False
def __init__(self, args, loglevel=logging.INFO): self.__logger = self.__logger self.args = args self.info = self.__logger.info self.error = self.__logger.error self.warning = self.__logger.warning if loglevel == logging.DEBUG: logfilename = os.path.join("logs", "log.txt") if os.path.exists(logfilename): os.remove(logfilename) fh = logging.FileHandler(logfilename) self.__logger.addHandler(fh) self.__logger.setLevel(logging.DEBUG) else: self.__logger.setLevel(logging.INFO) portconfig = [[0x0E8D, 0x0003, -1], [0x0E8D, 0x2000, -1]] self.cdc = usb_class(portconfig=portconfig, loglevel=loglevel, devclass=10)
"loggers": { "": { "handlers": ["root"], "level": log_level, "propagate": False } }, } logging.config.dictConfig(LOG_CONFIG) logging.info("[INFO] firehose image: %s" % args.firehose) logging.info("[INFO] rawprogram files: %s" % str(args.rawprogram)) logging.info("[INFO] patch files: %s" % str(args.patch)) logging.info("[INFO] USB device 0x%04x:0x%04x" % (args.vid, args.pid)) cdc = usb_class(vid=args.vid, pid=args.pid) cdc.timeout = 100 sahara = qualcomm_sahara(cdc) logging.info("[USB] waiting for device connecting...") while True: if cdc.connect(): break else: time.sleep(1) logging.info("[SAHARA] reading firehose images.") fl = open(args.firehose, "rb") sahara.programmer = fl.read() fl.close()
def main(): global LOGGER mode = "" loop = 0 vid = int(args["--vid"], 16) pid = int(args["--pid"], 16) usbids = [[vid, pid], [0x05c6, 0x9008], [0x05c6, 0x900e], [0x05c6, 0x9025], [0x1199, 0x9062], [0x1199, 0x9070], [0x1199, 0x9090], [0x0846, 0x68e0]] filename = "log.txt" if args["--debugmode"]: LOGGER = log_class(logging.DEBUG, filename) # ch = logging.StreamHandler() # ch.setLevel(logging.ERROR) else: LOGGER = log_class(logging.INFO, filename) cdc = usb_class(usbids, log=LOGGER, interface=-1) sahara = qualcomm_sahara(cdc) if args["--loader"] == 'None': LOGGER.info("Trying with no loader given ...") sahara.programmer = "" else: loader = args["--loader"] LOGGER.info(f"Using loader {loader} ...") sahara.programmer = loader LOGGER.info("Waiting for the device") resp = None cdc.timeout = 100 LOGGER.debug("Ohuh") mode, resp = doconnect(cdc, loop, mode, resp, sahara) if resp == -1: mode, resp = doconnect(cdc, loop, mode, resp, sahara) if resp == -1: LOGGER.error("USB desync, please rerun command !") sys.exit() # print((mode, resp)) if mode == "sahara": if resp == None: if mode == "sahara": print("Sahara in error state, resetting ...") sahara.cmd_reset() exit(cdc) elif "mode" in resp: mode = resp["mode"] if mode == sahara.sahara_mode.SAHARA_MODE_MEMORY_DEBUG: if args["memorydump"]: time.sleep(0.5) print("Device is in memory dump mode, dumping memory") sahara.debug_mode() exit(cdc) else: print("Device is in streaming mode, uploading loader") cdc.timeout = None sahara_info = sahara.streaminginfo() if sahara_info: mode, resp = sahara.connect() if mode == "sahara": mode = sahara.upload_loader() if "enprg" in sahara.programmer.lower(): mode = "load_enandprg" elif "nprg" in sahara.programmer.lower(): mode = "load_nandprg" elif mode != "": mode = "load_" + mode if "load_" in mode: time.sleep(0.3) else: print( "Error, couldn't find suitable enprg/nprg loader :(" ) exit(cdc) else: print("Device is in EDL mode .. continuing.") cdc.timeout = None sahara_info = sahara.info() if sahara_info: mode, resp = sahara.connect() if mode == "sahara": mode = sahara.upload_loader() if mode == "firehose": if "enprg" in sahara.programmer.lower(): mode = "enandprg" elif "nprg" in sahara.programmer.lower(): mode = "nandprg" if mode != "": if mode != "firehose": streaming = QualcommStreaming(cdc, sahara) if streaming.connect(1): print( "Successfully uploaded programmer :)") mode = "nandprg" else: print("Device is in an unknown state") exit(cdc) else: print("Successfully uploaded programmer :)") else: print("No suitable loader found :(") exit(cdc) else: print("Device is in an unknown sahara state") print("resp={0}".format(resp)) exit(cdc) else: print("Device is in an unknown state") exit(cdc) else: sahara.bit64 = True if mode == "firehose": cdc.timeout = None fh = firehose_client(args, cdc, sahara, LOGGER, print) cmd = parse_cmd(args) options = parse_option(args) if cmd != "": fh.handle_firehose(cmd, options) elif mode == "nandprg" or mode == "enandprg" or mode == "load_nandprg" or mode == "load_enandprg": sc = streaming_client(args, cdc, sahara, LOGGER, print) cmd = parse_cmd(args) options = parse_option(args) if "load_" in mode: options["<mode>"] = 1 else: options["<mode>"] = 0 sc.handle_streaming(cmd, options) else: LOGGER.error( "Sorry, couldn't talk to Sahara, please reboot the device !") exit(cdc)
}, "loggers": { "": { "handlers": ["root"], "level": log_level, "propagate": False } }, } logging.config.dictConfig(LOG_CONFIG) logging.info("[INFO] firehose image: %s" % args.firehose) logging.info("[INFO] rawprogram files: %s" % str(args.rawprogram)) logging.info("[INFO] patch files: %s" % str(args.patch)) logging.info("[INFO] USB device 0x%04x:0x%04x" % (args.vid, args.pid)) cdc = usb_class(vidpid=[args.vid, args.pid]) cdc.timeout = 100 sahara = qualcomm_sahara(cdc) logging.info("[USB] waiting for device connecting...") while True: if cdc.connect(): break time.sleep(1) logging.info("[SAHARA] reading firehose images.") fl = open(args.firehose, "rb") sahara.programmer = fl.read() fl.close() logging.info("[SAHARA] connecting...")
def run(self): if sys.platform == 'win32' or sys.platform == 'win64' or sys.platform == 'winnt': proper_driver = self.console_cmd( r'reg query HKLM\HARDWARE\DEVICEMAP\SERIALCOMM') if re.findall(r'QCUSB', str(proper_driver)): self.__logger.warning( f'Please first install libusb_win32 driver from Zadig') mode = "" loop = 0 vid = int(args["--vid"], 16) pid = int(args["--pid"], 16) interface = -1 if vid != -1 and pid != -1: portconfig = [[vid, pid, interface]] else: portconfig = default_ids if args["--debugmode"]: logfilename = "log.txt" if os.path.exists(logfilename): os.remove(logfilename) fh = logging.FileHandler(logfilename) self.__logger.addHandler(fh) self.__logger.setLevel(logging.DEBUG) else: self.__logger.setLevel(logging.INFO) self.cdc = usb_class(portconfig=portconfig, loglevel=self.__logger.level) self.sahara = sahara(self.cdc, loglevel=self.__logger.level) if args["--loader"] == 'None': self.__logger.info("Trying with no loader given ...") self.sahara.programmer = "" else: loader = args["--loader"] self.__logger.info(f"Using loader {loader} ...") self.sahara.programmer = loader self.__logger.info("Waiting for the device") resp = None self.cdc.timeout = 100 mode, resp = self.doconnect(loop, mode, resp) if resp == -1: mode, resp = self.doconnect(loop, mode, resp) if resp == -1: self.__logger.error("USB desync, please rerun command !") self.exit() # print((mode, resp)) if mode == "sahara": if resp is None: if mode == "sahara": print("Sahara in error state, resetting ...") self.sahara.cmd_reset() data = self.cdc.read(5) self.exit() elif "mode" in resp: mode = resp["mode"] if mode == self.sahara.sahara_mode.SAHARA_MODE_MEMORY_DEBUG: if args["memorydump"]: time.sleep(0.5) print("Device is in memory dump mode, dumping memory") self.sahara.debug_mode() self.exit() else: print("Device is in streaming mode, uploading loader") self.cdc.timeout = None sahara_info = self.sahara.streaminginfo() if sahara_info: mode, resp = self.sahara.connect() if mode == "sahara": mode = self.sahara.upload_loader() if "enprg" in self.sahara.programmer.lower(): mode = "load_enandprg" elif "nprg" in self.sahara.programmer.lower(): mode = "load_nandprg" elif mode != "": mode = "load_" + mode if "load_" in mode: time.sleep(0.3) else: print( "Error, couldn't find suitable enprg/nprg loader :(" ) self.exit() else: print("Device is in EDL mode .. continuing.") self.cdc.timeout = None sahara_info = self.sahara.info() if sahara_info: mode, resp = self.sahara.connect() if mode == "sahara": mode = self.sahara.upload_loader() if mode == "firehose": if "enprg" in self.sahara.programmer.lower(): mode = "enandprg" elif "nprg" in self.sahara.programmer.lower(): mode = "nandprg" if mode != "": if mode != "firehose": streaming = Streaming( self.cdc, self.sahara, self.__logger.level) if streaming.connect(1): print( "Successfully uploaded programmer :)" ) mode = "nandprg" else: print("Device is in an unknown state") self.exit() else: print( "Successfully uploaded programmer :)") else: print("No suitable loader found :(") self.exit() else: print( "Device is in an unknown sahara state, resetting") print("resp={0}".format(resp)) self.sahara.cmd_reset() self.exit() else: print("Device is in an unknown state") self.exit() else: self.sahara.bit64 = True if mode == "firehose": self.cdc.timeout = None fh = firehose_client(args, self.cdc, self.sahara, self.__logger.level, print) cmd = self.parse_cmd(args) options = self.parse_option(args) if cmd != "": fh.handle_firehose(cmd, options) elif mode == "nandprg" or mode == "enandprg" or mode == "load_nandprg" or mode == "load_enandprg": sc = streaming_client(args, self.cdc, self.sahara, self.__logger.level, print) cmd = self.parse_cmd(args) options = self.parse_option(args) if "load_" in mode: options["<mode>"] = 1 else: options["<mode>"] = 0 sc.handle_streaming(cmd, options) else: self.__logger.error( "Sorry, couldn't talk to Sahara, please reboot the device !") self.exit()