public static void ThrowOnError(this iDeviceError value, string message)
 {
     if ((value != iDeviceError.Success))
     {
         throw new iDeviceException(value, message);
     }
 }
Пример #2
0
        static iDeviceError searchForDevices(out List <iDevice> devices, out IntPtr devicesPtr)
        {
            int          count;
            iDeviceError returnCode = idevice_get_device_list(out devicesPtr, out count);

            devices = new List <iDevice>();
            if (returnCode != iDeviceError.IDEVICE_E_SUCCESS)
            {
                return(returnCode);
            }

            else if (devicesPtr == IntPtr.Zero)
            {
                return(iDeviceError.IDEVICE_E_UNKNOWN_ERROR);
            }

            if (Marshal.ReadInt32(devicesPtr) != 0)
            {
                string currUdid;
                int    i = 0;
                while ((currUdid = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(devicesPtr, i))) != null &&
                       devices.Count(x => x.Udid == currUdid) == 0)
                {
                    IntPtr currDevice;
                    returnCode = NewDevice(out currDevice, currUdid);
                    devices.Add(new iDevice(currDevice, currUdid));
                    i = i + 4;
                }

                idevice_device_list_free(devicesPtr);
            }

            return(returnCode);
        }
        public static iDeviceError idevice_get_udid(iDeviceHandle device, out string udid)
        {
            System.Runtime.InteropServices.ICustomMarshaler udidMarshaler = NativeStringMarshaler.GetInstance(null);
            System.IntPtr udidNative  = System.IntPtr.Zero;
            iDeviceError  returnValue = iDeviceNativeMethods.idevice_get_udid(device, out udidNative);

            udid = ((string)udidMarshaler.MarshalNativeToManaged(udidNative));
            udidMarshaler.CleanUpNativeData(udidNative);
            return(returnValue);
        }
        public static iDeviceError idevice_get_device_list(out System.Collections.ObjectModel.ReadOnlyCollection <string> devices, ref int count)
        {
            System.Runtime.InteropServices.ICustomMarshaler devicesMarshaler = iDeviceListMarshaler.GetInstance(null);
            System.IntPtr devicesNative = System.IntPtr.Zero;
            iDeviceError  returnValue   = iDeviceNativeMethods.idevice_get_device_list(out devicesNative, ref count);

            devices = ((System.Collections.ObjectModel.ReadOnlyCollection <string>)devicesMarshaler.MarshalNativeToManaged(devicesNative));
            devicesMarshaler.CleanUpNativeData(devicesNative);
            return(returnValue);
        }
        public static iDeviceError idevice_get_tcp_endpoint(out string host, ref ushort port)
        {
            System.Runtime.InteropServices.ICustomMarshaler hostMarshaler = NativeStringMarshaler.GetInstance(null);
            System.IntPtr hostNative  = System.IntPtr.Zero;
            iDeviceError  returnValue = iDeviceNativeMethods.idevice_get_tcp_endpoint(out hostNative, ref port);

            host = ((string)hostMarshaler.MarshalNativeToManaged(hostNative));
            hostMarshaler.CleanUpNativeData(hostNative);
            return(returnValue);
        }
