예제 #1
0
async def gen_main(cmd_input: Optional[List[str]] = None) -> int:
    # Make sure all files are created with global rw permissions
    os.umask(0o000)
    # Setup parser
    parser = argparse.ArgumentParser(
        description=
        "idb: a versatile tool to communicate with iOS Simulators and Devices",
        epilog="See Also: https://www.fbidb.io/docs/guided-tour",
        formatter_class=argparse.RawTextHelpFormatter,
    )
    parser.add_argument(
        "--log",
        dest="log_level",
        choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
        default="WARNING",
        help="Set the logging level",
    )
    parser.add_argument(
        "--compression",
        dest="compression",
        choices=[str(key) for (key, _) in Compression.__members__.items()],
        default=None,
        help="Compression algorithm, default: GZIP. "
        "Compressor should be available at this host. "
        "Decompressor should be available at the destination site (where IDB companion is hosted)",
    )
    parser.add_argument(
        "--companion",
        type=str,
        default=os.environ.get("IDB_COMPANION"),
        help=
        "A string of the form HOSTNAME:PORT that will describe the companion connect to."
        "Can also be set with the IDB_COMPANION environment variable",
    )
    parser.add_argument(
        "--companion-path",
        type=str,
        default=get_default_companion_path(),
        help=
        "The path to the idb companion binary. This is only valid when running on macOS platforms",
    )
    parser.add_argument(
        "--companion-local",
        action="store_true",
        default=bool(os.environ.get("IDB_COMPANION_LOCAL")),
        help=
        "If set, any companion provided via IDB_COMPANION or --companion will be assumed to be running on this host."
        "Even if the companion provided is 'localhost' idb will still assume it is remote."
        "The reason for this is that idb shouldn't assume there are no tunnels from localhost to a remote host."
        "Can also be set with the IDB_COMPANION_LOCAL environment variable",
    )
    parser.add_argument(
        "--companion-tls",
        action="store_true",
        default=bool(os.environ.get("IDB_COMPANION_TLS")),
        help=
        "Will force idb client to use TLS encrypted connection to companion."
        "Can also be set with the IDB_COMPANION_TLS environment variable",
    )
    parser.add_argument(
        "--no-prune-dead-companion",
        dest="prune_dead_companion",
        action="store_false",
        default=True,
        help=
        "If flagged will not modify local state when a companion is known to be unresponsive",
    )
    shell_command = ShellCommand(parser=parser)
    commands: List[Command] = [
        AppInstallCommand(),
        AppUninstallCommand(),
        AppListCommand(),
        LaunchCommand(),
        AppTerminateCommand(),
        CommandGroup(
            name="xctest",
            description="Operations with xctest on target",
            commands=[
                XctestInstallCommand(),
                XctestsListBundlesCommand(),
                XctestListTestsCommand(),
                XctestRunCommand,
            ],
        ),
        CommandGroup(
            name="file",
            description="File operations on target",
            commands=[
                FSMoveCommand(),
                FSPullCommand(),
                FSPushCommand(),
                FSMkdirCommand(),
                FSRemoveCommand(),
                FSListCommand(),
                FBSReadCommand(),
                FSWriteCommand(),
            ],
        ),
        CommandGroup(
            name="contacts",
            description="Contacts database operations on target",
            commands=[ContactsUpdateCommand()],
        ),
        LogCommand(),
        CommandGroup(
            name="record",
            description="Record what the screen is doing",
            commands=[VideoRecordCommand()],
        ),
        VideoRecordCommand(),
        VideoStreamCommand(),
        UrlOpenCommand(),
        KeychainClearCommand(),
        LocationSetCommand(),
        ApproveCommand(),
        TargetConnectCommand(),
        TargetDisconnectCommand(),
        TargetListCommand(),
        TargetDescribeCommand(),
        TargetCreateCommand(),
        TargetBootCommand(),
        TargetShutdownCommand(),
        TargetEraseCommand(),
        TargetCloneCommand(),
        TargetDeleteCommand(),
        TargetDeleteAllCommand(),
        DaemonCommand(),
        ScreenshotCommand(),
        CommandGroup(
            name="ui",
            description="UI interactions on target",
            commands=[
                AccessibilityInfoAllCommand(),
                AccessibilityInfoAtPointCommand(),
                TapCommand(),
                ButtonCommand(),
                TextCommand(),
                KeyCommand(),
                KeySequenceCommand(),
                SwipeCommand(),
            ],
        ),
        CommandGroup(
            name="crash",
            description="Operations on crashes",
            commands=[
                CrashListCommand(),
                CrashShowCommand(),
                CrashDeleteCommand()
            ],
        ),
        InstrumentsCommand(),
        KillCommand(),
        MediaAddCommand(),
        FocusCommand(),
        CommandGroup(
            name="debugserver",
            description="debugserver interactions",
            commands=[
                DebugServerStartCommand(),
                DebugServerStopCommand(),
                DebugServerStatusCommand(),
            ],
        ),
        CommandGroup(name="dsym",
                     description="dsym commands",
                     commands=[DsymInstallCommand()]),
        CommandGroup(name="dylib",
                     description="dylib commands",
                     commands=[DylibInstallCommand()]),
        CommandGroup(
            name="framework",
            description="framework commands",
            commands=[FrameworkInstallCommand()],
        ),
        CommandGroup(
            name="companion",
            description="commands related to the companion",
            commands=[CompanionLogCommand()],
        ),
        CommandGroup(
            name="xctrace",
            description="Run xctrace commands",
            commands=[XctraceRecordCommand()],
        ),
        SetCommand,
        GetCommand,
        ListCommand,
        shell_command,
    ]
    commands.extend(plugin.get_commands())
    root_command = CommandGroup(
        name="root_command",
        description="",
        commands=sorted(commands, key=lambda command: command.name),
    )
    root_command.add_parser_arguments(parser)
    shell_command.root_command = root_command

    # Parse input and run
    cmd_input = cmd_input or sys.argv[1:]

    try:
        args = parser.parse_args(cmd_input)
        plugin.on_launch(logger)
        await root_command.run(args)
        return 0
    except ConnectCommandException as e:
        print(str(e), file=sys.stderr)
        return 1
    except IdbException as e:
        print(e.args[0], file=sys.stderr)
        return 1
    except ExitWithCodeException as e:
        return e.exit_code
    except SystemExit as e:
        return e.code
    except Exception:
        logger.exception("Exception thrown in main")
        return 1
    finally:
        await plugin.on_close(logger)
        pending = set(asyncio.all_tasks())
        current_task = asyncio.current_task()
        if current_task is not None:
            pending.discard(current_task)
        await drain_coroutines(pending)
