Esempio n. 1
0
        private Rule ParseRule(Rule rule)
        {
            if (rule.abpfile != null || rule.abp != null || rule.abpuri != null)
            {
                try {
                    void load(Rule rule2, string abpString)
                    {
                        Stopwatch sw = Stopwatch.StartNew();

                        try {
                            abpString = abpString ?? rule2.abp;
                            if (abpString == null)
                            {
                                var realPath = Controller.ProcessFilePath(rule2.abpfile);
                                if (!File.Exists(realPath))
                                {
                                    Logger.warning($"abp file '{realPath}' does not exist.");
                                    rule._abp_current_filter = null;
                                    return;
                                }
                                abpString = File.ReadAllText(realPath, Encoding.UTF8);
                            }
                            if (rule2.base64)
                            {
                                abpString = Encoding.UTF8.GetString(Convert.FromBase64String(abpString));
                            }
                            var isreloading  = rule._abp_current_filter != null;
                            var abpProcessor = new AbpProcessor();
                            abpProcessor.Parse(abpString);
                            rule._abp_current_filter = abpProcessor.Check;
                            Logg?.info($"{(isreloading ? "re" : null)}loaded abp filter" +
                                       $" {(rule2.abpfile == null ? "(inline/network)" : rule2.abpfile.Quoted())}" +
                                       $" {abpProcessor.RulesCount} rules in {sw.ElapsedMilliseconds} ms");
                        } catch (Exception e) {
                            Logger.exception(e, Logging.Level.Error, "loading abp filter");
                        }
                    }

                    if (rule.abpfile != null || rule.abp != null)
                    {
                        load(rule, null);
                    }
                    if (rule.abpuri != null)
                    {
                        UpdateAbpFile(rule, load);
                    }
                } catch (Exception e) {
                    Logger.exception(e);
                }
            }
            return(rule);
        }
Esempio n. 2
0
 public bool Contains(char ch, int offset)
 => AbpProcessor.Contains(str, new SubRange(Offset + offset, Length - offset), ch);