diff --git a/ios/listdevices.go b/ios/listdevices.go index f5fbcb35..604ed01a 100755 --- a/ios/listdevices.go +++ b/ios/listdevices.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "strings" + "time" plist "howett.net/plist" ) @@ -102,9 +103,47 @@ func (muxConn *UsbMuxConnection) ListDevices() (DeviceList, error) { if err != nil { return DeviceList{}, fmt.Errorf("Failed getting devicelist: %v", err) } + muxResponse := MuxResponsefromBytes(response.Payload) + if muxResponse.Number == 0xffffffff { + // get list of devices from Listen + // this is a workaround for the case where connected devices more than 34 + return muxConn.ListDevicesFromListen() + } return DeviceListfromBytes(response.Payload), nil } +func (muxConn *UsbMuxConnection) ListDevicesFromListen() (DeviceList, error) { + attachedReceiver, err := muxConn.Listen() + if err != nil { + return DeviceList{}, fmt.Errorf("Failed to start listening: %v", err) + } + defer muxConn.Close() + + deviceEntryChan := make(chan DeviceEntry) + go func() { + for { + msg, err := attachedReceiver() + if err != nil { + break + } + if msg.DeviceAttached() { + deviceEntryChan <- msg.DeviceEntry() + } + } + }() + var deviceList = DeviceList{ + DeviceList: make([]DeviceEntry, 0, 40), + } + for { + select { + case entry := <-deviceEntryChan: + deviceList.DeviceList = append(deviceList.DeviceList, entry) + case <-time.After(100 * time.Millisecond): + return deviceList, nil + } + } +} + // ListDevices returns a DeviceList containing data about all // currently connected iOS devices using a new UsbMuxConnection func ListDevices() (DeviceList, error) { diff --git a/ios/mobileactivation/activation.go b/ios/mobileactivation/activation.go index 14479b62..0af2587e 100644 --- a/ios/mobileactivation/activation.go +++ b/ios/mobileactivation/activation.go @@ -1,6 +1,7 @@ package mobileactivation import ( + "fmt" "io" "net/url" "strings" @@ -77,7 +78,10 @@ func Activate(device ios.DeviceEntry) error { return err } log.Debugf("CreateTunnel1SessionInfoRequest resp: %v", resp) - val := resp["Value"].(map[string]interface{}) + val, ok := resp["Value"].(map[string]interface{}) + if !ok { + return fmt.Errorf("expected 'Value' to be a map, got nil or wrong type") + } handshakeRequestMessage := val["HandshakeRequestMessage"].([]byte) log.Debugf("HandshakeRequestMessage: %v", handshakeRequestMessage)