예제 #2
0
            help="Run these tests only. \
            if not specified all tests are run. \
            Format: className/methodName",
        )

    def get_tests_to_run(self, args: Namespace) -> Optional[Set[str]]:
        if args.test_to_run:
            return set(args.test_to_run)
        if args.tests_to_run:
            tests = ""
            for test in args.tests_to_run:
                tests += test + ","
            tests = tests[:-1]
            # the companion is expecting a set of size one for the logic tests,
            # that is why we parse it here
            return {tests}
        return None


XctestRunCommand = CommandGroup(
    name="run",
    description=(
        "Run an installed xctest. Any environment variables of the form IDB_X\n"
        " will be passed through with the IDB_ prefix removed."),
    commands=[
        XctestRunAppCommand(),
        XctestRunUICommand(),
        XctestRunLogicCommand(),
    ],
)
예제 #3
0
    def description(self) -> str:
        return "Lists available locale identifiers"

    @property
    def name(self) -> str:
        return "locale"

    async def run_with_client(self, args: Namespace, client: Client) -> None:
        locale_identifiers = await client.list_locale_identifiers()
        for locale_identifier in locale_identifiers:
            print(locale_identifier)


SetCommand = CommandGroup(
    name="set",
    description="Sets a preference on the target",
    commands=[SetHardwareKeyboardCommand(),
              SetLocaleCommand()],
)

GetCommand = CommandGroup(
    name="get",
    description="Gets a value from the target",
    commands=[GetLocaleCommand()],
)

