TG-Twilight / AWAvenue-Ads-Rule

开源社区中最优秀的广告过滤器列表之一,实现了最优秀的广告拦截、隐私保护和流量节省。支持各种常见的网络层广告拦截工具和代理工具等。 | Use Adblock syntax to fight against various advertising SDKs in Android applications from the network level , prevent them from loading.
https://AWAvenue.top
Other
1.84k stars 62 forks source link

[BUG] sing-box 规则正则解析出错 #77

Closed doveccl closed 3 weeks ago

doveccl commented 3 months ago

问题描述

sing-box 规则 domain_regex 中出现不少以 * 打头的规则导致正则解析失败

{
  // ...
  "domain_regex": [
    "*.*.shouji.sogou.com",
    // ...
  ]
}
FATAL[0000] start service: initialize rule-set[5]: initial rule-set: ad: parse rule_set.rules.[0]: domain_regex: parse expression 0: error parsing regexp: missing argument to repetition operator: `*`

复现步骤

No response

问题截图

No response

自查步骤

TG-Twilight commented 3 months ago

singbox老大难问题,不支持正则解析,这个请耐心等待我们找到别的解决思路。

TG-Twilight commented 3 months ago

初步计划是打算在规则生成阶段,直接让singbox的脚本不读取正则部分。

heinu123 commented 2 months ago

为什么不适应无正则版本呢 https://raw.githubusercontent.com/TG-Twilight/AWAvenue-Ads-Rule/main/Filters/AWAvenue-Ads-Rule-Singbox.json

doveccl commented 2 months ago

为什么不适应无正则版本呢 https://raw.githubusercontent.com/TG-Twilight/AWAvenue-Ads-Rule/main/Filters/AWAvenue-Ads-Rule-Singbox.json

少了部分规则

{
      "domain_regex": [
        "*.*.shouji.sogou.com",
        "*.[a-zA-Z0-9.-]skwai.com",
        "*.a.market.xiaomi.com",
        "*.data.hicloud.com",
        "*.log.aliyuncs.com",
        "*.shouji.sogou.com",
        "[a-zA-Z0-9.-]*-ad-[a-zA-Z0-9.-]*.byteimg.com",
        "[a-zA-Z0-9.-]*-ad.sm.cn",
        "[a-zA-Z0-9.-]*-ad.video.yximgs.com",
        "[a-zA-Z0-9.-]*-ad.wtzw.com",
        "[a-zA-Z0-9.-]*-be-pack-sign.pglstatp-toutiao.com",
        "[a-zA-Z0-9.-]*-lm.adkwai.com",
        "[a-zA-Z0-9.-]*-normal-[a-zA-Z0-9.-]*.zijieapi.com",
        "[a-zA-Z0-9.-]*-normal.zijieapi.com",
        "cloudinject[a-zA-Z0-9.-]*-dev.*.[a-zA-Z0-9.-]*-[a-zA-Z0-9.-]*-[a-zA-Z0-9.-]*.amazonaws.com"
      ]
}

anyway 我现在没在用 sing-box 了,影响倒是不大

不过问题应该出在以 * 开头的几个规则里,也许用 .* 代替 * 能解决这个问题

doveccl commented 2 months ago

@TG-Twilight 刚才发现官方给了 adguard.txt -> srs 转换程序,是不是可以考虑直接用 https://sing-box.sagernet.org/zh/configuration/rule-set/adguard/

TG-Twilight commented 2 months ago

@doveccl 但是还是会包括正则内容

singbox不支持正则内容

doveccl commented 2 months ago

@TG-Twilight 好像也是支持的吧

{
  "inbounds": [{ "type": "mixed", "listen_port": 7890 }],
  "outbounds": [
    { "type": "direct", "tag": "direct" },
    { "type": "block", "tag": "block" }
  ],
  "route": {
    "rules": [{ "domain_regex": "[a-zA-Z0-9.-]*-ad.sm.cn", "outbound": "block" }]
  }
}

上面这个配置跑一下 ./sing-box run -c config.json & (sleep 1; all_proxy=http://localhost:7890 curl -v 1-ad.sm.cn) 日志也很清楚路由到了

INFO[0000] router: updated default interface en0, index 6
INFO[0000] inbound/mixed[0]: tcp server started at 127.0.0.1:7890
INFO[0000] sing-box started (0.00s)
* Uses proxy env variable all_proxy == 'http://localhost:7890'
* Host localhost:7890 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:7890...
* connect to ::1 port 7890 from ::1 port 50812 failed: Connection refused
*   Trying 127.0.0.1:7890...
* Connected to localhost (127.0.0.1) port 7890
> GET http://1-ad.sm.cn/ HTTP/1.1
> Host: 1-ad.sm.cn
> User-Agent: curl/8.6.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
INFO[0000] [976685108 0ms] inbound/mixed[0]: inbound connection from 127.0.0.1:50813
INFO[0000] [976685108 1ms] inbound/mixed[0]: inbound connection to 1-ad.sm.cn:80
DEBUG[0000] [976685108 1ms] router: match[0] domain_regex=[a-zA-Z0-9.-]*-ad.sm.cn => block
INFO[0000] [976685108 1ms] outbound/block[block]: blocked connection to 1-ad.sm.cn:80
< DEBUG[0000] [976685108 1ms] inbound/mixed[0]: connection closed: process connection from 127.0.0.1:50813: Get "http://1-ad.sm.cn/": io: read/write on closed pipe
HTTP/1.1 502 Bad Gateway
< Content-Length: 0
< 
* Connection #0 to host localhost left intact
ghitori commented 1 month ago

@doveccl 但是还是会包括正则内容

singbox不支持正则内容

在目前这个时间点上sing官方已经支持regex了,但使用的regex中.的含义为任意字符,*的含义为任意数量,与通配符解释略有不同 例如*.*.shouji.sogou.com的正确写法应为.*\\..*\\.shouji\\.sogou\\.com

附图:

配置: 配置 拦截*.*.shouji.sogou.com 拦截1 未误伤*.shouji.sogou.com 拦截2

TG-Twilight commented 1 month ago

好的,两位朋友们,之后我们会尝试解决这个问题,当然,你们亦可直接在我们解决之前进行Pr。🙏