2022-01-22 22:10:45 +08:00
|
|
|
package common
|
2020-12-17 22:17:27 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2023-11-03 21:01:45 +08:00
|
|
|
C "github.com/metacubex/mihomo/constant"
|
2020-12-17 22:17:27 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type Process struct {
|
2022-03-17 23:24:07 +08:00
|
|
|
*Base
|
|
|
|
adapter string
|
|
|
|
process string
|
|
|
|
nameOnly bool
|
2022-03-16 00:43:08 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
feat: support sub-rule, eg.
rules:
- SUB-RULE,(AND,((NETWORK,TCP),(DOMAIN-KEYWORD,google))),TEST2
- SUB-RULE,(GEOIP,!CN),TEST1
- MATCH,DIRECT
sub-rules:
TEST2:
- MATCH,Proxy
TEST1:
- RULE-SET,Local,DIRECT,no-resolve
- GEOSITE,CN,Domestic
- GEOIP,CN,Domestic
- MATCH,Proxy
2022-09-06 17:30:35 +08:00
|
|
|
func (ps *Process) Match(metadata *C.Metadata) (bool, string) {
|
2022-03-26 16:17:44 +08:00
|
|
|
if ps.nameOnly {
|
feat: support sub-rule, eg.
rules:
- SUB-RULE,(AND,((NETWORK,TCP),(DOMAIN-KEYWORD,google))),TEST2
- SUB-RULE,(GEOIP,!CN),TEST1
- MATCH,DIRECT
sub-rules:
TEST2:
- MATCH,Proxy
TEST1:
- RULE-SET,Local,DIRECT,no-resolve
- GEOSITE,CN,Domestic
- GEOIP,CN,Domestic
- MATCH,Proxy
2022-09-06 17:30:35 +08:00
|
|
|
return strings.EqualFold(metadata.Process, ps.process), ps.adapter
|
2021-11-17 16:03:47 +08:00
|
|
|
}
|
2022-06-14 22:50:57 +08:00
|
|
|
|
feat: support sub-rule, eg.
rules:
- SUB-RULE,(AND,((NETWORK,TCP),(DOMAIN-KEYWORD,google))),TEST2
- SUB-RULE,(GEOIP,!CN),TEST1
- MATCH,DIRECT
sub-rules:
TEST2:
- MATCH,Proxy
TEST1:
- RULE-SET,Local,DIRECT,no-resolve
- GEOSITE,CN,Domestic
- GEOIP,CN,Domestic
- MATCH,Proxy
2022-09-06 17:30:35 +08:00
|
|
|
return strings.EqualFold(metadata.ProcessPath, ps.process), ps.adapter
|
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
|
|
|
}
|
|
|
|
|
2022-06-14 22:50:57 +08:00
|
|
|
func (ps *Process) ShouldFindProcess() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-03-17 23:24:07 +08:00
|
|
|
func NewProcess(process string, adapter string, nameOnly bool) (*Process, error) {
|
2020-12-17 22:17:27 +08:00
|
|
|
return &Process{
|
2022-03-17 23:24:07 +08:00
|
|
|
Base: &Base{},
|
|
|
|
adapter: adapter,
|
|
|
|
process: process,
|
|
|
|
nameOnly: nameOnly,
|
2020-12-17 22:17:27 +08:00
|
|
|
}, nil
|
|
|
|
}
|