Esempio n. 1
0
    def handle(self):
        if 'options' in globals():
            sockpath = options.sockpath
        else:
            sockpath = None
        mux = usbmux.USBMux(sockpath)
        print("Waiting for devices...")
        mux.process(1.0)

        dev = None
        if 'options' in globals():
            udid = options.udid
        else:
            udid = self.server.udid
        if udid:
            for device in mux.devices:
                if device.serial == udid:
                    dev = device
                    break
            if not dev:
                for _ in range(20):
                    mux.process(0.5)
                    for device in mux.devices:
                        if device.serial == udid:
                            dev = device
                            break
                    if dev:
                        break
        else:
            dev = mux.devices[0]

        if not mux.devices:
            print("No device found")
            self.request.close()
            return
        print("Connecting to device %s" % str(dev))
        dsock = mux.connect(dev, self.server.rport)
        lsock = self.request
        print("Connection established, relaying data")
        try:
            fwd = SocketRelay(dsock, lsock, self.server.bufsize * 1024)
            fwd.handle()
        finally:
            dsock.close()
            lsock.close()
            print("Connection closed")
Esempio n. 2
0
    def connect(self, udid=None):
        mux = usbmux.USBMux()
        mux.process(1.0)
        dev = None

        while not dev and mux.devices:
            mux.process(1.0)
            if udid:
                for d in mux.devices:
                    if d.serial == udid:
                        dev = d
            else:
                dev = mux.devices[0]
                self.logger.info("Connecting to device: " + dev.serial)
        try:
            self.s = mux.connect(dev, self.port)
        except:
            raise Exception("Connexion to device port %d failed" % self.port)
        return dev.serial
Esempio n. 3
0
 def handle(self):
     logging.debug("Incoming connection to %d" %
                   self.server.server_address[1])
     mux = usbmux.USBMux(options.sockpath)
     logging.debug("Waiting for devices...")
     if not mux.devices:
         mux.process(1.0)
     if not mux.devices:
         logging.debug("No device found")
         self.request.close()
         return
     dev = mux.devices[0]
     logging.debug("Connecting to device %s" % str(dev))
     dsock = mux.connect(dev, self.server.rport)
     lsock = self.request
     logging.debug("Connection established, relaying data")
     try:
         fwd = SocketRelay(dsock, lsock, self.server.bufsize * 1024)
         fwd.handle()
     finally:
         dsock.close()
         lsock.close()
     logging.debug("Connection closed")
Esempio n. 4
0
def list_devices():
    mux = usbmux.USBMux()
    mux.process(1)
    return [d.serial for d in mux.devices]
Esempio n. 5
0
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
import logging
import ssl
import struct
import plistlib
from re import sub
from pymobiledevice.usbmux import usbmux

mux = usbmux.USBMux()


class PlistService(object):
    def __init__(self, port, udid=None):
        self.port = port
        self.connect(udid)

    def connect(self, udid=None):
        mux.process(1.0)
        dev = None

        while not dev and mux.devices:
            mux.process(1.0)
            if udid:
                for d in mux.devices: