示例#1
0
文件: edl.py 项目: yashomer1994/edl
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)
示例#2
0
文件: edl.py 项目: Ethern0T/edl
    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.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 = UsbClass(portconfig=portconfig,
                            loglevel=self.__logger.level)
        self.sahara = sahara(self.cdc, loglevel=self.__logger.level)

        if args["--loader"] == 'None':
            self.info("Trying with no loader given ...")
            self.sahara.programmer = ""
        else:
            loader = args["--loader"]
            self.info(f"Using loader {loader} ...")
            self.sahara.programmer = loader

        self.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.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.cmd_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.error(
                "Sorry, couldn't talk to Sahara, please reboot the device !")

        self.exit()