Skip to content

Commit

Permalink
added discovery code for finding ios devices with QT and Usbmux
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Paulus committed Sep 13, 2019
1 parent 0e3a5e8 commit bf648f4
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
#### Operating System indepedent implementation for Quicktime Screensharing for iOS devices :-)

## MAC OS LIBUSB -- IMPORTANT
Make sure to use either this fork `https://github.com/GroundControl-Solutions/libusb`
or a LibUsb version BELOW 1.0.20 or iOS devices won't be found on Mac OS X.
[See Github Issue](https://github.com/libusb/libusb/issues/290)
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ go 1.13

require (
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 // indirect
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/google/gousb v0.0.0-20190812193832-18f4c1d8a750
github.com/sirupsen/logrus v1.4.2
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/google/gousb v0.0.0-20190812193832-18f4c1d8a750 h1:DVKHLo3yE4psTjD9aM2pY7EHoicaQbgmaxxvvHC6ZSM=
github.com/google/gousb v0.0.0-20190812193832-18f4c1d8a750/go.mod h1:Tl4HdAs1ThE3gECkNwz+1MWicX6FXddhJEw7L8jRDiI=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package main

import (
"github.com/danielpaulus/quicktime_video_hack/usb"
"github.com/docopt/docopt-go"
log "github.com/sirupsen/logrus"
)

func main() {
log.Info("hi")
usage := `iOS client v 0.01
usage := `Q.uickTime V.ideo H.ack or qvh client v0.01
Usage:
qvh devices
Expand All @@ -21,7 +21,8 @@ Options:
arguments, _ := docopt.ParseDoc(usage)
devices, _ := arguments.Bool("devices")
if devices {
log.Info("devices")
log.Info("iOS Devices with QT Endpoint:")
usb.FindIosDevices()
}

}
79 changes: 78 additions & 1 deletion usb/discovery.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,91 @@
package usb

import "errors"
import (
"errors"
"github.com/sirupsen/logrus"
)
import "github.com/google/gousb"

type IosDevice struct {
}

const (
//Interesting, maybe the subclass type Application was chosen intentionally by Apple
//Because this config enables the basic communication between MacOSX Apps and iOS Devices over USBMuxD
UsbMuxSubclass gousb.Class = gousb.ClassApplication
//You can observe this config being activated as soon as you enable iOS Screen Sharing in Quicktime (That's how I
//found out :-D )
QuicktimeSubclass gousb.Class = 0x2A
)

func FindIosDevices() ([]IosDevice, error) {
ctx := gousb.NewContext()
defer ctx.Close()

devices, err := ctx.OpenDevices(func(desc *gousb.DeviceDesc) bool {
// this function is called for every device present.
// Returning true means the device should be opened.
b, _, _ := isValidIosDevice(desc)
return b
})
if err != nil {
return nil, err
}
for _, d := range devices {
serial, err := d.SerialNumber()
if err != nil {
logrus.Fatalf("Failed to get Device UDID for '%s'.. what the hell?!", serial)
}
product, err:= d.Product()
if err != nil{
logrus.Fatalf("Failed to get Device Name for '%s'.. what the hell?!", serial)
}

logrus.Infof("'%s' %s serial: %s",product, d.String(), serial)
}
return nil, errors.New("bla")
}

func isValidIosDevice(desc *gousb.DeviceDesc) (bool, int, int) {
var muxConfigIndex = -1
var qtConfigIndex = -1

for k, v := range desc.Configs {
if isMuxConfig(v) && !isQtConfig(v) {
muxConfigIndex = k
}
if isQtConfig(v) {
qtConfigIndex = k
}
}
if muxConfigIndex == -1 || qtConfigIndex == -1 {
return false, 0, 0
}
return true, muxConfigIndex, qtConfigIndex
}

func isQtConfig(confDesc gousb.ConfigDesc) bool {
b, _ := findInterfaceForSubclass(confDesc, QuicktimeSubclass)
return b
}

func isMuxConfig(confDesc gousb.ConfigDesc) bool {
b, _ := findInterfaceForSubclass(confDesc, UsbMuxSubclass)
return b
}

func findInterfaceForSubclass(confDesc gousb.ConfigDesc, subClass gousb.Class) (bool, int) {
for i := range confDesc.Interfaces {
//usually those interfaces have only one altsetting
isVendorClass := confDesc.Interfaces[i].AltSettings[0].Class == gousb.ClassVendorSpec
isCorrectSubClass := confDesc.Interfaces[i].AltSettings[0].SubClass == subClass
if isVendorClass && isCorrectSubClass {
return true, i
}
}
return false, -1
}

func (d *IosDevice) String() string {
return "IosDevice"
}
Expand Down

0 comments on commit bf648f4

Please sign in to comment.