diff --git a/internal/option.go b/internal/option.go index 0539689..d10c091 100644 --- a/internal/option.go +++ b/internal/option.go @@ -505,7 +505,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) { logs.Log.Importantf("Loaded %d dictionaries and %d decorators", len(opt.Dictionaries), len(r.Fns)) if opt.Match != "" { - exp, err := expr.Compile(opt.Match) + exp, err := expr.Compile(opt.Match, expr.Patch(&bytesPatcher{})) if err != nil { return nil, err } @@ -513,7 +513,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) { } if opt.Filter != "" { - exp, err := expr.Compile(opt.Filter) + exp, err := expr.Compile(opt.Filter, expr.Patch(&bytesPatcher{})) if err != nil { return nil, err } @@ -535,7 +535,7 @@ func (opt *Option) PrepareRunner() (*Runner, error) { } if express != "" { - exp, err := expr.Compile(express) + exp, err := expr.Compile(express, expr.Patch(&bytesPatcher{})) if err != nil { return nil, err } diff --git a/internal/utils.go b/internal/utils.go index ca81894..2ff9073 100644 --- a/internal/utils.go +++ b/internal/utils.go @@ -3,6 +3,7 @@ package internal import ( "bytes" "github.com/antonmedv/expr" + "github.com/antonmedv/expr/ast" "github.com/antonmedv/expr/vm" "github.com/chainreactors/logs" "github.com/chainreactors/spray/pkg" @@ -276,3 +277,18 @@ func MatchWithGlobs(u string, globs []string) bool { } return false } + +type bytesPatcher struct{} + +func (p *bytesPatcher) Visit(node *ast.Node) { + switch (*node).(type) { + case *ast.MemberNode: + ast.Patch(node, &ast.CallNode{ + Callee: &ast.MemberNode{ + Node: *node, + Name: "String", + Property: &ast.StringNode{Value: "String"}, + }, + }) + } +} diff --git a/pkg/baseline.go b/pkg/baseline.go index ebcb357..c015ba9 100644 --- a/pkg/baseline.go +++ b/pkg/baseline.go @@ -105,9 +105,9 @@ type Baseline struct { Url *url.URL `json:"-"` Dir bool `json:"-"` Chunked bool `json:"-"` - Body []byte `json:"-"` - Header []byte `json:"-"` - Raw []byte `json:"-"` + Body BS `json:"-"` + Header BS `json:"-"` + Raw BS `json:"-"` Recu bool `json:"-"` RecuDepth int `json:"-"` URLs []string `json:"-"` diff --git a/pkg/types.go b/pkg/types.go index 1dd3575..a5012af 100644 --- a/pkg/types.go +++ b/pkg/types.go @@ -37,3 +37,9 @@ var ErrMap = map[ErrorType]string{ func (e ErrorType) Error() string { return ErrMap[e] } + +type BS []byte + +func (b BS) String() string { + return string(b) +}