Example #1
0
        private static void DumpNode(StringBuilder builder, String prefix, AssistStructure.ViewNode node, int childNumber)
        {
            builder.Append(prefix)
            .Append("child #").Append(Integer.ToString(childNumber)).Append("\n");

            builder.Append(prefix)
            .Append("autoFillId: ").Append(node.AutofillId.ToString())
            .Append("\tidEntry: ").Append(node.IdEntry)
            .Append("\tid: ").Append(node.Id.ToString())
            .Append("\tclassName: ").Append(node.ClassName)
            .Append('\n');

            builder.Append(prefix)
            .Append("focused: ").Append(node.IsFocused.ToString())
            .Append("\tvisibility").Append(node.Visibility.ToString())
            .Append("\tchecked: ").Append(node.IsChecked.ToString())
            .Append("\twebDomain: ").Append(node.WebDomain)
            .Append("\thint: ").Append(node.Hint)
            .Append('\n');

            ViewStructure.HtmlInfo htmlInfo = node.HtmlInfo;

            if (htmlInfo != null)
            {
                builder.Append(prefix)
                .Append("HTML TAG: ").Append(htmlInfo.Tag)
                .Append(" attrs: ").Append(htmlInfo.Attributes.ToString())
                .Append('\n');
            }

            var afHints = string.Join(string.Empty, node.GetAutofillHints()).ToCharArray();
            var options = string.Join(string.Empty, node.GetAutofillOptions()).ToCharArray();

            builder.Append(prefix).Append("afType: ").Append(GetTypeAsString((int)node.AutofillType))
            .Append("\tafValue:")
            .Append(getAutofillValueAndTypeAsString(node.AutofillValue))
            .Append("\tafOptions:").Append(options == null ? "N/A" : Arrays.ToString(options))
            .Append("\tafHints: ").Append(afHints == null ? "N/A" : Arrays.ToString(afHints))
            .Append("\tinputType:").Append(node.InputType.ToString())
            .Append('\n');

            int numberChildren = node.ChildCount;

            builder.Append(prefix).Append("# children: ").Append(numberChildren.ToString())
            .Append("\ttext: ").Append(node.Text)
            .Append('\n');

            String prefix2 = prefix + "  ";

            for (int i = 0; i < numberChildren; i++)
            {
                DumpNode(builder, prefix2, node.GetChildAt(i), i);
            }
            Logv(builder.ToString());
        }
        private void TraverseRoot(AssistStructure.ViewNode viewNode, INodeProcessor processor)
        {
            processor.ProcessNode(viewNode);
            int childrenSize = viewNode.ChildCount;

            if (childrenSize > 0)
            {
                for (int i = 0; i < childrenSize; i++)
                {
                    TraverseRoot(viewNode.GetChildAt(i), processor);
                }
            }
        }
Example #3
0
        /**
         * Gets a node if it matches the filter criteria for the given id.
         */
        public static AssistStructure.ViewNode FindNodeByFilter([NonNull] AssistStructure.ViewNode node, [NonNull] object id, [NonNull] NodeFilter filter)
        {
            if (filter.matches(node, id))
            {
                return(node);
            }
            int childrenSize = node.ChildCount;

            if (childrenSize > 0)
            {
                for (int i = 0; i < childrenSize; i++)
                {
                    AssistStructure.ViewNode found = FindNodeByFilter(node.GetChildAt(i), id, filter);
                    if (found != null)
                    {
                        return(found);
                    }
                }
            }
            return(null);
        }
        void ParseLocked(bool forFill, bool isManualRequest, AssistStructure.ViewNode viewNode, ref string validWebdomain)
        {
            String webDomain = viewNode.WebDomain;

            if (webDomain != null)
            {
                Log.Debug(CommonUtil.Tag, $"child web domain: {webDomain}");
                if (!string.IsNullOrEmpty(validWebdomain))
                {
                    if (webDomain == validWebdomain)
                    {
                        throw new Java.Lang.SecurityException($"Found multiple web domains: valid= {validWebdomain}, child={webDomain}");
                    }
                }
                else
                {
                    validWebdomain = webDomain;
                }
            }

            string[] viewHints = viewNode.GetAutofillHints();
            if (viewHints != null && viewHints.Length == 1 && viewHints.First() == "off" && viewNode.IsFocused &&
                isManualRequest)
            {
                viewHints[0] = "on";
            }
            CommonUtil.logd("viewHints=" + viewHints);
            CommonUtil.logd("class=" + viewNode.ClassName);
            CommonUtil.logd("tag=" + (viewNode?.HtmlInfo?.Tag ?? "(null)"));
            if (viewNode?.HtmlInfo?.Tag == "input")
            {
                foreach (var p in viewNode.HtmlInfo.Attributes)
                {
                    CommonUtil.logd("attr=" + p.First + "/" + p.Second);
                }
            }
            if (viewHints != null && viewHints.Length > 0 && viewHints.First() != "on" /*if hint is "on", treat as if there is no hint*/)
            {
                if (forFill)
                {
                    AutofillFields.Add(new AutofillFieldMetadata(viewNode));
                }
                else
                {
                    //TODO implement save
                    throw new NotImplementedException("TODO: Port and use AutoFill hints");
                    //ClientFormData.Add(new FilledAutofillField(viewNode));
                }
            }
            else
            {
                if (viewNode.ClassName == "android.widget.EditText" || viewNode?.HtmlInfo?.Tag == "input")
                {
                    _editTextsWithoutHint.Add(viewNode);
                }
            }
            var childrenSize = viewNode.ChildCount;

            if (childrenSize > 0)
            {
                for (int i = 0; i < childrenSize; i++)
                {
                    ParseLocked(forFill, isManualRequest, viewNode.GetChildAt(i), ref validWebdomain);
                }
            }
        }