ListCommand = CommandGroup(
    name="list",
    description="Lists values from the target",
    commands=[ListLocaleCommand()],
)
예제 #4
0
파일: main.py 프로젝트: guhappranavk/idb
async def gen_main(cmd_input: Optional[List[str]] = None, ) -> int:
    # Make sure all files are created with global rw permissions
    os.umask(0o000)
    # Setup parser
    parser = argparse.ArgumentParser(
        description=
        "idb: a versatile tool to communicate with iOS Simulators and Devices",
        epilog="See Also: https://www.fbidb.io/docs/guided-tour",
        formatter_class=argparse.RawTextHelpFormatter,
    )
    parser.add_argument(
        "--log",
        dest="log_level",
        choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
        default="WARNING",
        help="Set the logging level",
    )
    parser.add_argument(
        "--companion",
        type=str,
        default=os.environ.get("IDB_COMPANION"),
        help=
        "A string of the form HOSTNAME:PORT that will describe the companion connect to."
        "Can also be set with the IDB_COMPANION environment variable",
    )
    parser.add_argument(
        "--companion-path",
        type=str,
        default="/usr/local/bin/idb_companion",
        help="The path to the idb companion binary",
    )
    commands: List[Command] = [
        AppInstallCommand(),
        AppUninstallCommand(),
        AppListCommand(),
        LaunchCommand(),
        AppTerminateCommand(),
        CommandGroup(
            name="xctest",
            description="Operations with xctest on target",
            commands=[
                XctestInstallCommand(),
                XctestsListBundlesCommand(),
                XctestListTestsCommand(),
                XctestRunCommand(),
            ],
        ),
        CommandGroup(
            name="file",
            description="File operations on target",
            commands=[
                FSMoveCommand(),
                FSPullCommand(),
                FSPushCommand(),
                FSMkdirCommand(),
                FSRemoveCommand(),
                FSListCommand(),
            ],
        ),
        CommandGroup(
            name="contacts",
            description="Contacts database operations on target",
            commands=[ContactsUpdateCommand()],
        ),
        LogCommand(),
        CommandGroup(
            name="record",
            description="Record what the screen is doing",
            commands=[RecordVideoCommand()],
        ),
        RecordVideoCommand(),
        DeprecatedPushCommand(),
        DeprecatedPullCommand(),
        UrlOpenCommand(),
        KeychainClearCommand(),
        LocationSetCommand(),
        ApproveCommand(),
        TargetConnectCommand(),
        TargetDisconnectCommand(),
        TargetListCommand(),
        TargetDescribeCommand(),
        TargetBootCommand(),
        DaemonCommand(),
        ScreenshotCommand(),
        CommandGroup(
            name="ui",
            description="UI interactions on target",
            commands=[
                AccessibilityInfoAllCommand(),
                AccessibilityInfoAtPointCommand(),
                TapCommand(),
                ButtonCommand(),
                TextCommand(),
                KeyCommand(),
                KeySequenceCommand(),
                SwipeCommand(),
            ],
        ),
        CommandGroup(
            name="crash",
            description="Operations on crashes",
            commands=[
                CrashListCommand(),
                CrashShowCommand(),
                CrashDeleteCommand()
            ],
        ),
        InstrumentsCommand(),
        KillCommand(),
        MediaAddCommand(),
        FocusCommand(),
        CommandGroup(
            name="debugserver",
            description="debugserver interactions",
            commands=[
                DebugServerStartCommand(),
                DebugServerStopCommand(),
                DebugServerStatusCommand(),
            ],
        ),
        CommandGroup(name="dsym",
                     description="dsym commands",
                     commands=[DsymInstallCommand()]),
        CommandGroup(name="dylib",
                     description="dylib commands",
                     commands=[DylibInstallCommand()]),
        CommandGroup(
            name="framework",
            description="framework commands",
            commands=[FrameworkInstallCommand()],
        ),
        CommandGroup(
            name="companion",
            description="commands related to the companion",
            commands=[CompanionLogCommand()],
        ),
    ]
    commands.extend(plugin.get_commands())
    root_command = CommandGroup(
        name="root_command",
        description="",
        commands=sorted(commands, key=lambda command: command.name),
    )
    root_command.add_parser_arguments(parser)

    # Parse input and run
    cmd_input = cmd_input or sys.argv[1:]

    try:
        args = parser.parse_args(cmd_input)
        plugin.on_launch(logger)
        await root_command.run(args)
        return 0
    except ConnectCommandException as e:
        print(str(e), file=sys.stderr)
        return 1
    except IdbException as e:
        print(e.args[0], file=sys.stderr)
        return 1
    except Exception:
        logger.exception("Exception thrown in main")
        return 1
    finally:
        await plugin.on_close(logger)
        pending = set(asyncio.all_tasks())
        current_task = asyncio.current_task()
        if current_task is not None:
            pending.discard(current_task)
        await drain_coroutines(pending)
예제 #5
0
        # for backwards compatibility
        if args.name == "locale":
            locale_identifier = await client.get_locale()
            print(locale_identifier)
        else:
            value = await client.get_preference(name=args.name,
                                                domain=args.domain)
            print(value)


class ListLocaleCommand(ClientCommand):
    @property
    def description(self) -> str:
        return "Lists available locale identifiers"

    @property
    def name(self) -> str:
        return "locale"

    async def run_with_client(self, args: Namespace, client: Client) -> None:
        locale_identifiers = await client.list_locale_identifiers()
        for locale_identifier in locale_identifiers:
            print(locale_identifier)


ListCommand = CommandGroup(
    name="list",
    description="Lists values from the target",
    commands=[ListLocaleCommand()],
)
예제 #6
0
_DISABLE = "disable"


