Exemplo n.º 1
0
        static void ProcessRegex(string[] args)
        {
            var sr  = new SimpleRegex(args[0]);
            var cur = sr.Diagram.start_node;

            Console.Instance.WriteLine(sr.PrintDiagram());

            for (int i = 0; i < args[1].Length; i++)
            {
                var ch = args[1][i];
                if (cur.transition.Any(x => x.Item1 == ch))
                {
                    cur = cur.transition.Where(x => x.Item1 == ch).ElementAt(0).Item2;
                }
                else
                {
                    Console.Instance.WriteLine("Error! A token that can not be derived. Char='" + ch + "', POS=" + i);
                    return;
                }
            }

            if (cur.is_acceptable)
            {
                Console.Instance.WriteLine("Matching pattern!");
            }
            else
            {
                Console.Instance.WriteLine("Partial matching pattern! End=" + cur.index);
            }
        }
        // MetaAspect Eval
        /// Some definitions may have been added from outside (typically for embedded advice)
        /// Just add the new definitions the expressions point to
        private void Eval(AdviceSpec spec, string XPathBase, string XPathConstraint)
        {
            // Evaluate the XPath expressions on Cecil object model
            if (spec.targetXPath != null)
            {
                spec.TargetNavigators.AddRange(Cil.TargetNavigator.SelectList(spec.targetXPath + XPathConstraint));
            }
            else if (spec.targetRegExp != null)
            {
                foreach (Navigator nav in Cil.TargetNavigator.SelectList(XPathBase + XPathConstraint))
                {
                    if (SimpleRegex.IsPreciseMatch(nav, spec.targetRegExp))
                    {
                        spec.TargetNavigators.Add(nav);
                    }
                }
            }

            if (spec.aspectXPath != null)
            {
                spec.AspectNavigators.AddRange(Cil.AspectsNavigator.SelectList(spec.aspectXPath));
            }
            else if (spec.aspectRegExp != null)
            {
                foreach (Navigator nav in Cil.AspectsNavigator.SelectList(Cil.AllDeclarations))
                {
                    if (SimpleRegex.IsPreciseMatch(nav, spec.aspectRegExp))
                    {
                        spec.AspectNavigators.Add(nav);
                    }
                }
            }
        }
        private static void TestSimpleRegex()
        {
            string txt = "some some .text";

            AssertTrue(SimpleRegex.IsPreciseMatch(txt, "so*xt"));
            AssertFalse(SimpleRegex.IsPreciseMatch(txt, "so*.ext"));
            AssertFalse(SimpleRegex.IsPreciseMatch(txt, "{some }2.text"));
        }
Exemplo n.º 4
0
        private void bREA_Click(object sender, EventArgs e)
        {
            var sr = new SimpleRegex();

            sr.MakeNFA(tbRE.Text);
            pictureBox1.Image = Graph.ToImage(SimpleRegex.PrintGraph(sr.Diagram));
            sr.OptimizeNFA();
            pictureBox2.Image = Graph.ToImage(SimpleRegex.PrintGraph(sr.Diagram));
            sr.NFAtoDFA();
            pictureBox3.Image = Graph.ToImage(SimpleRegex.PrintGraph(sr.Diagram));
            sr.MinimizeDFA();
            pictureBox4.Image = Graph.ToImage(SimpleRegex.PrintGraph(sr.Diagram));
        }
        public static MethodDefinition ConcreteMethodMatching(Navigator nav, string regex, AdviceSpec spec)
        {
            MethodDefinition result = Method(nav, spec);

            if (!SimpleRegex.IsMatch(result, regex))
            {
                string errorMsg = string.Format
                                      ("Expected to match signature {0}, but got {1}",
                                      SimpleRegex.EscapePseudoRegex(regex), result);
                throw new AdviceException(errorMsg, spec);
            }
            return(result);
        }