Пример #6
0
        // Token: 0x06000021 RID: 33 RVA: 0x0000274C File Offset: 0x0000094C
        public bool GetDevice()
        {
            this.Devices.Clear();
            int num = 0;
            ReadOnlyCollection <string> readOnlyCollection;
            iDeviceError iDeviceError = this.iDevice.idevice_get_device_list(out readOnlyCollection, ref num);
            bool         flag         = iDeviceError == iDeviceError.NoDevice;
            bool         result;

            if (flag)
            {
                result = false;
            }
            else
            {
                iDeviceError.ThrowOnError();
                foreach (string udid in readOnlyCollection)
                {
                    iDeviceHandle iDeviceHandle;
                    this.iDevice.idevice_new(out iDeviceHandle, udid).ThrowOnError();
                    LockdownClientHandle lockdownClientHandle;
                    this.lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "Quamotion").ThrowOnError();
                    string deviceName;
                    this.lockdown.lockdownd_get_device_name(lockdownClientHandle, out deviceName).ThrowOnError();
                    string      version = "";
                    PlistHandle node;
                    bool        flag2 = this.lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "waua") == LockdownError.Success && this.lockdown.lockdownd_get_value(lockdownClientHandle, null, "ProductVersion", out node) == LockdownError.Success;
                    if (flag2)
                    {
                        LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out version);
                    }
                    iDeviceHandle.Dispose();
                    lockdownClientHandle.Dispose();
                    DeviceModel device = new DeviceModel
                    {
                        UDID    = udid,
                        Name    = deviceName,
                        Version = version
                    };
                    this.PrintMessage(string.Concat(new string[]
                    {
                        "发现设备: ",
                        deviceName,
                        "  ",
                        version,
                        "  ",
                        udid
                    }));
                    this.LoadDevelopmentTool(device);
                    this.Devices.Add(device);
                }
                result = true;
            }
            return(result);
        }
Пример #7
0
        public static iDeviceError GetDeviceList(out List <iDevice> deviceList)
        {
            List <iDevice> devices = new List <iDevice>();
            IntPtr         devicesPtr;
            iDeviceError   returnCode = searchForDevices(out devices, out devicesPtr);

            deviceList = new List <iDevice>();
            if (returnCode != iDeviceError.IDEVICE_E_SUCCESS)
            {
                return(returnCode);
            }

            foreach (iDevice currDevice in devices)
            {
                IntPtr lockdownService;
                IntPtr lockdownClient;
                Lockdown.LockdownError lockdownReturnCode = Lockdown.Start(currDevice.Handle, out lockdownClient, out lockdownService);

                if (lockdownReturnCode != Lockdown.LockdownError.LOCKDOWN_E_SUCCESS)
                {
                    idevice_free(currDevice.Handle);
                    continue;
                }

                XDocument deviceProperties;
                lockdownReturnCode = Lockdown.GetProperties(lockdownClient, out deviceProperties);

                if (lockdownReturnCode != Lockdown.LockdownError.LOCKDOWN_E_SUCCESS || deviceProperties == default(XDocument))
                {
                    lockdownReturnCode = Lockdown.FreeService(lockdownService);
                    lockdownReturnCode = Lockdown.FreeClient(lockdownClient);
                    idevice_free(currDevice.Handle);
                    continue;
                }

                IEnumerable <XElement> keys = deviceProperties.Descendants("dict").Descendants("key");
                deviceList.Add(new iDevice(
                                   IntPtr.Zero,
                                   keys.Where(x => x.Value == "UniqueDeviceID").Select(x => (x.NextNode as XElement).Value).FirstOrDefault(),
                                   keys.Where(x => x.Value == "SerialNumber").Select(x => (x.NextNode as XElement).Value).FirstOrDefault(),
                                   keys.Where(x => x.Value == "DeviceName").Select(x => (x.NextNode as XElement).Value).FirstOrDefault(),
                                   keys.Where(x => x.Value == "ProductType").Select(x => (x.NextNode as XElement).Value).FirstOrDefault()
                                   ));

                Lockdown.FreeService(lockdownService);
                Lockdown.FreeClient(lockdownClient);
                idevice_free(currDevice.Handle);
            }

            return(returnCode);
        }
