mihomo/rule/process.go

54 lines
892 B
Go
Raw Normal View History

package rules
import (
"strings"
C "github.com/Dreamacro/clash/constant"
)
type Process struct {
2022-03-13 01:21:23 +08:00
*Base
adapter string
process string
nameOnly bool
}
func (ps *Process) RuleType() C.RuleType {
return C.Process
}
func (ps *Process) Match(metadata *C.Metadata) bool {
2022-03-13 01:21:23 +08:00
if ps.nameOnly {
2021-07-01 22:49:29 +08:00
return strings.EqualFold(metadata.Process, ps.process)
}
2022-03-13 01:21:23 +08:00
return strings.EqualFold(metadata.ProcessPath, ps.process)
}
2021-03-24 01:00:21 +08:00
func (ps *Process) Adapter() string {
return ps.adapter
}
2021-03-24 01:00:21 +08:00
func (ps *Process) Payload() string {
return ps.process
}
2021-03-24 01:00:21 +08:00
func (ps *Process) ShouldResolveIP() bool {
return false
}
2022-03-13 01:21:23 +08:00
func (ps *Process) ShouldFindProcess() bool {
return true
2021-07-01 22:49:29 +08:00
}
2022-03-13 01:21:23 +08:00
func NewProcess(process string, adapter string, nameOnly bool) (*Process, error) {
return &Process{
2022-03-13 01:21:23 +08:00
Base: &Base{},
adapter: adapter,
process: process,
nameOnly: nameOnly,
}, nil
}
2022-03-13 01:21:23 +08:00
var _ C.Rule = (*Process)(nil)