@cli.command('download-apks', help='Download all or non-safelisted installed APKs installed on the device')
@click.option('--serial', '-s', type=str, help=HELP_MSG_SERIAL)
@click.option('--all-apks', '-a', is_flag=True, help='Extract all packages installed on the phone, including system packages')
@click.option('--virustotal', '-v', is_flag=True, help='Check packages on VirusTotal')
@click.option('--koodous', '-k', is_flag=True, help='Check packages on Koodous')
@click.option('--all-checks', '-A', is_flag=True, help='Run all available checks')
@click.option('--output', '-o', type=click.Path(exists=False), help='Specify a path to a folder where you want to store the APKs')
@click.option('--from-file', '-f', type=click.Path(exists=True), help='Instead of acquiring from phone, load an existing packages.json file for lookups (mainly for debug purposes)')
@click.pass_context
def download_apks(ctx, all_apks, virustotal, koodous, all_checks, output, from_file, serial):
    try:
        if from_file:
            download = DownloadAPKs.from_json(from_file)
        else:
            if (not output):
                log.critical('You need to specify an output folder with --output!')
                ctx.exit(1)
            if (not os.path.exists(output)):
                try:
                    os.makedirs(output)
                except Exception as e:
                    log.critical('Unable to create output folder %s: %s', output, e)
                    ctx.exit(1)
            download = DownloadAPKs(output_folder=output, all_apks=all_apks, log=logging.getLogger(DownloadAPKs.__module__))
            if serial:
                download.serial = serial
            download.run()
        packages = download.packages
        if (len(packages) == 0):
            return
        if (virustotal or all_checks):
            virustotal_lookup(packages)
        if (koodous or all_checks):
            koodous_lookup(packages)
    except KeyboardInterrupt:
        print('')
        ctx.exit(1)
@cli.command('download-apks', help='Download all or non-safelisted installed APKs installed on the device')
@click.option('--serial', '-s', type=str, help=HELP_MSG_SERIAL)
@click.option('--all-apks', '-a', is_flag=True, help='Extract all packages installed on the phone, including system packages')
@click.option('--virustotal', '-v', is_flag=True, help='Check packages on VirusTotal')
@click.option('--koodous', '-k', is_flag=True, help='Check packages on Koodous')
@click.option('--all-checks', '-A', is_flag=True, help='Run all available checks')
@click.option('--output', '-o', type=click.Path(exists=False), help='Specify a path to a folder where you want to store the APKs')
@click.option('--from-file', '-f', type=click.Path(exists=True), help='Instead of acquiring from phone, load an existing packages.json file for lookups (mainly for debug purposes)')
@click.pass_context
def download_apks(ctx, all_apks, virustotal, koodous, all_checks, output, from_file, serial):
    try:
        if from_file:
            download = DownloadAPKs.from_json(from_file)
        else:
            if (not output):
                log.critical('You need to specify an output folder with --output!')
                ctx.exit(1)
            if (not os.path.exists(output)):
                try:
                    os.makedirs(output)
                except Exception as e:
                    log.critical('Unable to create output folder %s: %s', output, e)
                    ctx.exit(1)
            download = DownloadAPKs(output_folder=output, all_apks=all_apks, log=logging.getLogger(DownloadAPKs.__module__))
            if serial:
                download.serial = serial
            download.run()
        packages = download.packages
        if (len(packages) == 0):
            return
        if (virustotal or all_checks):
            virustotal_lookup(packages)
        if (koodous or all_checks):
            koodous_lookup(packages)
    except KeyboardInterrupt:
        print()
        ctx.exit(1)