mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-01-09 07:59:00 +08:00
Some checks are pending
Test / test (1.20, macos-15-intel) (push) Waiting to run
Test / test (1.20, macos-latest) (push) Waiting to run
Test / test (1.20, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.20, ubuntu-latest) (push) Waiting to run
Test / test (1.20, windows-latest) (push) Waiting to run
Test / test (1.21, macos-15-intel) (push) Waiting to run
Test / test (1.21, macos-latest) (push) Waiting to run
Test / test (1.21, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.21, ubuntu-latest) (push) Waiting to run
Test / test (1.21, windows-latest) (push) Waiting to run
Test / test (1.22, macos-15-intel) (push) Waiting to run
Test / test (1.22, macos-latest) (push) Waiting to run
Test / test (1.22, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.22, ubuntu-latest) (push) Waiting to run
Test / test (1.22, windows-latest) (push) Waiting to run
Test / test (1.23, macos-15-intel) (push) Waiting to run
Test / test (1.23, macos-latest) (push) Waiting to run
Test / test (1.23, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.23, ubuntu-latest) (push) Waiting to run
Test / test (1.23, windows-latest) (push) Waiting to run
Test / test (1.24, macos-15-intel) (push) Waiting to run
Test / test (1.24, macos-latest) (push) Waiting to run
Test / test (1.24, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.24, ubuntu-latest) (push) Waiting to run
Test / test (1.24, windows-latest) (push) Waiting to run
Test / test (1.25, macos-15-intel) (push) Waiting to run
Test / test (1.25, macos-latest) (push) Waiting to run
Test / test (1.25, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.25, ubuntu-latest) (push) Waiting to run
Test / test (1.25, windows-latest) (push) Waiting to run
Test / test (1.26.0-rc.1, macos-15-intel) (push) Waiting to run
Test / test (1.26.0-rc.1, macos-latest) (push) Waiting to run
Test / test (1.26.0-rc.1, ubuntu-24.04-arm) (push) Waiting to run
Test / test (1.26.0-rc.1, ubuntu-latest) (push) Waiting to run
Test / test (1.26.0-rc.1, windows-latest) (push) Waiting to run
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package common
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/metacubex/mihomo/component/wildcard"
|
|
C "github.com/metacubex/mihomo/constant"
|
|
|
|
"github.com/dlclark/regexp2"
|
|
)
|
|
|
|
type Process struct {
|
|
Base
|
|
pattern string
|
|
adapter string
|
|
ruleType C.RuleType
|
|
regexp *regexp2.Regexp
|
|
}
|
|
|
|
func (ps *Process) Payload() string {
|
|
return ps.pattern
|
|
}
|
|
|
|
func (ps *Process) Adapter() string {
|
|
return ps.adapter
|
|
}
|
|
|
|
func (ps *Process) RuleType() C.RuleType {
|
|
return ps.ruleType
|
|
}
|
|
|
|
func (ps *Process) Match(metadata *C.Metadata, helper C.RuleMatchHelper) (bool, string) {
|
|
if helper.FindProcess != nil {
|
|
helper.FindProcess()
|
|
}
|
|
var target string
|
|
switch ps.ruleType {
|
|
case C.ProcessName, C.ProcessNameRegex, C.ProcessNameWildcard:
|
|
target = metadata.Process
|
|
default:
|
|
target = metadata.ProcessPath
|
|
}
|
|
|
|
switch ps.ruleType {
|
|
case C.ProcessNameRegex, C.ProcessPathRegex:
|
|
match, _ := ps.regexp.MatchString(target)
|
|
return match, ps.adapter
|
|
case C.ProcessNameWildcard, C.ProcessPathWildcard:
|
|
return wildcard.Match(strings.ToLower(ps.pattern), strings.ToLower(target)), ps.adapter
|
|
default:
|
|
return strings.EqualFold(target, ps.pattern), ps.adapter
|
|
}
|
|
}
|
|
|
|
func NewProcess(pattern string, adapter string, ruleType C.RuleType) (*Process, error) {
|
|
ps := &Process{
|
|
Base: Base{},
|
|
pattern: pattern,
|
|
adapter: adapter,
|
|
ruleType: ruleType,
|
|
}
|
|
switch ps.ruleType {
|
|
case C.ProcessNameRegex, C.ProcessPathRegex:
|
|
r, err := regexp2.Compile(pattern, regexp2.IgnoreCase)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ps.regexp = r
|
|
default:
|
|
}
|
|
return ps, nil
|
|
}
|
|
|
|
var _ C.Rule = (*Process)(nil)
|