Example #1
0
def _visualize(target):
    target = fb.evaluateInputExpression(target)

    if fb.evaluateBooleanExpression("(unsigned long)CFGetTypeID((CFTypeRef)" +
                                    target +
                                    ") == (unsigned long)CGImageGetTypeID()"):
        _showImage("(id)[UIImage imageWithCGImage:" + target + "]")
    else:
        if objectHelpers.isKindOfClass(target, "UIImage"):
            _showImage(target)
        elif objectHelpers.isKindOfClass(target, "UIView"):
            _showLayer("[(id)" + target + " layer]")
        elif objectHelpers.isKindOfClass(target, "CALayer"):
            _showLayer(target)
        elif (objectHelpers.isKindOfClass(target, "UIColor")
              or objectHelpers.isKindOfClass(target, "CIColor")
              or _colorIsCGColorRef(target)):
            _showColor(target)
        elif objectHelpers.isKindOfClass(target, "NSData"):
            if _dataIsImage(target):
                _showImage("(id)[UIImage imageWithData:" + target + "]")
            elif _dataIsString(target):
                print(
                    fb.describeObject("[[NSString alloc] initWithData:" +
                                      target + " encoding:4]"))
            else:
                print("Data isn't an image and isn't a string.")
        else:
            print(
                "{} isn't supported. You can visualize UIImage, CGImageRef, UIView, CALayer, NSData, UIColor, CIColor, or CGColorRef."
                .format(objectHelpers.className(target)))
    def accessibilityGrepHierarchy(self, view, needle):
        a11yLabel = accessibilityLabel(view)
        # if we don't have any accessibility string - we should have some children
        if int(a11yLabel.GetValue(), 16) == 0:
            # We call private method that gives back all visible accessibility children
            # for view iOS 10 and higher
            if fb.evaluateBooleanExpression(
                    "[UIView respondsToSelector:@selector(_accessibilityElementsAndContainersDescendingFromViews:options:sorted:)]"  # noqa B950
            ):
                accessibilityElements = fb.evaluateObjectExpression(
                    "[UIView _accessibilityElementsAndContainersDescendingFromViews:@[(id)%s] options:0 sorted:NO]"  # noqa B950
                    % view)
            else:
                accessibilityElements = fb.evaluateObjectExpression(
                    "[[[UIApplication sharedApplication] keyWindow] _accessibilityElementsInContainer:0 topLevel:%s includeKB:0]"  # noqa B950
                    % view)
            accessibilityElementsCount = fb.evaluateIntegerExpression(
                "[%s count]" % accessibilityElements)
            for index in range(0, accessibilityElementsCount):
                subview = fb.evaluateObjectExpression(
                    "[%s objectAtIndex:%i]" % (accessibilityElements, index))
                self.accessibilityGrepHierarchy(subview, needle)
        elif re.match(r".*" + needle + ".*", a11yLabel.GetObjectDescription(),
                      re.IGNORECASE):
            classDesc = objHelpers.className(view)
            print("({} {}) {}".format(classDesc, view,
                                      a11yLabel.GetObjectDescription()))

            # First element that is found is copied to clipboard
            if not self.foundElement:
                self.foundElement = True
                cmd = 'echo %s | tr -d "\n" | pbcopy' % view
                os.system(cmd)
Example #3
0
def _copy(target, preferredFilename, noOpen):
    target = '(' + target + ')'

    if objectHelpers.isKindOfClass(target, 'NSURL'):
        _copyFromURL(target, preferredFilename, noOpen)
    elif objectHelpers.isKindOfClass(target, 'NSData'):
        _copyFromData(
            target,
            time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime()) + ".data",
            preferredFilename, noOpen)
    else:
        print('{} isn\'t supported. You can copy an NSURL or NSData.'.format(
            objectHelpers.className(target)))
Example #4
0
def _copy(target, preferredFilename, noOpen):
    target = "(" + target + ")"

    if objectHelpers.isKindOfClass(target, "NSURL"):
        _copyFromURL(target, preferredFilename, noOpen)
    elif objectHelpers.isKindOfClass(target, "NSData"):
        _copyFromData(
            target,
            time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime()) + ".data",
            preferredFilename,
            noOpen,
        )
    else:
        print("{} isn't supported. You can copy an NSURL or NSData.".format(
            objectHelpers.className(target)))
def printAccessibilityIdentifiersHierarchy(view, indent=0):
    a11yIdentifier = accessibilityIdentifier(view)
    classDesc = objHelpers.className(view)
    indentString = "   | " * indent

    # if we don't have any accessibility identifier - we should have some children
    if int(a11yIdentifier.GetValue(), 16) == 0:
        print(indentString + ("{} {}".format(classDesc, view)))
        # We call private method that gives back all visible accessibility children
        # for view
        a11yElements = accessibilityElements(view)
        accessibilityElementsCount = int(
            fb.evaluateExpression("(int)[%s count]" % a11yElements))
        for index in range(0, accessibilityElementsCount):
            subview = fb.evaluateObjectExpression("[%s objectAtIndex:%i]" %
                                                  (a11yElements, index))
            printAccessibilityIdentifiersHierarchy(subview, indent + 1)
    else:
        print(indentString + ("({} {}) {}".format(
            classDesc, view, a11yIdentifier.GetObjectDescription())))