Example #1
0
def _recursiveViewControllerDescriptionWithPrefixAndChildPrefix(
        vc, string, prefix, childPrefix):
    isMac = runtimeHelpers.isMacintoshArch()

    s = "%s%s%s\n" % (
        prefix,
        "" if prefix == "" else " ",
        _viewControllerDescription(vc),
    )

    nextPrefix = childPrefix + "   |"

    numChildViewControllers = fb.evaluateIntegerExpression(
        "(int)[(id)[%s childViewControllers] count]" % (vc))

    for i in range(0, numChildViewControllers):
        viewController = fb.evaluateExpression(
            "(id)[(id)[%s childViewControllers] objectAtIndex:%d]" % (vc, i))
        s += _recursiveViewControllerDescriptionWithPrefixAndChildPrefix(
            viewController, string, nextPrefix, nextPrefix)

    if not isMac:
        isModal = fb.evaluateBooleanExpression(
            "%s != nil && ((id)[(id)[(id)%s presentedViewController] presentingViewController]) == %s"  # noqa B950
            % (vc, vc, vc))

        if isModal:
            modalVC = fb.evaluateObjectExpression(
                "(id)[(id)%s presentedViewController]" % (vc))
            s += _recursiveViewControllerDescriptionWithPrefixAndChildPrefix(
                modalVC, string, childPrefix + "  *M", nextPrefix)
            s += "\n// '*M' means the view controller is presented modally."

    return string + s
Example #2
0
    def run(self, arguments, options):
        maxDepth = int(options.depth)
        window = int(options.window)
        isMac = runtimeHelpers.isMacintoshArch()

        if window > 0:
            if isMac:
                arguments[0] = (
                    "(id)[[[[NSApplication sharedApplication] windows] objectAtIndex:"
                    + str(window)
                    + "] contentView]"
                )
            else:
                arguments[0] = (
                    "(id)[[[UIApplication sharedApplication] windows] objectAtIndex:"
                    + str(window)
                    + "]"
                )
        elif arguments[0] == "__keyWindow_dynamic__":
            if isMac:
                arguments[
                    0
                ] = "(id)[[[[NSApplication sharedApplication] windows] objectAtIndex:0] contentView]"
            else:
                arguments[0] = "(id)[[UIApplication sharedApplication] keyWindow]"

        if options.upwards:
            view = arguments[0]
            description = viewHelpers.upwardsRecursiveDescription(view, maxDepth)
            if description:
                print(description)
            else:
                print(
                    "Failed to walk view hierarchy. Make sure you pass a view, not any other kind of object or expression."
                )
        else:
            printingMethod = "recursiveDescription"
            if isMac:
                printingMethod = "_subtreeDescription"

            description = fb.evaluateExpressionValue(
                "(id)[" + arguments[0] + " " + printingMethod + "]"
            ).GetObjectDescription()
            if maxDepth > 0:
                separator = re.escape("   | ")
                prefixToRemove = separator * maxDepth + " "
                description += "\n"
                description = re.sub(r"%s.*\n" % (prefixToRemove), r"", description)

            if options.short:
                toRemove = ":.*(?:\n|$)"
                description = re.sub(toRemove, r">\n", description)
            elif options.medium:
                toRemove = ";.*(?:\n|$)"
                description = re.sub(toRemove, r">\n", description)

            print(description)
Example #3
0
    def run(self, arguments, options):
        startResponder = fb.evaluateInputExpression(arguments[0])

        isMac = runtimeHelpers.isMacintoshArch()
        responderClass = "UIResponder"
        if isMac:
            responderClass = "NSResponder"

        if not fb.evaluateBooleanExpression("(BOOL)[(id)" + startResponder +
                                            " isKindOfClass:[" +
                                            responderClass + " class]]"):
            print("Whoa, " + startResponder + " is not a " + responderClass +
                  ". =(")
            return

        _printIterative(startResponder, _responderChain)
