mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-03 03:47:39 +03:00
Fix read android packages
This commit is contained in:
parent
2de6198696
commit
529224be2d
3 changed files with 21 additions and 7 deletions
1
go.mod
1
go.mod
|
@ -4,6 +4,7 @@ go 1.18
|
|||
|
||||
require (
|
||||
github.com/fsnotify/fsnotify v1.5.4
|
||||
github.com/sagernet/abx-go v0.0.0-20220819185957-dba1257d738e
|
||||
github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61
|
||||
github.com/sagernet/netlink v0.0.0-20220816152750-7a75378bd31a
|
||||
github.com/sagernet/sing v0.0.0-20220819003212-2424b1e2fac1
|
||||
|
|
2
go.sum
2
go.sum
|
@ -2,6 +2,8 @@ github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwV
|
|||
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
|
||||
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
|
||||
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
|
||||
github.com/sagernet/abx-go v0.0.0-20220819185957-dba1257d738e h1:5CFRo8FJbCuf5s/eTBdZpmMbn8Fe2eSMLNAYfKanA34=
|
||||
github.com/sagernet/abx-go v0.0.0-20220819185957-dba1257d738e/go.mod h1:qbt0dWObotCfcjAJJ9AxtFPNSDUfZF+6dCpgKEOBn/g=
|
||||
github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61 h1:5+m7c6AkmAylhauulqN/c5dnh8/KssrE9c93TQrXldA=
|
||||
github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61/go.mod h1:QUQ4RRHD6hGGHdFMEtR8T2P6GS6R3D/CXKdaYHKKXms=
|
||||
github.com/sagernet/netlink v0.0.0-20220816152750-7a75378bd31a h1:iNtsfGMenajBUGZ/1yAzl1v3p+t/7IJ/ilQXq9haRZ8=
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package tun
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/xml"
|
||||
"io"
|
||||
|
@ -11,6 +12,7 @@ import (
|
|||
E "github.com/sagernet/sing/common/exceptions"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/sagernet/abx-go"
|
||||
)
|
||||
|
||||
type packageManager struct {
|
||||
|
@ -97,18 +99,27 @@ func (m *packageManager) SharedPackageByID(id uint32) (string, bool) {
|
|||
}
|
||||
|
||||
func (m *packageManager) updatePackages() error {
|
||||
packagesData, err := os.ReadFile("/data/system/packages.xml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var decoder *xml.Decoder
|
||||
reader, ok := abx.NewReader(bytes.NewReader(packagesData))
|
||||
if ok {
|
||||
decoder = xml.NewTokenDecoder(reader)
|
||||
} else {
|
||||
decoder = xml.NewDecoder(bytes.NewReader(packagesData))
|
||||
}
|
||||
return m.decodePackages(decoder)
|
||||
}
|
||||
|
||||
func (m *packageManager) decodePackages(decoder *xml.Decoder) error {
|
||||
idByPackage := make(map[string][]uint32)
|
||||
sharedByPackage := make(map[string]uint32)
|
||||
packageById := make(map[uint32]string)
|
||||
sharedById := make(map[uint32]string)
|
||||
packagesData, err := os.Open("/data/system/packages.xml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
decoder := xml.NewDecoder(packagesData)
|
||||
var token xml.Token
|
||||
for {
|
||||
token, err = decoder.Token()
|
||||
token, err := decoder.Token()
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue