-
-
Notifications
You must be signed in to change notification settings - Fork 182
/
startservice.go
executable file
·67 lines (60 loc) · 2.22 KB
/
startservice.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
package ios
import (
"bytes"
"fmt"
log "github.com/sirupsen/logrus"
plist "howett.net/plist"
)
type startServiceRequest struct {
Label string
Request string
Service string
}
// StartServiceResponse is sent by the phone after starting a service, it contains servicename, port and tells us
// whether we should enable SSL or not.
type StartServiceResponse struct {
Port uint16
Request string
Service string
EnableServiceSSL bool
Error string
}
func getStartServiceResponsefromBytes(plistBytes []byte) StartServiceResponse {
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
var data StartServiceResponse
_ = decoder.Decode(&data)
return data
}
// StartService sends a StartServiceRequest using the provided serviceName
// and returns the Port of the services in a BigEndian Integer.
// This port cann be used with a new UsbMuxClient and the Connect call.
func (lockDownConn *LockDownConnection) StartService(serviceName string) (StartServiceResponse, error) {
err := lockDownConn.Send(startServiceRequest{Label: "go.ios.control", Request: "StartService", Service: serviceName})
if err != nil {
return StartServiceResponse{}, err
}
resp, err := lockDownConn.ReadMessage()
if err != nil {
return StartServiceResponse{}, err
}
response := getStartServiceResponsefromBytes(resp)
if response.Error != "" {
return StartServiceResponse{}, fmt.Errorf("Could not start service:%s with reason:'%s'. Have you mounted the Developer Image?", serviceName, response.Error)
}
log.WithFields(log.Fields{"Port": response.Port, "Request": response.Request, "Service": response.Service, "EnableServiceSSL": response.EnableServiceSSL}).Debug("Service started on device")
return response, nil
}
// StartService conveniently starts a service on a device and cleans up the used UsbMuxconnection.
// It returns the service port as a uint16 in BigEndian byte order.
func StartService(device DeviceEntry, serviceName string) (StartServiceResponse, error) {
lockdown, err := ConnectLockdownWithSession(device)
if err != nil {
return StartServiceResponse{}, err
}
defer lockdown.Close()
response, err := lockdown.StartService(serviceName)
if err != nil {
return response, err
}
return response, nil
}