From c349c8aa3f5dabe68dd85308b0e3a7ba160dbe52 Mon Sep 17 00:00:00 2001 From: M09Ic Date: Fri, 9 Dec 2022 19:30:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=A3=85rule-base=E7=9A=84filter=20ru?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 ++-- internal/option.go | 6 +++++- internal/pool.go | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index e8795d8..27e1344 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/chainreactors/ipcs v0.0.13 github.com/chainreactors/logs v0.6.2 github.com/chainreactors/parsers v0.2.7 - github.com/chainreactors/words v0.3.0 + github.com/chainreactors/words v0.3.1 ) require ( diff --git a/go.sum b/go.sum index 3de06ef..fa24950 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,8 @@ github.com/chainreactors/logs v0.6.2/go.mod h1:Y0EtAnoF0kiASIJUnXN0pcOt420iRpHOA github.com/chainreactors/parsers v0.2.6/go.mod h1:Z9weht+lnFCk7UcwqFu6lXpS7u5vttiy0AJYOAyCCLA= github.com/chainreactors/parsers v0.2.7 h1:3iEuluL7gSDrElZWyf1KEiTgddgcoZC0IaIHb9KA3pk= github.com/chainreactors/parsers v0.2.7/go.mod h1:Z9weht+lnFCk7UcwqFu6lXpS7u5vttiy0AJYOAyCCLA= -github.com/chainreactors/words v0.3.0 h1:6wC6lARE2MuD0UihW4RTV76cbiAoGVJM3k+HZg+R+hc= -github.com/chainreactors/words v0.3.0/go.mod h1:jRcFgafTKqdkd1+StzPCTJG1ESrZHluXEO2eERdHBMQ= +github.com/chainreactors/words v0.3.1 h1:Onx+FKOp0cZHCNQj2hB2tHOclbWCvQ8aOcreX8e5SSQ= +github.com/chainreactors/words v0.3.1/go.mod h1:jRcFgafTKqdkd1+StzPCTJG1ESrZHluXEO2eERdHBMQ= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/internal/option.go b/internal/option.go index 2527b0f..1140052 100644 --- a/internal/option.go +++ b/internal/option.go @@ -34,6 +34,7 @@ type InputOptions struct { Limit int `long:"limit" description:"Int, wordlist limit, start with offset. e.g.: --offset 1000 --limit 100"` Dictionaries []string `short:"d" long:"dict" description:"Files, dict files, e.g.: -d 1.txt -d 2.txt"` Word string `short:"w" long:"word" description:"String, word generate dsl, e.g.: -w test{?ld#4}"` + FilterRule string `long:"rule-filter" description:"String, filter rule, e.g.: --rule-filter '>8'"` Rules []string `short:"r" long:"rules" description:"Files, rule files, e.g.: -r rule1.txt -r rule2.txt"` Extensions string `short:"e" long:"extension" description:"String, add extensions (separated by commas), e.g.: -e jsp,jspx"` ExcludeExtensions string `long:"exclude-extension" description:"String, exclude extensions (separated by commas), e.g.: --exclude-extension jsp,jspx"` @@ -238,7 +239,10 @@ func (opt *Option) PrepareRunner() (*Runner, error) { rules.Write(content) rules.WriteString("\n") } - r.Rules = rule.Compile(rules.String()) + r.Rules = rule.Compile(rules.String(), opt.FilterRule) + } else if opt.FilterRule != "" { + // if filter rule is not empty, set rules to ":", force to open filter mode + r.Rules = rule.Compile(":", opt.FilterRule) } if len(r.Rules) > 0 { diff --git a/internal/pool.go b/internal/pool.go index f3812bc..baa3460 100644 --- a/internal/pool.go +++ b/internal/pool.go @@ -229,6 +229,7 @@ type Pool struct { } func (p *Pool) Init() error { + // 分成两步是为了避免闭包的线程安全问题 p.initwg.Add(1) p.pool.Invoke(newUnit("/", InitIndexSource)) p.initwg.Wait() @@ -237,6 +238,7 @@ func (p *Pool) Init() error { } p.index.Collect() logs.Log.Important("[baseline.index] " + p.index.String()) + p.initwg.Add(1) p.pool.Invoke(newUnit(pkg.RandPath(), InitRandomSource)) p.initwg.Wait()