class HardwareKeyboardCommand(ClientCommand):
    @property
    def description(self) -> str:
        return "Set the hardware keyboard"

    @property
    def name(self) -> str:
        return "hardware-keyboard"

    def add_parser_arguments(self, parser: ArgumentParser) -> None:
        parser.add_argument(
            "setting",
            help="Whether to enable or disable the hardware keyboard",
            choices=[_ENABLE, _DISABLE],
        )
        super().add_parser_arguments(parser)

    async def run_with_client(self, args: Namespace, client: Client) -> None:
        await client.set_hardware_keyboard(
            enabled=(True if args.setting == _ENABLE else False))


SetCommand = CommandGroup(
    name="set",
    description="Sets a preference on the target",
    commands=[HardwareKeyboardCommand()],
)
예제 #7
0
파일: main.py 프로젝트: zeng4250538/idb
async def gen_main(cmd_input: Optional[List[str]] = None, ) -> int:
    # Setup parser
    parser = argparse.ArgumentParser(
        description=
        "idb: a versatile tool to communicate with iOS Simulators and Devices",
        epilog="See Also: https://www.fbidb.io/docs/guided-tour",
        formatter_class=argparse.RawTextHelpFormatter,
    )
    commands: List[Command] = [
        DescribeCommand(),
        AppInstallCommand(),
        AppUninstallCommand(),
        ListAppsCommand(),
        LaunchCommand(),
        AppTerminateCommand(),
        CommandGroup(
            name="xctest",
            description="Operations with xctest on target",
            commands=[
                XctestInstallCommand(),
                XctestsListBundlesCommand(),
                XctestListTestsCommand(),
                XctestRunCommand(),
            ],
        ),
        CommandGroup(
            name="file",
            description="File operations on target",
            commands=[
                FSMoveCommand(),
                FSPullCommand(),
                FSPushCommand(),
                FSMkdirCommand(),
                FSRemoveCommand(),
                FSListCommand(),
            ],
        ),
        CommandGroup(
            name="contacts",
            description="Contacts database operations on target",
            commands=[ContactsUpdateCommand()],
        ),
        LogCommand(),
        CommandGroup(
            name="record",
            description="Record what the screen is doing",
            commands=[RecordVideoCommand()],
        ),
        RecordVideoCommand(),
        DeprecatedPushCommand(),
        DeprecatedPullCommand(),
        OpenUrlCommand(),
        ClearKeychainCommand(),
        SetLocationCommand(),
        ApproveCommand(),
        ConnectCommand(),
        DisconnectCommand(),
        ListTargetsCommand(),
        DaemonCommand(),
        ScreenshotCommand(),
        CommandGroup(
            name="ui",
            description="UI interactions on target",
            commands=[
                AccessibilityInfoAllCommand(),
                AccessibilityInfoAtPointCommand(),
                TapCommand(),
                ButtonCommand(),
                TextCommand(),
                KeyCommand(),
                KeySequenceCommand(),
                SwipeCommand(),
            ],
        ),
        CommandGroup(
            name="crash",
            description="Operations on crashes",
            commands=[
                CrashListCommand(),
                CrashShowCommand(),
                CrashDeleteCommand()
            ],
        ),
        InstrumentsCommand(),
        KillCommand(),
        AddMediaCommand(),
        FocusCommand(),
        BootCommand(),
        CommandGroup(
            name="debugserver",
            description="debugserver interactions",
            commands=[
                DebugServerStartCommand(),
                DebugServerStopCommand(),
                DebugServerStatusCommand(),
            ],
        ),
        CommandGroup(name="dsym",
                     description="dsym commands",
                     commands=[DsymInstallCommand()]),
        CommandGroup(name="dylib",
                     description="dylib commands",
                     commands=[DylibInstallCommand()]),
        CommandGroup(
            name="framework",
            description="framework commands",
            commands=[FrameworkInstallCommand()],
        ),
        CommandGroup(
            name="companion",
            description="commands related to the companion",
            commands=[CompanionLogCommand()],
        ),
    ]
    commands.extend(plugin.get_commands())
    sorted_commands = sorted(commands, key=lambda command: command.name)
    root_command = CommandGroup("root_command", "", sorted_commands)
    root_command.add_parser_arguments(parser)

    # Parse input and run
    cmd_input = cmd_input or sys.argv[1:]

    try:
        args = parser.parse_args(cmd_input)
        plugin.on_launch(logger)
        await root_command.run(args)
        return 0
    except ConnectCommandException as e:
        print(str(e))
        return 1
    except IdbException as e:
        print(e.args[0])
        return 1
    except Exception:
        logger.exception("Exception thrown in main")
        return 1
    finally:
        await plugin.on_close(logger)
        pending = set(asyncio.Task.all_tasks())
        pending.discard(asyncio.Task.current_task())
        await drain_coroutines(pending)