clash/rule/process.go

58 lines
966 B
Go
Raw Normal View History

package rules
import (
"path/filepath"
"strings"
C "github.com/Dreamacro/clash/constant"
)
// Implements C.Rule
var _ C.Rule = (*Process)(nil)
type Process struct {
adapter string
process string
nameOnly bool
}
func (ps *Process) RuleType() C.RuleType {
2022-07-06 13:44:04 +08:00
if ps.nameOnly {
return C.Process
}
return C.ProcessPath
}
func (ps *Process) Match(metadata *C.Metadata) bool {
if ps.nameOnly {
return strings.EqualFold(filepath.Base(metadata.ProcessPath), ps.process)
}
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
}
func (ps *Process) ShouldFindProcess() bool {
return true
}
func NewProcess(process string, adapter string, nameOnly bool) (*Process, error) {
return &Process{
adapter: adapter,
process: process,
nameOnly: nameOnly,
}, nil
}