Example #4
0
    def run(self, arguments, options):
        isMac = runtimeHelpers.isMacintoshArch()

        if arguments[0] == "__keyWindow_rootVC_dynamic__":
            if fb.evaluateBooleanExpression(
                    "[UIViewController respondsToSelector:@selector(_printHierarchy)]"
            ):
                print(fb.describeObject("[UIViewController _printHierarchy]"))
                return

            arguments[
                0] = "(id)[(id)[[UIApplication sharedApplication] keyWindow] rootViewController]"  # noqa B950
            if isMac:
                arguments[
                    0] = "(id)[[[[NSApplication sharedApplication] windows] objectAtIndex:0] contentViewController]"  # noqa B950

        print(vcHelpers.viewControllerRecursiveDescription(arguments[0]))
Example #5
0
    def inputCallback(self, input):
        oldView = self.currentView

        if input == "q":
            cmd = 'echo %s | tr -d "\n" | pbcopy' % oldView
            os.system(cmd)

            print(
                "\nI hope " + oldView +
                " was what you were looking for. I put it on your clipboard.")
            viewHelpers.unmaskView(oldView)
            self.keepRunning = False

        elif input == "w":
            v = superviewOfView(self.currentView)
            if not v:
                print("There is no superview. Where are you trying to go?!")
            self.setCurrentView(v, oldView)
        elif input == "s":
            v = firstSubviewOfView(self.currentView)
            if not v:
                print("\nThe view has no subviews.\n")
            self.setCurrentView(v, oldView)
        elif input == "d":
            v = nthSiblingOfView(self.currentView, -1)
            if v == oldView:
                print("\nThere are no sibling views to this view.\n")
            self.setCurrentView(v, oldView)
        elif input == "a":
            v = nthSiblingOfView(self.currentView, 1)
            if v == oldView:
                print("\nThere are no sibling views to this view.\n")
            self.setCurrentView(v, oldView)
        elif input == "p":
            recursionName = "recursiveDescription"
            isMac = runtimeHelpers.isMacintoshArch()

            if isMac:
                recursionName = "_subtreeDescription"

            print(
                fb.describeObject("[(id){} {}]".format(oldView,
                                                       recursionName)))
        else:
            print("\nI really have no idea what you meant by '" + input +
                  "'... =\\\n")
Example #6
0
    def run(self, args, options):
        def setBorder(layer, width, color, colorClass):
            fb.evaluateEffect("[%s setBorderWidth:(CGFloat)%s]" % (layer, width))
            fb.evaluateEffect(
                "[%s setBorderColor:(CGColorRef)[(id)[%s %sColor] CGColor]]"
                % (layer, colorClass, color)
            )

        obj = fb.evaluateInputExpression(args[0])
        depth = int(options.depth)
        isMac = runtimeHelpers.isMacintoshArch()
        color = options.color
        assert color in self.colors, "Color must be one of the following: {}".format(
            " ".join(self.colors)
        )
        colorClassName = "UIColor"
        if isMac:
            colorClassName = "NSColor"

        if viewHelpers.isView(obj):
            prevLevel = 0
            for view, level in viewHelpers.subviewsOfView(obj):
                if level > depth:
                    break
                if prevLevel != level:
                    color = self.nextColorAfterColor(color)
                    prevLevel = level
                layer = viewHelpers.convertToLayer(view)
                setBorder(layer, options.width, color, colorClassName)
        else:
            # `obj` is not a view, make sure recursive bordering is not requested
            assert (
                depth <= 0
            ), "Recursive bordering is only supported for UIViews or NSViews"
            layer = viewHelpers.convertToLayer(obj)
            setBorder(layer, options.width, color, colorClassName)

        lldb.debugger.HandleCommand("caflush")
def isNSView(obj):
    return runtimeHelpers.isMacintoshArch() and fb.evaluateBooleanExpression(
        "[(id)%s isKindOfClass:(Class)[NSView class]]" % obj)