sing-box/common/process/searcher_android.go

39 lines
939 B
Go
Raw Permalink Normal View History

package process
import (
"context"
"net/netip"
2022-08-18 23:29:47 +00:00
"github.com/sagernet/sing-tun"
)
var _ Searcher = (*androidSearcher)(nil)
type androidSearcher struct {
packageManager tun.PackageManager
}
func NewSearcher(config Config) (Searcher, error) {
return &androidSearcher{config.PackageManager}, nil
}
2022-08-20 02:38:12 +00:00
func (s *androidSearcher) FindProcessInfo(ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error) {
2022-08-26 09:25:36 +00:00
_, uid, err := resolveSocketByNetlink(network, source, destination)
if err != nil {
return nil, err
}
if sharedPackage, loaded := s.packageManager.SharedPackageByID(uid % 100000); loaded {
return &Info{
2022-08-26 09:25:36 +00:00
UserId: int32(uid),
PackageName: sharedPackage,
}, nil
}
if packageName, loaded := s.packageManager.PackageByID(uid % 100000); loaded {
return &Info{
2022-08-26 09:25:36 +00:00
UserId: int32(uid),
PackageName: packageName,
}, nil
}
2022-08-26 09:25:36 +00:00
return &Info{UserId: int32(uid)}, nil
}