Exemplo n.º 6
0
        public object Invoke(XsltContext xsltContext, object[] args, XPathNavigator docContext)
        {
            bool result = false;

            try {
                if (args.Length == 2)
                {
                    XPathNodeIterator it = (XPathNodeIterator)args[0];
                    if (it.MoveNext())
                    {
                        string pseudoRegexp = (string)args[1];
                        result = SimpleRegex.IsMatch(it.Current, pseudoRegexp);
                    }
                }
                else
                {
                    string pseudoRegexp = (string)args[0];
                    result = SimpleRegex.IsMatch(docContext, pseudoRegexp);
                }
            } catch (Exception e) {
                Console.WriteLine("Regular Expression function failed : \n" + e);
            }
            return(result);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the proxy URIs.
        /// </summary>
        public MultiProxy GetMultiProxy(Uri uri)
        {
            // We need WinHTTP to detect and/or process a PAC (JavaScript) file. This maps to
            // "Automatically detect settings" and/or "Use automatic configuration script" from IE
            // settings. But, calling into WinHTTP can be slow especially when it has to call into
            // the out-of-process service to discover, load, and run the PAC file. So, we skip
            // calling into WinHTTP if there was a recent failure to detect a PAC file on the network.
            // This is a common error. The default IE settings on a Windows machine consist of the
            // single checkbox for "Automatically detect settings" turned on and most networks
            // won't actually discover a PAC file on the network since WPAD protocol isn't configured.
            if (_proxyHelper.AutoSettingsUsed && !_proxyHelper.RecentAutoDetectionFailure)
            {
                Interop.WinHttp.WINHTTP_PROXY_INFO proxyInfo = default;
                try
                {
                    if (_proxyHelper.GetProxyForUrl(_sessionHandle, uri, out proxyInfo))
                    {
                        // If WinHTTP just specified a Proxy with no ProxyBypass list, then
                        // we can return the Proxy uri directly.
                        if (proxyInfo.ProxyBypass == IntPtr.Zero)
                        {
                            if (proxyInfo.Proxy != IntPtr.Zero)
                            {
                                string proxyStr = Marshal.PtrToStringUni(proxyInfo.Proxy) !;

                                return(MultiProxy.CreateLazy(_failedProxies, proxyStr, IsSecureUri(uri)));
                            }
                            else
                            {
                                return(MultiProxy.Empty);
                            }
                        }

                        // A bypass list was also specified. This means that WinHTTP has fallen back to
                        // using the manual IE settings specified and there is a ProxyBypass list also.
                        // Since we're not really using the full WinHTTP stack, we need to use HttpSystemProxy
                        // to do the computation of the final proxy uri merging the information from the Proxy
                        // and ProxyBypass strings.
                    }
                    else
                    {
                        return(MultiProxy.Empty);
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(proxyInfo.Proxy);
                    Marshal.FreeHGlobal(proxyInfo.ProxyBypass);
                }
            }

            // Fallback to manual settings if present.
            if (_proxyHelper.ManualSettingsUsed)
            {
                if (_bypassLocal)
                {
                    IPAddress?address;

                    if (uri.IsLoopback)
                    {
                        // This is optimization for loopback addresses.
                        // Unfortunately this does not work for all local addresses.
                        return(MultiProxy.Empty);
                    }

                    // Pre-Check if host may be IP address to avoid parsing.
                    if (uri.HostNameType == UriHostNameType.IPv6 || uri.HostNameType == UriHostNameType.IPv4)
                    {
                        // RFC1123 allows labels to start with number.
                        // Leading number may or may not be IP address.
                        // IPv6 [::1] notation. '[' is not valid character in names.
                        if (IPAddress.TryParse(uri.IdnHost, out address))
                        {
                            // Host is valid IP address.
                            // Check if it belongs to local system.
                            foreach (IPAddress a in _localIp !)
                            {
                                if (a.Equals(address))
                                {
                                    return(MultiProxy.Empty);
                                }
                            }
                        }
                    }
                    if (uri.HostNameType != UriHostNameType.IPv6 && !uri.IdnHost.Contains('.'))
                    {
                        // Not address and does not have a dot.
                        // Hosts without FQDN are considered local.
                        return(MultiProxy.Empty);
                    }
                }

                // Check if we have other rules for bypass.
                if (_bypass != null)
                {
                    foreach (string entry in _bypass)
                    {
                        // IdnHost does not have [].
                        if (SimpleRegex.IsMatchWithStarWildcard(uri.IdnHost, entry))
                        {
                            return(MultiProxy.Empty);
                        }
                    }
                }

                // We did not find match on bypass list.
                return(IsSecureUri(uri) ? _secureProxy : _insecureProxy);
            }

            return(MultiProxy.Empty);
        }
Exemplo n.º 8
0
 public void InputMatchesStarWildcardPattern(string input, string pattern, bool expected)
 {
     Assert.Equal(expected, SimpleRegex.IsMatchWithStarWildcard(input, pattern));
 }