feat: 修改元数据

This commit is contained in:
Skyxim 2022-06-05 17:54:51 +08:00
parent 55c7c4edb3
commit 9602d42d7d
2 changed files with 24 additions and 2 deletions

View File

@ -89,3 +89,16 @@ type Rule interface {
RuleExtra() *RuleExtra
SetRuleExtra(re *RuleExtra)
}
type JSMetadata struct {
Type string `json:"type"`
Network string `json:"network"`
Host string `json:"host"`
SrcIP string `json:"srcIP"`
DstIP string `json:"dstIP"`
SrcPort string `json:"srcPort"`
DstPort string `json:"dstPort"`
Uid *int32 `json:"uid"`
Process string `json:"process"`
ProcessPath string `json:"processPath"`
}

View File

@ -19,7 +19,17 @@ func (s *Script) RuleType() C.RuleType {
func (s *Script) Match(metadata *C.Metadata) bool {
res := false
js.Run(s.name, map[string]any{
"metadata": metadata,
"metadata": C.JSMetadata{
Host: metadata.Host,
Network: metadata.NetWork.String(),
Type: metadata.Type.String(),
SrcIP: metadata.SrcIP.String(),
SrcPort: metadata.SrcPort,
DstPort: metadata.DstPort,
Uid: metadata.Uid,
Process: metadata.Process,
ProcessPath: metadata.ProcessPath,
},
}, func(a any, err error) {
if err != nil {
res = false
@ -29,7 +39,6 @@ func (s *Script) Match(metadata *C.Metadata) bool {
if !ok {
res = false
}
res = r
})