mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-04 20:37:43 +03:00
Fix include_android_user
This commit is contained in:
parent
e01ce3a8a7
commit
3117b24c68
3 changed files with 26 additions and 15 deletions
|
@ -5,7 +5,7 @@ import E "github.com/sagernet/sing/common/exceptions"
|
||||||
type PackageManager interface {
|
type PackageManager interface {
|
||||||
Start() error
|
Start() error
|
||||||
Close() error
|
Close() error
|
||||||
IDByPackage(packageName string) ([]uint32, bool)
|
IDByPackage(packageName string) (uint32, bool)
|
||||||
IDBySharedPackage(sharedPackage string) (uint32, bool)
|
IDBySharedPackage(sharedPackage string) (uint32, bool)
|
||||||
PackageByID(id uint32) (string, bool)
|
PackageByID(id uint32) (string, bool)
|
||||||
SharedPackageByID(id uint32) (string, bool)
|
SharedPackageByID(id uint32) (string, bool)
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
type packageManager struct {
|
type packageManager struct {
|
||||||
callback PackageManagerCallback
|
callback PackageManagerCallback
|
||||||
watcher *fsnotify.Watcher
|
watcher *fsnotify.Watcher
|
||||||
idByPackage map[string][]uint32
|
idByPackage map[string]uint32
|
||||||
sharedByPackage map[string]uint32
|
sharedByPackage map[string]uint32
|
||||||
packageById map[uint32]string
|
packageById map[uint32]string
|
||||||
sharedById map[uint32]string
|
sharedById map[uint32]string
|
||||||
|
@ -78,7 +78,7 @@ func (m *packageManager) Close() error {
|
||||||
return common.Close(common.PtrOrNil(m.watcher))
|
return common.Close(common.PtrOrNil(m.watcher))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *packageManager) IDByPackage(packageName string) ([]uint32, bool) {
|
func (m *packageManager) IDByPackage(packageName string) (uint32, bool) {
|
||||||
id, loaded := m.idByPackage[packageName]
|
id, loaded := m.idByPackage[packageName]
|
||||||
return id, loaded
|
return id, loaded
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func (m *packageManager) updatePackages() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *packageManager) decodePackages(decoder *xml.Decoder) error {
|
func (m *packageManager) decodePackages(decoder *xml.Decoder) error {
|
||||||
idByPackage := make(map[string][]uint32)
|
idByPackage := make(map[string]uint32)
|
||||||
sharedByPackage := make(map[string]uint32)
|
sharedByPackage := make(map[string]uint32)
|
||||||
packageById := make(map[uint32]string)
|
packageById := make(map[uint32]string)
|
||||||
sharedById := make(map[uint32]string)
|
sharedById := make(map[uint32]string)
|
||||||
|
@ -149,7 +149,7 @@ func (m *packageManager) decodePackages(decoder *xml.Decoder) error {
|
||||||
if userID == 0 && name == "" {
|
if userID == 0 && name == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
idByPackage[name] = append(idByPackage[name], uint32(userID))
|
idByPackage[name] = uint32(userID)
|
||||||
packageById[uint32(userID)] = name
|
packageById[uint32(userID)] = name
|
||||||
case "shared-user":
|
case "shared-user":
|
||||||
var name string
|
var name string
|
||||||
|
|
31
tun_rules.go
31
tun_rules.go
|
@ -15,23 +15,33 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (o *Options) BuildAndroidRules(packageManager PackageManager, errorHandler E.Handler) {
|
func (o *Options) BuildAndroidRules(packageManager PackageManager, errorHandler E.Handler) {
|
||||||
|
var includeUser []uint32
|
||||||
if len(o.IncludeAndroidUser) > 0 {
|
if len(o.IncludeAndroidUser) > 0 {
|
||||||
o.IncludeAndroidUser = common.Uniq(o.IncludeAndroidUser)
|
o.IncludeAndroidUser = common.Uniq(o.IncludeAndroidUser)
|
||||||
sort.Ints(o.IncludeAndroidUser)
|
sort.Ints(o.IncludeAndroidUser)
|
||||||
|
var userExcludeRange []ranges.Range[uint32]
|
||||||
for _, androidUser := range o.IncludeAndroidUser {
|
for _, androidUser := range o.IncludeAndroidUser {
|
||||||
o.IncludeUID = append(o.IncludeUID, ranges.New[uint32](uint32(androidUser)*androidUserRange, uint32(androidUser+1)*androidUserRange-1))
|
includeUser = append(includeUser, uint32(androidUser))
|
||||||
|
userExcludeRange = append(userExcludeRange, ranges.New[uint32](uint32(androidUser)*androidUserRange, uint32(androidUser+1)*androidUserRange-1))
|
||||||
}
|
}
|
||||||
|
userExcludeRange = ranges.Revert(0, userEnd, userExcludeRange)
|
||||||
|
o.ExcludeUID = append(o.ExcludeUID, userExcludeRange...)
|
||||||
|
}
|
||||||
|
if len(includeUser) == 0 {
|
||||||
|
includeUser = []uint32{0}
|
||||||
}
|
}
|
||||||
if len(o.IncludePackage) > 0 {
|
if len(o.IncludePackage) > 0 {
|
||||||
o.IncludePackage = common.Uniq(o.IncludePackage)
|
o.IncludePackage = common.Uniq(o.IncludePackage)
|
||||||
for _, packageName := range o.IncludePackage {
|
for _, packageName := range o.IncludePackage {
|
||||||
if sharedId, loaded := packageManager.IDBySharedPackage(packageName); loaded {
|
if sharedId, loaded := packageManager.IDBySharedPackage(packageName); loaded {
|
||||||
o.IncludeUID = append(o.IncludeUID, ranges.NewSingle(sharedId))
|
for _, androidUser := range includeUser {
|
||||||
|
o.IncludeUID = append(o.IncludeUID, ranges.NewSingle(sharedId+androidUser*androidUserRange))
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ids, loaded := packageManager.IDByPackage(packageName); loaded {
|
if userId, loaded := packageManager.IDByPackage(packageName); loaded {
|
||||||
for _, id := range ids {
|
for _, androidUser := range includeUser {
|
||||||
o.IncludeUID = append(o.IncludeUID, ranges.NewSingle(id))
|
o.IncludeUID = append(o.IncludeUID, ranges.NewSingle(userId+androidUser*androidUserRange))
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -42,12 +52,13 @@ func (o *Options) BuildAndroidRules(packageManager PackageManager, errorHandler
|
||||||
o.ExcludePackage = common.Uniq(o.ExcludePackage)
|
o.ExcludePackage = common.Uniq(o.ExcludePackage)
|
||||||
for _, packageName := range o.ExcludePackage {
|
for _, packageName := range o.ExcludePackage {
|
||||||
if sharedId, loaded := packageManager.IDBySharedPackage(packageName); loaded {
|
if sharedId, loaded := packageManager.IDBySharedPackage(packageName); loaded {
|
||||||
o.ExcludeUID = append(o.ExcludeUID, ranges.NewSingle(sharedId))
|
for _, androidUser := range includeUser {
|
||||||
continue
|
o.ExcludeUID = append(o.ExcludeUID, ranges.NewSingle(sharedId+androidUser*androidUserRange))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ids, loaded := packageManager.IDByPackage(packageName); loaded {
|
if userId, loaded := packageManager.IDByPackage(packageName); loaded {
|
||||||
for _, id := range ids {
|
for _, androidUser := range includeUser {
|
||||||
o.ExcludeUID = append(o.ExcludeUID, ranges.NewSingle(id))
|
o.ExcludeUID = append(o.ExcludeUID, ranges.NewSingle(userId+androidUser*androidUserRange))
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue