Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/xiecat/fofax into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
FanqXu committed Jan 2, 2022
2 parents f7fa7bd + d131a6a commit 2090659
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
2 changes: 2 additions & 0 deletions internal/cli/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type query struct {
type queryOfFile struct {
// 从文件中进行查询
QueryFile string `key:"-qf"`
QueryFx string `key:"-qx"`
CoinFile string `key:"-fcf"`
// 批量 URL,计算 icon hash 后进行查询
UrlIconFile string `key:"-iuf"`
Expand Down Expand Up @@ -173,6 +174,7 @@ func init() {
flags, "queryFile", "Multiple query/cert/icon",
flags.StringVarP(&args.CoinFile, "fofa-coin-file", "fcf", args.CoinFile, "Load files downloaded with fofa coins (only use -ffi -fs or not)"),
flags.StringVarP(&args.QueryFile, "query-file", "qf", args.QueryFile, "Load files, query multiple statements"),
flags.StringVarP(&args.QueryFx, "query-fx", "qx", args.QueryFx, "Find all statements from the fx rules"),
flags.StringVarP(&args.PeerCertificatesFile, "url-cert-file", "ucf", args.UrlIconFile, "Read the URL from the file, calculate the cert and then query it"),
flags.StringVarP(&args.UrlIconFile, "icon-hash-url-file", "iuf", args.UrlIconFile, "Retrieve the URL from the file, calculate the icon hash and query it"),
)
Expand Down
40 changes: 33 additions & 7 deletions internal/fx/fxquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ func (fx FoFaxQuery) Search(id, query, ruleName, ruleEnglish, Author, tag string
}
return
}
func (fx FoFaxQuery) SearchQueryExp(rawStrs string) (plugins []Plugin) {
strs := strings.Split(rawStrs, ";")

if len(strs) == 1 && len(strings.Split(strs[0], "=")) == 1 {
return fx.SearchOr(rawStrs, rawStrs, rawStrs, rawStrs, rawStrs, rawStrs)

}
id, query, ruleName, ruleEnglish, author, tag := fx.searchExp(rawStrs)
return fx.Search(id, query, ruleName, ruleEnglish, author, tag)
}

func (fx FoFaxQuery) SearchSingle(query string) (Plugin, error) {
if len(query) < 3 {
Expand All @@ -60,14 +70,9 @@ func (fx FoFaxQuery) SearchSingle(query string) (Plugin, error) {
return Plugin{}, errors.New("not found")
}

func (fx FoFaxQuery) SearchExpTab(rawStrs string) {
var id, query, ruleName, ruleEnglish, author, tag string
strs := strings.Split(rawStrs, ";")
func (fx FoFaxQuery) searchExp(rawStrs string) (id, query, ruleName, ruleEnglish, author, tag string) {

if len(strs) == 1 && len(strings.Split(strs[0], "=")) == 1 {
fx.SearchOrTable(rawStrs, rawStrs, rawStrs, rawStrs, rawStrs, rawStrs)
return
}
strs := strings.Split(rawStrs, ";")

for _, expr := range strs {
exprSplit := strings.Split(expr, "=")
Expand Down Expand Up @@ -100,9 +105,30 @@ func (fx FoFaxQuery) SearchExpTab(rawStrs string) {
}
}
printer.Debugf("id=%s,query=%s,ruleName=%s,ruleEnglish=%s,author=%s,tag=%s", id, query, ruleName, ruleEnglish, author, tag)
return
}
func (fx FoFaxQuery) SearchExpTab(rawStrs string) {
strs := strings.Split(rawStrs, ";")

if len(strs) == 1 && len(strings.Split(strs[0], "=")) == 1 {
fx.SearchOrTable(rawStrs, rawStrs, rawStrs, rawStrs, rawStrs, rawStrs)
return
}
id, query, ruleName, ruleEnglish, author, tag := fx.searchExp(rawStrs)
fx.SearchTable(id, query, ruleName, ruleEnglish, author, tag)
}

func (fx FoFaxQuery) SearchOr(id, query, ruleName, ruleEnglish, Author, tag string) (plugins []Plugin) {
for _, q := range fx.Plugins {
if StrContain(id, q.Id) || StrContain(query, q.Query) || StrContain(ruleName, q.RuleName) ||
StrContain(ruleEnglish, q.RuleEnglish) || StrContain(Author, q.Author) ||
StrEqualInList(tag, q.Tag) {
plugins = append(plugins, q)
}
}
return
}

func (fx FoFaxQuery) SearchOrTable(id, query, ruleName, ruleEnglish, Author, tag string) {
type qTable struct {
Id string `table:"Id" yaml:"Id"`
Expand Down
7 changes: 7 additions & 0 deletions internal/runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func NewRunner(options *cli.Options) (*Runner, error) {

// 多个 Query/cert/icon 搜索项 代码块
{
// 根据 fx 搜索条件,查询多个语句
if options.QueryFx != "" {
plugins := options.FxQuery.SearchQueryExp(options.QueryFx)
for _, p := range plugins {
runner.query.Push(p.FofaQuery)
}
}
// 加载文件,查询多个语句 -qf
if len(options.QueryFile) != 0 && utils.FileExist(options.QueryFile) {
input, err := os.Open(options.QueryFile)
Expand Down

0 comments on commit 2090659

Please sign in to comment.