Example #5
0
        void ParseLocked(bool forFill, bool isManualRequest, AssistStructure.ViewNode viewNode, ref string validWebdomain)
        {
            String webDomain = viewNode.WebDomain;

            if ((PackageId == null) && (!string.IsNullOrWhiteSpace(viewNode.IdPackage)) &&
                (viewNode.IdPackage != "android"))
            {
                PackageId = viewNode.IdPackage;
            }

            DomainName outDomain;

            if (DomainName.TryParse(webDomain, domainSuffixParserCache, out outDomain))
            {
                webDomain = outDomain.RegisterableDomainName;
            }

            if (webDomain != null)
            {
                if (!string.IsNullOrEmpty(validWebdomain))
                {
                    if (webDomain != validWebdomain)
                    {
                        throw new Java.Lang.SecurityException($"Found multiple web domains: valid= {validWebdomain}, child={webDomain}");
                    }
                }
                else
                {
                    validWebdomain = webDomain;
                }
            }

            string[] viewHints = viewNode.GetAutofillHints();
            if (viewHints != null && viewHints.Length == 1 && viewHints.First() == "off" && viewNode.IsFocused &&
                isManualRequest)
            {
                viewHints[0] = "on";
            }
            if (viewHints != null && viewHints.Any())
            {
                CommonUtil.logd("viewHints=" + viewHints);
                CommonUtil.logd("class=" + viewNode.ClassName);
                CommonUtil.logd("tag=" + (viewNode?.HtmlInfo?.Tag ?? "(null)"));
            }

            if (viewNode?.HtmlInfo?.Tag == "input")
            {
                foreach (var p in viewNode.HtmlInfo.Attributes)
                {
                    CommonUtil.logd("attr=" + p.First + "/" + p.Second);
                }
            }
            if (viewHints != null && viewHints.Length > 0 && viewHints.First() != "on" /*if hint is "on", treat as if there is no hint*/)
            {
                if (forFill)
                {
                    AutofillFields.Add(new AutofillFieldMetadata(viewNode));
                }
                else
                {
                    FilledAutofillField filledAutofillField = new FilledAutofillField(viewNode);
                    ClientFormData.Add(filledAutofillField);
                }
            }
            else
            {
                if (viewNode.ClassName == "android.widget.EditText" || viewNode?.HtmlInfo?.Tag == "input")
                {
                    _editTextsWithoutHint.Add(viewNode);
                }
            }
            var childrenSize = viewNode.ChildCount;

            if (childrenSize > 0)
            {
                for (int i = 0; i < childrenSize; i++)
                {
                    ParseLocked(forFill, isManualRequest, viewNode.GetChildAt(i), ref validWebdomain);
                }
            }
        }
        private void ParseLocked(bool forFill, AssistStructure.ViewNode viewNode, StringBuilder validWebDomain)
        {
            var webDomain = viewNode.WebDomain;

            if (webDomain != null)
            {
                if (CommonUtil.DEBUG)
                {
                    Log.Debug(CommonUtil.TAG, "child web domain: " + webDomain);
                }
                if (validWebDomain.Length() > 0)
                {
                    if (webDomain != validWebDomain.ToString())
                    {
                        throw new SecurityException("Found multiple web domains: valid= "
                                                    + validWebDomain + ", child=" + webDomain);
                    }
                }
                else
                {
                    validWebDomain.Append(webDomain);
                }
            }

            if (viewNode.GetAutofillHints() != null)
            {
                var filteredHints = AutofillHints.FilterForSupportedHints(
                    viewNode.GetAutofillHints());
                if (filteredHints != null && filteredHints.Length > 0)
                {
                    if (forFill)
                    {
                        mAutofillFields.Add(new AutofillFieldMetadata(viewNode));
                    }
                    else
                    {
                        var           filledAutofillField = new FilledAutofillField(viewNode.GetAutofillHints());
                        AutofillValue autofillValue       = viewNode.AutofillValue;
                        if (autofillValue.IsText)
                        {
                            // Using toString of AutofillValue.getTextValue in order to save it to
                            // SharedPreferences.
                            filledAutofillField.SetTextValue(autofillValue.TextValue);
                        }
                        else if (autofillValue.IsDate)
                        {
                            filledAutofillField.SetDateValue(autofillValue.DateValue);
                        }
                        else if (autofillValue.IsList)
                        {
                            filledAutofillField.SetListValue(viewNode.GetAutofillOptions(),
                                                             autofillValue.ListValue);
                        }

                        mFilledAutofillFieldCollection.Add(filledAutofillField);
                    }
                }
            }

            int childrenSize = viewNode.ChildCount;

            if (childrenSize > 0)
            {
                for (int i = 0; i < childrenSize; i++)
                {
                    ParseLocked(forFill, viewNode.GetChildAt(i), validWebDomain);
                }
            }
        }