2020-12-17 22:17:27 +08:00
|
|
|
package rules
|
|
|
|
|
|
|
|
import (
|
2022-03-12 19:07:53 +08:00
|
|
|
"path/filepath"
|
2020-12-17 22:17:27 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
)
|
|
|
|
|
2023-08-16 11:06:30 +08:00
|
|
|
// Implements C.Rule
|
|
|
|
var _ C.Rule = (*Process)(nil)
|
|
|
|
|
2020-12-17 22:17:27 +08:00
|
|
|
type Process struct {
|
2022-03-12 19:07:53 +08:00
|
|
|
adapter string
|
|
|
|
process string
|
|
|
|
nameOnly bool
|
2020-12-17 22:17:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ps *Process) RuleType() C.RuleType {
|
2022-07-06 13:44:04 +08:00
|
|
|
if ps.nameOnly {
|
|
|
|
return C.Process
|
|
|
|
}
|
|
|
|
|
|
|
|
return C.ProcessPath
|
2020-12-17 22:17:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ps *Process) Match(metadata *C.Metadata) bool {
|
2022-03-12 19:07:53 +08:00
|
|
|
if ps.nameOnly {
|
|
|
|
return strings.EqualFold(filepath.Base(metadata.ProcessPath), ps.process)
|
2020-12-17 22:17:27 +08:00
|
|
|
}
|
|
|
|
|
2022-03-12 19:07:53 +08:00
|
|
|
return strings.EqualFold(metadata.ProcessPath, ps.process)
|
2020-12-17 22:17:27 +08:00
|
|
|
}
|
|
|
|
|
2021-03-24 01:00:21 +08:00
|
|
|
func (ps *Process) Adapter() string {
|
|
|
|
return ps.adapter
|
2020-12-17 22:17:27 +08:00
|
|
|
}
|
|
|
|
|
2021-03-24 01:00:21 +08:00
|
|
|
func (ps *Process) Payload() string {
|
|
|
|
return ps.process
|
2020-12-17 22:17:27 +08:00
|
|
|
}
|
|
|
|
|
2021-03-24 01:00:21 +08:00
|
|
|
func (ps *Process) ShouldResolveIP() bool {
|
2020-12-17 22:17:27 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-03-12 19:07:53 +08:00
|
|
|
func (ps *Process) ShouldFindProcess() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewProcess(process string, adapter string, nameOnly bool) (*Process, error) {
|
2020-12-17 22:17:27 +08:00
|
|
|
return &Process{
|
2022-03-12 19:07:53 +08:00
|
|
|
adapter: adapter,
|
|
|
|
process: process,
|
|
|
|
nameOnly: nameOnly,
|
2020-12-17 22:17:27 +08:00
|
|
|
}, nil
|
|
|
|
}
|