コード例 #1
0
ファイル: session.py プロジェクト: WhySoGeeky/DroidPot
    def push_boot_partition(self, session, device_serial):
        # create new boot.img
        logging.debug("creating new boot partition")
        params = " ".join([session.extracted_boot_dir, session.new_bootimg_dir])
        cmd = Command()
        cmd.setCommand(self.tool.mkboot)
        cmd.setParameters(params)
        logging.debug(params)
        cmd.execute()

        time.sleep(5)

        # push new partition to device
        self.adb.reboot_bootloader(device_serial)
        time.sleep(5)

        fastboot_devices = self.fastboot.devices()
        for i in range(0, 5):
            if len(fastboot_devices) > 0:
                log.info("[*] Device found in bootloader mode")
                break
            else:
                log.info("[!] Could not detect device in bootloader mode. Retrying...")
                time.sleep(10)
                fastboot_devices = self.fastboot.devices()

            if i == 4:
                log.warning("[!] Could not detect device in bootloader mode. TIME OUT")
                return False

        # flash boot partition with fastboot
        # must be in sudo
        log.info("[*] Flashing partition with new image")

        self.fastboot.flash(partition="boot", image_path=session.new_bootimg_dir, device_serial=device_serial)

        time.sleep(5)
        self.fastboot.reboot(device_serial)
コード例 #2
0
ファイル: session.py プロジェクト: WhySoGeeky/DroidPot
    def get_and_extract_boot_partition(self, session, device_serial):
        self.start_logger.info("Extracting boot partition for modification")
        EXTRACTED_BOOT_LOC = "/sdcard/boot.img"

        # retrieve boot partition location
        retry = True
        while retry:
            log.warn("[*] Retrieving boot partition location...")
            command = "ls -al /dev/block/platform/msm_sdcc.1/by-name | grep ' boot'"
            result = self.adb.shell(command=command, device_serial=device_serial)

            boot_image_loc = ""

            for output in result.std_output:
                log.debug("result line: %s" % output)
                try:
                    output_split = output.split("-> ")
                    boot_image_loc = output_split[1]
                    boot_image_loc.replace("\r", "")
                    retry = False
                except IndexError:
                    log.debug("Cannot get boot partition location. Retrying.")
                    time.sleep(3)
                    pass

        time.sleep(5)

        # copy image locally
        log.info("[*] dd image on device...")
        command = "dd if=" + boot_image_loc + " of=" + EXTRACTED_BOOT_LOC
        result = self.adb.shell(root=True, command=command, device_serial=device_serial)

        if not result.isSuccess:
            raise OSError

        time.sleep(5)

        # pulling boot.img from device
        log.info("[*] Pulling boot.img from device...")
        self.adb.pull(source=EXTRACTED_BOOT_LOC, dest=session.partition_dir, device_serial=device_serial)

        time.sleep(5)

        # decompress boot.img
        log.info("[*] Decompressing boot.img with mkboot tool...")
        params = " ".join([session.bootimg_dir, session.extracted_boot_dir])

        log.debug("parameters are %s" % params)
        cmd = Command()
        cmd.setCommand(self.tool.mkboot)
        cmd.setParameters(params)
        logging.debug(params)
        cmd.execute()

        time.sleep(5)

        if not os.path.exists(session.extracted_boot_dir):
            self.start_logger.info("Extracting boot partition failed")
            return False
        else:
            return True