From fc3f476fe23b0cb2fb590b0713524a99026d6356 Mon Sep 17 00:00:00 2001 From: M09Ic Date: Sat, 3 Jun 2023 21:09:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbytes=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E9=94=99=E8=AF=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/option.go | 6 +++--- internal/utils.go | 16 ++++++++++++++++ pkg/baseline.go | 6 +++--- pkg/types.go | 6 ++++++ 4 files changed, 28 insertions(+), 6 deletions(-) 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) +}