Exemple #1
0
    def list_devices():
        logging.info("Getting list of devices")
        adb_location = Utils.get_adb_location()
        command = """{} devices""".format(adb_location)
        info = subprocess.Popen(command, shell=True,
                                stdout=subprocess.PIPE).stdout.read()

        devices = []

        for device in info.decode().splitlines():
            if 'devices attached' in device:
                continue

            device_serial = device.split('\t')[0].strip()

            if not device_serial:
                continue

            if '\tunauthorized' in device:
                logging.warning(
                    "{} unauthorized. Trust this device. Ignoring...".format(
                        device_serial))
                continue

            devices.append(device_serial)

        message = "Found {} device".format(len(devices))
        if (len(devices) != 1):
            message += "s"

        logging.info("{}".format(message))
        return devices
Exemple #2
0
    def __init__(self):
        self.internal_data_path = "/data/data/{}"
        self.external_data_path = "/sdcard/Android/data/{}"
        self.internal_data_dump_name = "{}_internal.tar.gz"
        self.external_data_dump_name = "{}_external.tar.gz"

        #Dump internal data https://android.stackexchange.com/questions/85564/need-one-line-adb-shell-su-push-pull-to-access-data-from-windows-batch-file
        self.check_root_command = """{} -s {} shell "su -c 'echo HASROOT'"""
        self.magic_root_command = """{} -s {} shell "su -c 'cd {} && tar czf - ./ --exclude='./files'| base64' 2>/dev/null" | {} -d"""
        self.magic_noroot_command = """{} -s {} shell "cd {} && tar czf - ./ --exclude='./files'| base64 2>/dev/null" | {} -d"""

        if not (
                Utils.get_platform().startswith("windows")
                or Utils.get_platform().startswith("darwin")
        ):  #some linux versions doesn't output if contains errors, so we ignore it. but base64 for windows doesn't have this attribute
            self.magic_root_command += "i"  #add -i flag to base64 decode to avoid some encoding issues
            self.magic_noroot_command += "i"  #add -i flag to base64 decode to avoid some encoding issues

        self.adb_location = Utils.get_adb_location()
        self.base64_location = Utils.get_base64_location()

        self.dumps_path = os.path.join(Utils.get_base_path_folder(), "dumps")
        Utils.check_and_generate_folder(self.dumps_path)

        self.path_dump_folder = os.path.join(self.dumps_path,
                                             Utils.get_current_time())