-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
installationproxy.go
156 lines (143 loc) · 3.96 KB
/
installationproxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package installationproxy
import (
"bytes"
ios "github.com/danielpaulus/go-ios/ios"
"howett.net/plist"
)
const serviceName = "com.apple.mobile.installation_proxy"
type Connection struct {
deviceConn ios.DeviceConnectionInterface
plistCodec ios.PlistCodec
}
func (c *Connection) Close() {
c.deviceConn.Close()
}
func New(device ios.DeviceEntry) (*Connection, error) {
deviceConn, err := ios.ConnectToService(device, serviceName)
if err != nil {
return &Connection{}, err
}
return &Connection{deviceConn: deviceConn, plistCodec: ios.NewPlistCodec()}, nil
}
func (conn *Connection) BrowseUserApps() ([]AppInfo, error) {
return conn.browseApps(browseUserApps())
}
func (conn *Connection) BrowseSystemApps() ([]AppInfo, error) {
return conn.browseApps(browseSystemApps())
}
func (conn *Connection) browseApps(request interface{}) ([]AppInfo, error) {
reader := conn.deviceConn.Reader()
bytes, err := conn.plistCodec.Encode(request)
if err != nil {
return make([]AppInfo, 0), err
}
conn.deviceConn.Send(bytes)
stillReceiving := true
responses := make([]BrowseResponse, 0)
size := uint64(0)
for stillReceiving {
response, err := conn.plistCodec.Decode(reader)
ifa, err := plistFromBytes(response)
stillReceiving = "Complete" != ifa.Status
if err != nil {
return make([]AppInfo, 0), err
}
size += ifa.CurrentAmount
responses = append(responses, ifa)
}
appinfos := make([]AppInfo, size)
for _, v := range responses {
copy(appinfos[v.CurrentIndex:], v.CurrentList)
}
return appinfos, nil
}
func plistFromBytes(plistBytes []byte) (BrowseResponse, error) {
var browseResponse BrowseResponse
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
err := decoder.Decode(&browseResponse)
if err != nil {
return browseResponse, err
}
return browseResponse, nil
}
func browseSystemApps() map[string]interface{} {
returnAttributes := []string{
"ApplicationDSID",
"ApplicationType",
"CFBundleDisplayName",
"CFBundleExecutable",
"CFBundleIdentifier",
"CFBundleName",
"CFBundleShortVersionString",
"CFBundleVersion",
"Container",
"Entitlements",
"EnvironmentVariables",
"MinimumOSVersion",
"Path",
"ProfileValidated",
"SBAppTags",
"SignerIdentity",
"UIDeviceFamily",
"UIRequiredDeviceCapabilities",
}
clientOptions := map[string]interface{}{
"ApplicationType": "System",
"ReturnAttributes": returnAttributes,
}
return map[string]interface{}{"ClientOptions": clientOptions, "Command": "Browse"}
}
func browseUserApps() map[string]interface{} {
returnAttributes := []string{
"ApplicationDSID",
"ApplicationType",
"CFBundleDisplayName",
"CFBundleExecutable",
"CFBundleIdentifier",
"CFBundleName",
"CFBundleShortVersionString",
"CFBundleVersion",
"Container",
"Entitlements",
"EnvironmentVariables",
"MinimumOSVersion",
"Path",
"ProfileValidated",
"SBAppTags",
"SignerIdentity",
"UIDeviceFamily",
"UIRequiredDeviceCapabilities",
}
clientOptions := map[string]interface{}{
"ApplicationType": "User",
"ReturnAttributes": returnAttributes,
"ShowLaunchProhibitedApps": true,
}
return map[string]interface{}{"ClientOptions": clientOptions, "Command": "Browse"}
}
type BrowseResponse struct {
CurrentIndex uint64
CurrentAmount uint64
Status string
CurrentList []AppInfo
}
type AppInfo struct {
ApplicationDSID int
ApplicationType string
CFBundleDisplayName string
CFBundleExecutable string
CFBundleIdentifier string
CFBundleName string
CFBundleShortVersionString string
CFBundleVersion string
Container string
Entitlements map[string]interface{}
EnvironmentVariables map[string]interface{}
MinimumOSVersion string
Path string
ProfileValidated bool
SBAppTags []string
SignerIdentity string
UIDeviceFamily []int
UIRequiredDeviceCapabilities []string
}