forked from Kuingsmile/clash-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.go
57 lines (44 loc) · 966 Bytes
/
process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 {
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)
}
func (ps *Process) Adapter() string {
return ps.adapter
}
func (ps *Process) Payload() string {
return ps.process
}
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
}