Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小体积规则无法正确识别 #76

Open
YujiaCheng1996 opened this issue Oct 17, 2024 · 1 comment
Open

小体积规则无法正确识别 #76

YujiaCheng1996 opened this issue Oct 17, 2024 · 1 comment

Comments

@YujiaCheng1996
Copy link

YujiaCheng1996 commented Oct 17, 2024

    def __isConfigFile(self, filename):
        filestats = os.stat(filename)
        if filestats.st_size < 1024 * 4:
            return False
        return True

这块判断是不是粗暴了一些,一些小的规则如https://osint.digitalside.it/Threat-Intel/lists/latestdomains.piHole.txt 无法正确地被识别。设想是不是可以通过响应内容是不是html/json或者直接根据响应头和响应码来精确判断一下。

以下是某AI生成的代码,通过规则的特征判断的,考虑到小体积订阅规则数量不多,性能影响应该不大:

    def __isConfigFile(self, filename):
        file_stats = os.stat(filename)
        if file_stats.st_size >= 4 * 1024:
            return True

        with open(filename, 'r', encoding='utf-8', errors='ignore') as f:
            non_comment_lines = 0
            for line in f:
                line = line.strip()
                if not line or line.startswith('!') or line.startswith('#'):
                    continue

                non_comment_lines += 1
                if non_comment_lines > 10:
                    return False

                if (line.startswith('||') or line.startswith('@@') or '##' in line or
                    re.match(r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s+\S+', line)):
                    return True

        return False
217heidai added a commit that referenced this issue Oct 17, 2024
@217heidai
Copy link
Owner

嗯,去掉原来的isConfigFile判断,加上Content-Type是否为text/plain,响应码+类型判断足够了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants