-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
buid.go
52 lines (45 loc) · 1.11 KB
/
buid.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
package ios
import (
"bytes"
plist "howett.net/plist"
)
type readBuid struct {
BundleID string
ClientVersionString string
MessageType string
ProgName string
LibUSBMuxVersion uint32 `plist:"kLibUSBMuxVersion"`
}
type readBuidResponse struct {
BUID string
}
func newReadBuid() readBuid {
data := readBuid{
BundleID: "go.ios.control",
ClientVersionString: "go-usbmux-0.0.1",
MessageType: "ReadBUID",
ProgName: "go-usbmux",
LibUSBMuxVersion: 3,
}
return data
}
func readBuidResponsefromBytes(plistBytes []byte) readBuidResponse {
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
var data readBuidResponse
_ = decoder.Decode(&data)
return data
}
//ReadBuid requests the BUID of the host
//It returns the deserialized BUID as a string.
func (muxConn *UsbMuxConnection) ReadBuid() (string, error) {
err:= muxConn.Send(newReadBuid())
if err != nil {
return "", err
}
resp, err := muxConn.ReadMessage()
if err != nil {
return "", err
}
buidResponse := readBuidResponsefromBytes(resp.Payload)
return buidResponse.BUID, nil
}