github.com/igoogolx/clash@v1.19.8/rule/process.go (about)

     1  package rules
     2  
     3  import (
     4  	"path/filepath"
     5  	"strings"
     6  
     7  	C "github.com/igoogolx/clash/constant"
     8  )
     9  
    10  // Implements C.Rule
    11  var _ C.Rule = (*Process)(nil)
    12  
    13  type Process struct {
    14  	adapter  string
    15  	process  string
    16  	nameOnly bool
    17  }
    18  
    19  func (ps *Process) RuleType() C.RuleType {
    20  	if ps.nameOnly {
    21  		return C.Process
    22  	}
    23  
    24  	return C.ProcessPath
    25  }
    26  
    27  func (ps *Process) Match(metadata *C.Metadata) bool {
    28  	if ps.nameOnly {
    29  		return strings.EqualFold(filepath.Base(metadata.ProcessPath), ps.process)
    30  	}
    31  
    32  	return strings.EqualFold(metadata.ProcessPath, ps.process)
    33  }
    34  
    35  func (ps *Process) Adapter() string {
    36  	return ps.adapter
    37  }
    38  
    39  func (ps *Process) Payload() string {
    40  	return ps.process
    41  }
    42  
    43  func (ps *Process) ShouldResolveIP() bool {
    44  	return false
    45  }
    46  
    47  func (ps *Process) ShouldFindProcess() bool {
    48  	return true
    49  }
    50  
    51  func NewProcess(process string, adapter string, nameOnly bool) (*Process, error) {
    52  	return &Process{
    53  		adapter:  adapter,
    54  		process:  process,
    55  		nameOnly: nameOnly,
    56  	}, nil
    57  }