Esempio n. 1
0
        public static List <DeviceInformation> GetDevices()
        {
            IiDeviceApi  iDevice  = LibiMobileDevice.Instance.iDevice;
            ILockdownApi lockdown = LibiMobileDevice.Instance.Lockdown;
            IPlistApi    plist    = LibiMobileDevice.Instance.Plist;
            int          count    = 0;
            ReadOnlyCollection <string> devices;

            if (iDevice.idevice_get_device_list(out devices, ref count) != 0)
            {
                return(new List <DeviceInformation>());
            }
            iDeviceHandle            device = null;
            LockdownClientHandle     client = null;
            PlistHandle              value  = null;
            List <DeviceInformation> list   = new List <DeviceInformation>();

            foreach (string item in devices.Distinct())
            {
                try
                {
                    string deviceName;
                    if (iDevice.idevice_new(out device, item) == iDeviceError.Success && lockdown.lockdownd_client_new_with_handshake(device, out client, "iFakeLocation") == LockdownError.Success && lockdown.lockdownd_get_device_name(client, out deviceName) == LockdownError.Success)
                    {
                        DeviceInformation deviceInformation = new DeviceInformation(deviceName, item);
                        if (lockdown.lockdownd_get_value(client, null, null, out value) == LockdownError.Success && plist.plist_get_node_type(value) == PlistType.Dict)
                        {
                            deviceInformation.ReadProperties(value);
                            if (!deviceInformation.Properties.ContainsKey("HostAttached") || (bool)deviceInformation.Properties["HostAttached"])
                            {
                                list.Add(deviceInformation);
                            }
                        }
                    }
                }
                finally
                {
                    if (value != null)
                    {
                        value.Close();
                    }
                    if (client != null)
                    {
                        client.Close();
                    }
                    if (device != null)
                    {
                        device.Close();
                    }
                }
            }
            return(list);
        }
        public static List <DeviceInformation> GetDevices()
        {
            var idevice  = LibiMobileDevice.Instance.iDevice;
            var lockdown = LibiMobileDevice.Instance.Lockdown;
            var plist    = LibiMobileDevice.Instance.Plist;

            // Retrieve list of unique device identifiers
            ReadOnlyCollection <string> uddids;
            int count = 0;
            var ret   = idevice.idevice_get_device_list(out uddids, ref count);

            if (ret != iDeviceError.Success)
            {
                return(null);
            }

            iDeviceHandle        deviceHandle   = null;
            LockdownClientHandle lockdownHandle = null;
            PlistHandle          plistHandle    = null;

            var devices = new List <DeviceInformation>();

            foreach (var udid in uddids.Distinct())
            {
                try {
                    // Attempt to get device handle of each uuid
                    var err = idevice.idevice_new(out deviceHandle, udid);
                    if (err != iDeviceError.Success)
                    {
                        continue;
                    }

                    // Obtain a lockdown client handle
                    if (lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle,
                                                                     "iFakeLocation") !=
                        LockdownError.Success)
                    {
                        continue;
                    }

                    // Obtain the device name
                    string            name;
                    DeviceInformation device;
                    if (lockdown.lockdownd_get_device_name(lockdownHandle, out name) != LockdownError.Success)
                    {
                        continue;
                    }

                    device = new DeviceInformation(name, udid);

                    // Get device details
                    if (lockdown.lockdownd_get_value(lockdownHandle, null, null, out plistHandle) !=
                        LockdownError.Success ||
                        plist.plist_get_node_type(plistHandle) != PlistType.Dict)
                    {
                        continue;
                    }

                    device.ReadProperties(plistHandle);

                    // Ensure device is attached
                    if (!device.Properties.ContainsKey("HostAttached") || (bool)device.Properties["HostAttached"])
                    {
                        devices.Add(device);
                    }
                }
                finally {
                    // Cleanup
                    if (plistHandle != null)
                    {
                        plistHandle.Close();
                    }
                    if (lockdownHandle != null)
                    {
                        lockdownHandle.Close();
                    }
                    if (deviceHandle != null)
                    {
                        deviceHandle.Close();
                    }
                }
            }

            return(devices);
        }