Exemplo n.º 1
0
        private bool IsDeviceConnected()
        {
            // Don't do anything if a device already connected.
            //if (DeviceConnected) return;

            // Load native imobiledevice shit..
            NativeLibraries.Load();

            bool result = false;

            ReadOnlyCollection <string> _pluggedDevices;
            int pluggedDevicesCount = 0;

            try
            {
                DeviceState   = (iDeviceApi)LibiMobileDevice.Instance.iDevice;
                LockDownState = (LockdownApi)LibiMobileDevice.Instance.Lockdown;

                // Try to connect to any connected iDevice...
                DeviceState.idevice_get_device_list(out _pluggedDevices, ref pluggedDevicesCount);


                // Populate the list with found iDevices and then put
                // the said devices to our global list.
                pluggedDevices = _pluggedDevices;

                // Etasblish connection to found device.
                if (pluggedDevices.Count > 0)
                {
                    // Connect to the first found device...
                    var thisDevice = pluggedDevices[0];

                    DeviceState.idevice_new(out deviceHandle, thisDevice).ThrowOnError();
                    LockDownState.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();
                    DeviceConnected = (LockDownState != null ? true : false);
                    if (DeviceConnected)
                    {
                        //ParseDevice();
                        result = true;
                    }
                }
            }
            catch (LockdownException)
            {
                ReleaseDevice();
                //throw new LockdownException("Couldn't connect to iDevice. Please make sure your device has trusted this pc.");
            }
            return(result);
        }
Exemplo n.º 2
0
        private bool HookDevice()
        {
            // Don't do anything if a device already connected.
            //if (DeviceConnected) return;

            // Load native imobiledevice shit..
            NativeLibraries.Load();

            bool result = false;

            ReadOnlyCollection <string> _pluggedDevices;
            int pluggedDevicesCount = 0;

            try
            {
                DeviceState   = (iDeviceApi)LibiMobileDevice.Instance.iDevice;
                LockDownState = (LockdownApi)LibiMobileDevice.Instance.Lockdown;

                // Try to connect to any connected iDevice...
                DeviceState.idevice_get_device_list(out _pluggedDevices, ref pluggedDevicesCount);


                // Populate the list with found iDevices and then put
                // the said devices to our global list.
                pluggedDevices = _pluggedDevices;

                // Check if any device is present, if no do nothing but display message.
                if (pluggedDevices.Count <= 0)
                {
                    // Not actually an error in our case.
                    MessageBox.Show("No iDevice found!", "No iDevice connected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    ReleaseDevice();
                    result = false;
                }
                // Since we only plan (and only supports) 1 device at a time, check.
                else if (pluggedDevices.Count > 1)
                {
                    MessageBox.Show("Please only connect one iDevice at a time!", "Multiple iDevices detected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    result = false;
                }

                // Etasblish connection to found device.
                if (pluggedDevices.Count > 0)
                {
                    // Connect to the first found device...
                    var thisDevice = pluggedDevices[0];

                    DeviceState.idevice_new(out deviceHandle, thisDevice).ThrowOnError();
                    LockDownState.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();
                    PlistReader     = new PlistApi(LibiMobileDevice.Instance);
                    DeviceConnected = (LockDownState != null ? true : false);
                    if (DeviceConnected)
                    {
                        ParseDevice();
                        result = true;
                    }
                }
            }
            catch (LockdownException)
            {
                ReleaseDevice();
                throw new LockdownException("Couldn't connect to iDevice. Please make sure your device has trusted this pc.");
            }
            return(result);
        }