spray/internal/types.go

79 lines
1.4 KiB
Go
Raw Normal View History

2022-09-15 19:27:07 +08:00
package internal
import (
"github.com/chainreactors/spray/pkg"
"github.com/chainreactors/words"
"github.com/chainreactors/words/rule"
)
2022-10-19 16:38:23 +08:00
const (
CheckSource = iota + 1
InitRandomSource
InitIndexSource
2022-11-29 21:55:27 +08:00
RedirectSource
2023-01-03 17:09:32 +08:00
CrawlSource
2023-01-03 17:16:55 +08:00
ActiveSource
2022-10-19 16:38:23 +08:00
WordSource
WafSource
RuleSource
BakSource
CommonFileSource
UpgradeSource
2023-05-04 12:04:59 +08:00
RetrySource
2022-10-19 16:38:23 +08:00
)
func newUnit(path string, source int) *Unit {
2022-10-19 16:38:23 +08:00
return &Unit{path: path, source: source}
}
func newUnitWithNumber(path string, source int, number int) *Unit {
return &Unit{path: path, source: source, number: number}
}
2022-10-19 16:38:23 +08:00
type Unit struct {
number int
2022-11-29 21:55:27 +08:00
path string
source int
2023-05-04 12:04:59 +08:00
retry int
2022-11-29 21:55:27 +08:00
frontUrl string
2023-01-03 17:09:32 +08:00
depth int // redirect depth
2022-10-19 16:38:23 +08:00
}
type Task struct {
baseUrl string
depth int
rule []rule.Expression
origin *Origin
}
func NewOrigin(stat *pkg.Statistor) *Origin {
return &Origin{Statistor: stat}
}
type Origin struct {
*pkg.Statistor
sum int
}
func (o *Origin) InitWorder(fns []func(string) string) (*words.Worder, error) {
var worder *words.Worder
wl, err := loadWordlist(o.Word, o.Dictionaries)
if err != nil {
return nil, err
}
worder = words.NewWorder(wl)
worder.Fns = fns
rules, err := loadRuleWithFiles(o.RuleFiles, o.RuleFilter)
if err != nil {
return nil, err
}
worder.Rules = rules
if len(rules) > 0 {
o.sum = len(rules) * len(wl)
} else {
o.sum = len(wl)
}
return worder, nil
}