Пример #8
0
        public bool GetDevice()
        {
            Devices.Clear();
            var          num          = 0;
            iDeviceError iDeviceError = iDevice.idevice_get_device_list(out var readOnlyCollection, ref num);

            if (iDeviceError == iDeviceError.NoDevice)
            {
                return(false);
            }
            iDeviceError.ThrowOnError();
            foreach (string udid in readOnlyCollection)
            {
                //iDeviceHandle iDeviceHandle;
                iDevice.idevice_new(out var iDeviceHandle, udid).ThrowOnError();
                //LockdownClientHandle lockdownClientHandle;
                lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out var lockdownClientHandle, "Quamotion").ThrowOnError();
                //string deviceName;
                lockdown.lockdownd_get_device_name(lockdownClientHandle, out var deviceName).ThrowOnError();
                string      version = "";
                PlistHandle node;
                if (lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "waua") == LockdownError.Success && lockdown.lockdownd_get_value(lockdownClientHandle, null, "ProductVersion", out node) == LockdownError.Success)
                {
                    LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out version);
                }
                iDeviceHandle.Dispose();
                lockdownClientHandle.Dispose();
                var device = new DeviceModel
                {
                    UDID    = udid,
                    Name    = deviceName,
                    Version = version
                };

                PrintMessage($"发现设备: {deviceName}  {version}  {udid}");
                LoadDevelopmentTool(device);
                Devices.Add(device);
            }
            return(true);
        }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="iDeviceException"/> class with a specified error code and error message.
 /// </summary>
 /// <param name="error">
 /// The error code of the error that occurred.
 /// </param>
 /// <param name="message">
 /// A message which describes the error.
 /// </param>
 public iDeviceException(iDeviceError error, string message) :
     base(string.Format("An iDevice error occurred. {1}. The error code was {0}", error, message))
 {
     this.errorCode = error;
 }
 public static bool IsError(this iDeviceError value)
 {
     return(value != iDeviceError.Success);
 }
Пример #11
0
        // Token: 0x06000020 RID: 32 RVA: 0x000026DC File Offset: 0x000008DC
        public void ListeningDevice()
        {
            int num = 0;
            ReadOnlyCollection <string> devices;
            iDeviceError deviceError = this.iDevice.idevice_get_device_list(out devices, ref num);
            bool         flag        = deviceError > iDeviceError.Success;

            if (flag)
            {
                this.PrintMessage("无法继续.可能本工具权限不足, 或者未正确安装iTunes工具.");
            }
            else
            {
                Action <DeviceModel> < > 9__1;
                ThreadPool.QueueUserWorkItem(delegate(object o)
                {
                    for (;;)
                    {
                        List <DeviceModel> devices;
                        deviceError = this.iDevice.idevice_get_device_list(out devices, ref num);
                        bool flag2  = devices.Count > 0;
                        if (flag2)
                        {
                            List <string> lst = (from s in this.Devices
                                                 select s.UDID).ToList <string>().Except(devices).ToList <string>();
                            List <string> dst = devices.Except(from s in this.Devices
                                                               select s.UDID).ToList <string>();
                            foreach (string udid in dst)
                            {
                                iDeviceHandle iDeviceHandle;
                                this.iDevice.idevice_new(out iDeviceHandle, udid).ThrowOnError();
                                LockdownClientHandle lockdownClientHandle;
                                this.lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "Quamotion").ThrowOnError("无法读取设备Quamotion");
                                string deviceName;
                                this.lockdown.lockdownd_get_device_name(lockdownClientHandle, out deviceName).ThrowOnError("获取设备名称失败.");
                                this.lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "waua").ThrowOnError("无法读取设备waua");
                                PlistHandle node;
                                this.lockdown.lockdownd_get_value(lockdownClientHandle, null, "ProductVersion", out node).ThrowOnError("获取设备系统版本失败.");
                                string version;
                                LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out version);
                                iDeviceHandle.Dispose();
                                lockdownClientHandle.Dispose();
                                DeviceModel device = new DeviceModel
                                {
                                    UDID    = udid,
                                    Name    = deviceName,
                                    Version = version
                                };
                                this.PrintMessage("发现设备: " + deviceName + "  " + version);
                                this.LoadDevelopmentTool(device);
                                this.Devices.Add(device);
                            }
                        }
                        else
                        {
                            devices = this.Devices;
                            Action <DeviceModel> action;
                            if ((action = < > 9__1) == null)
                            {
                                action = (< > 9__1 = delegate(DeviceModel itm)
                                {
                                    this.PrintMessage(string.Concat(new string[]
                                    {
                                        "设备 ",
                                        itm.Name,
                                        " ",
                                        itm.Version,
                                        " 已断开连接."
                                    }));
                                });
                            }
                            devices.ForEach(action);
                            this.Devices.Clear();
                        }
                        Thread.Sleep(1000);
                    }
                });
            }
        }