github.com/HXSecurity/DongTai-agent-go@v0.4.2/core/base/bufioWriterWrite/replacement.go (about)

     1  package bufioWriterWrite
     2  
     3  import (
     4  	"bufio"
     5  	"github.com/HXSecurity/DongTai-agent-go/global"
     6  	"github.com/HXSecurity/DongTai-agent-go/model/request"
     7  	"github.com/HXSecurity/DongTai-agent-go/utils"
     8  	"reflect"
     9  )
    10  
    11  func Write(b *bufio.Writer, v []byte) (n int, err error) {
    12  
    13  	if utils.IsHook("net/http.(*response).write", 6) {
    14  		value, ok := global.ResponseMap.Load(utils.CatGoroutineID())
    15  		if ok {
    16  			str := utils.StringAdd(value.(string), string(v))
    17  			global.ResponseMap.Store(utils.CatGoroutineID(), str)
    18  		} else {
    19  			global.ResponseMap.Store(utils.CatGoroutineID(), string(v))
    20  		}
    21  
    22  		var u uintptr
    23  		va := reflect.ValueOf(v)
    24  		u = va.Pointer()
    25  		request.FmtHookPool(request.PoolReq{
    26  			Args:            request.Collect(b, v),
    27  			Reqs:            request.Collect(n, err),
    28  			NeedHook:        request.Collect(u),
    29  			Source:          false,
    30  			OriginClassName: "bufio.(*Buffer)",
    31  			MethodName:      "Write",
    32  			ClassName:       "bufio.(*Buffer)",
    33  		})
    34  		if utils.IsHook("net/http.extraHeader.Write", 6) {
    35  			value, ok := global.ResponseHeaderMap.Load(utils.CatGoroutineID())
    36  			if ok {
    37  				str := utils.StringAdd(value.(string), string(v))
    38  				global.ResponseHeaderMap.Store(utils.CatGoroutineID(), str)
    39  			} else {
    40  				global.ResponseHeaderMap.Store(utils.CatGoroutineID(), string(v))
    41  			}
    42  		}
    43  	}
    44  
    45  	return WriteT(b, v)
    46  }
    47  
    48  func WriteT(b *bufio.Writer, v []byte) (n int, err error) {
    49  	return n, err
    50  }