예제 #1
0
        public void ListeningDevice()
        {
            var num         = 0;
            var deviceError = iDevice.idevice_get_device_list(out var devices, ref num);

            if (deviceError != iDeviceError.Success)
            {
                PrintMessage("无法继续.可能本工具权限不足, 没有正确电脑下载安装苹果爱思助手:http://url.i4.cn/faIfqyaa.");
                return;
            }
            ThreadPool.QueueUserWorkItem(o =>
            {
                while (true)
                {
                    deviceError = iDevice.idevice_get_device_list(out devices, ref num);
                    if (devices.Count > 0)
                    {
                        var lst = Devices.Select(s => s.UDID).ToList().Except(devices).ToList();

                        var dst = devices.Except(Devices.Select(s => s.UDID)).ToList();

                        foreach (string udid in dst)
                        {
                            iDeviceHandle iDeviceHandle;
                            iDevice.idevice_new(out iDeviceHandle, udid).ThrowOnError();
                            LockdownClientHandle lockdownClientHandle;

                            lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "Quamotion").ThrowOnError("无法读取设备Quamotion");

                            lockdown.lockdownd_get_device_name(lockdownClientHandle, out var deviceName).ThrowOnError("获取设备名称失败.");

                            lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "waua").ThrowOnError("无法读取设备waua");

                            lockdown.lockdownd_get_value(lockdownClientHandle, null, "ProductVersion", out var node).ThrowOnError("获取设备系统版本失败.");

                            LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out var version);

                            iDeviceHandle.Dispose();
                            lockdownClientHandle.Dispose();
                            var device = new DeviceModel
                            {
                                UDID    = udid,
                                Name    = deviceName,
                                Version = version
                            };

                            PrintMessage($"发现设备: {deviceName}  {version}");
                            LoadDevelopmentTool(device);
                            Devices.Add(device);
                        }
                    }
                    else
                    {
                        Devices.ForEach(itm => PrintMessage($"设备 {itm.Name} {itm.Version} 已断开连接."));
                        Devices.Clear();
                    }
                    Thread.Sleep(1000);
                }
            });
        }
예제 #2
0
        private void Refresh()
        {
            comboBox1.Items.Clear();

            ReadOnlyCollection <string> udids;
            int count = 0;

            var idevice = LibiMobileDevice.Instance.iDevice;

            var ret = idevice.idevice_get_device_list(out udids, ref count);

            if (ret == iDeviceError.NoDevice)
            {
                // Not actually an error in our case
                return;
            }

            ret.ThrowOnError();
            // Get the device name
            foreach (var udid in udids)
            {
                iDeviceHandle deviceHandle;
                idevice.idevice_new(out deviceHandle, udid).ThrowOnError();

                LockdownClientHandle lockdownHandle;
                lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, null)
                .ThrowOnError();

                string deviceName;
                lockdown.lockdownd_get_device_name(lockdownHandle, out deviceName).ThrowOnError();
                comboBox1.Items.Add(deviceName + " " + udid);
                deviceHandle.Dispose();
                lockdownHandle.Dispose();
            }

            if (comboBox1.Items.Count != 0)
            {
                comboBox1.SelectedIndex = 0;
            }
        }
예제 #3
0
        private int create_new_device(string udid, ref DeviceModel device)
        {
            iDeviceHandle iDeviceHandle;

            iDevice.idevice_new(out iDeviceHandle, udid).ThrowOnError();
            LockdownClientHandle lockdownClientHandle;

            var ret_handshake = lockdown.lockdownd_client_new_with_handshake(iDeviceHandle,
                                                                             out lockdownClientHandle, "Quamotion");

            if (ret_handshake != 0)
            {
                return(-1);
            }

            var ret_get_devname = lockdown.lockdownd_get_device_name(lockdownClientHandle,
                                                                     out var deviceName);

            if (ret_get_devname != 0)
            {
                return(-1);
            }

            ret_handshake = lockdown.lockdownd_client_new_with_handshake(iDeviceHandle,
                                                                         out lockdownClientHandle, "waua");
            if (ret_handshake != 0)
            {
                return(-1);
            }

            var ret_get_value = lockdown.lockdownd_get_value(lockdownClientHandle, null,
                                                             "ProductVersion", out var node);

            if (ret_get_devname != 0)
            {
                return(-1);
            }

            LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out var version);

            ret_get_value = lockdown.lockdownd_get_value(lockdownClientHandle, null,
                                                         "BuildVersion", out node);
            if (ret_get_devname != 0)
            {
                return(-1);
            }

            LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out var bldVersion);

            iDeviceHandle.Dispose();
            lockdownClientHandle.Dispose();

            device.UDID         = udid;
            device.Name         = deviceName;
            device.Version      = version;
            device.BuildVersion = bldVersion;
            device.ShortVersion = string.Join(".", version.Split('.').Take(2));
            device.FullVersion  = string.Join(".", version.Split('.').Take(2)) + "(" + bldVersion + ")";
            device.isDevMode    = DeviceUtils.is_device_on_dev_mode(udid);

            return(0);
        }
예제 #4
0
        public void ListeningDevice()
        {
            var num         = 0;
            var deviceError = iDevice.idevice_get_device_list(out var devices, ref num);

            if (deviceError != iDeviceError.Success)
            {
                PrintMessage("Please install iTunes first!");
                return;
            }
            ThreadPool.QueueUserWorkItem(o =>
            {
                while (true)
                {
                    deviceError = iDevice.idevice_get_device_list(out devices, ref num);
                    if (devices.Count > 0)
                    {
                        var lst = Devices.Select(s => s.UDID).ToList().Except(devices).ToList();

                        var dst = devices.Except(Devices.Select(s => s.UDID)).ToList();

                        foreach (string udid in dst)
                        {
                            var info = new iMobileDevice.Usbmuxd.UsbmuxdDeviceInfo();
                            LibiMobileDevice.Instance.Usbmuxd.usbmuxd_get_device_by_udid(udid, ref info);
                            if (info.product_id == 0)
                            {
                                continue;
                            }
                            iDeviceHandle iDeviceHandle;
                            iDevice.idevice_new(out iDeviceHandle, udid).ThrowOnError();
                            LockdownClientHandle lockdownClientHandle;

                            lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "Quamotion").ThrowOnError("无法读取设备Quamotion");

                            lockdown.lockdownd_get_device_name(lockdownClientHandle, out var deviceName).ThrowOnError("获取设备名称失败.");

                            lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "waua").ThrowOnError("无法读取设备waua");

                            lockdown.lockdownd_get_value(lockdownClientHandle, null, "ProductVersion", out var node).ThrowOnError("获取设备系统版本失败.");

                            LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out var version);

                            iDeviceHandle.Dispose();
                            lockdownClientHandle.Dispose();
                            var device = new DeviceModel
                            {
                                UDID    = udid,
                                Name    = deviceName,
                                Version = version
                            };

                            PrintMessage($"Found device: {deviceName}  {version}");
                            LoadDevelopmentTool(device);
                            Devices.Add(device);
                        }
                    }
                    else
                    {
                        Devices.ForEach(itm => PrintMessage($"Device {itm.Name} {itm.Version} disconnected."));
                        Devices.Clear();
                    }
                    Thread.Sleep(1000);
                }
            });
        }
예제 #5
0
        public void EnableDeveloperMode(string deviceImagePath, string deviceImageSignaturePath)
        {
            if (!File.Exists(deviceImagePath) || !File.Exists(deviceImageSignaturePath))
            {
                throw new FileNotFoundException("The specified device image files do not exist.");
            }
            iDeviceHandle                   device     = null;
            LockdownClientHandle            client     = null;
            LockdownServiceDescriptorHandle service    = null;
            MobileImageMounterClientHandle  client2    = null;
            AfcClientHandle                 client3    = null;
            PlistHandle            result              = null;
            FileStream             fileStream          = null;
            DiskImageUploadMode    diskImageUploadMode = (int.Parse(((string)Properties["ProductVersion"]).Split('.')[0]) >= 7) ? DiskImageUploadMode.UploadImage : DiskImageUploadMode.AFC;
            IiDeviceApi            iDevice             = LibiMobileDevice.Instance.iDevice;
            ILockdownApi           lockdown            = LibiMobileDevice.Instance.Lockdown;
            IServiceApi            service2            = LibiMobileDevice.Instance.Service;
            IMobileImageMounterApi mobileImageMounter  = LibiMobileDevice.Instance.MobileImageMounter;
            IAfcApi afc = LibiMobileDevice.Instance.Afc;

            try
            {
                if (iDevice.idevice_new(out device, UDID) != 0)
                {
                    throw new Exception("Unable to open device, is it connected?");
                }
                if (lockdown.lockdownd_client_new_with_handshake(device, out client, "iFakeLocation") != 0)
                {
                    throw new Exception("Unable to connect to lockdownd.");
                }
                if (lockdown.lockdownd_start_service(client, "com.apple.mobile.mobile_image_mounter", out service) != 0)
                {
                    throw new Exception("Unable to start the mobile image mounter service.");
                }
                if (mobileImageMounter.mobile_image_mounter_new(device, service, out client2) != 0)
                {
                    throw new Exception("Unable to create mobile image mounter instance.");
                }
                service.Close();
                service = null;
                if (diskImageUploadMode == DiskImageUploadMode.AFC)
                {
                    if (lockdown.lockdownd_start_service(client, "com.apple.afc", out service) != 0)
                    {
                        throw new Exception("Unable to start AFC service.");
                    }
                    if (afc.afc_client_new(device, service, out client3) != 0)
                    {
                        throw new Exception("Unable to connect to AFC service.");
                    }
                    service.Close();
                    service = null;
                }
                client.Close();
                client = null;
                if (mobileImageMounter.mobile_image_mounter_lookup_image(client2, "Developer", out result) != 0)
                {
                    goto IL_01c7;
                }
                Dictionary <string, object> dictionary = PlistReader.ReadPlistDictFromNode(result, new string[2]
                {
                    "ImagePresent",
                    "ImageSignature"
                });
                if ((!dictionary.ContainsKey("ImagePresent") || !(dictionary["ImagePresent"] is bool) || !(bool)dictionary["ImagePresent"]) && !dictionary.ContainsKey("ImageSignature"))
                {
                    goto IL_01c7;
                }
                goto end_IL_0094;
IL_01c7:
                result.Close();
                result = null;
                string text      = "PublicStaging/staging.dimage";
                string imagePath = "/private/var/mobile/Media/" + text;
                fileStream = new FileStream(deviceImagePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                byte[] array = File.ReadAllBytes(deviceImageSignaturePath);
                switch (diskImageUploadMode)
                {
                case DiskImageUploadMode.UploadImage:
                {
                    GCHandle value = GCHandle.Alloc(fileStream);
                    mobileImageMounter.mobile_image_mounter_upload_image(client2, "Developer", uint.Parse(fileStream.Length.ToString()), array, ushort.Parse(array.Length.ToString()), MounterUploadCallback, GCHandle.ToIntPtr(value));
                    value.Free();
                    break;
                }

                case DiskImageUploadMode.AFC:
                {
                    ReadOnlyCollection <string> fileInformation;
                    if (afc.afc_get_file_info(client3, "PublicStaging", out fileInformation) != 0 || afc.afc_make_directory(client3, "PublicStaging") != 0)
                    {
                        throw new Exception("Unable to create directory 'PublicStaging' on the device.");
                    }
                    ulong handle = 0uL;
                    if (afc.afc_file_open(client3, text, AfcFileMode.FopenWronly, ref handle) != 0)
                    {
                        throw new Exception("Unable to create file '" + text + "'.");
                    }
                    uint   num    = 0u;
                    byte[] array2 = new byte[8192];
                    do
                    {
                        num = (uint)fileStream.Read(array2, 0, array2.Length);
                        if (num != 0)
                        {
                            uint bytesWritten = 0u;
                            uint num2;
                            for (num2 = 0u; num2 < num; num2 += bytesWritten)
                            {
                                if (afc.afc_file_write(client3, handle, array2, num, ref bytesWritten) != 0)
                                {
                                    afc.afc_file_close(client3, handle);
                                    throw new Exception("An AFC write error occurred.");
                                }
                            }
                            if (num2 != num)
                            {
                                afc.afc_file_close(client3, handle);
                                throw new Exception("The developer image was not written completely.");
                            }
                        }
                    }while (num != 0);
                    afc.afc_file_close(client3, handle);
                    break;
                }
                }
                if (mobileImageMounter.mobile_image_mounter_mount_image(client2, imagePath, array, ushort.Parse(array.Length.ToString()), "Developer", out result) != 0)
                {
                    throw new Exception("Unable to mount developer image.");
                }
                Dictionary <string, object> dictionary2 = PlistReader.ReadPlistDictFromNode(result);
                if (!dictionary2.ContainsKey("Status") || dictionary2["Status"] as string != "Complete")
                {
                    object obj  = dictionary2.ContainsKey("Status") ? dictionary2["Status"] : "N/A";
                    string str  = (obj != null) ? obj.ToString() : null;
                    object obj2 = dictionary2.ContainsKey("Error") ? dictionary2["Error"] : "N/A";
                    throw new Exception("Mount failed with status: " + str + " and error: " + ((obj2 != null) ? obj2.ToString() : null));
                }
                end_IL_0094 :;
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
                if (result != null)
                {
                    result.Close();
                }
                if (client3 != null)
                {
                    client3.Close();
                }
                if (client2 != null)
                {
                    client2.Close();
                }
                if (service != null)
                {
                    service.Close();
                }
                if (client != null)
                {
                    client.Close();
                }
                if (device != null)
                {
                    device.Close();
                }
            }
        }
예제 #6
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);
        }
예제 #7
0
        private static void SetLocation(DeviceInformation deviceInfo, PointLatLng?target)
        {
            iDeviceHandle                   device  = null;
            LockdownClientHandle            client  = null;
            LockdownServiceDescriptorHandle service = null;
            ServiceClientHandle             client2 = null;
            IiDeviceApi  iDevice  = LibiMobileDevice.Instance.iDevice;
            ILockdownApi lockdown = LibiMobileDevice.Instance.Lockdown;
            IServiceApi  service2 = LibiMobileDevice.Instance.Service;

            try
            {
                if (iDevice.idevice_new(out device, deviceInfo.UDID) != 0)
                {
                    throw new Exception("Unable to connect to the device. Make sure it is connected.");
                }
                if (lockdown.lockdownd_client_new_with_handshake(device, out client, "iFakeLocation") != 0)
                {
                    throw new Exception("Unable to connect to lockdownd.");
                }
                if (lockdown.lockdownd_start_service(client, "com.apple.dt.simulatelocation", out service) != 0 || service.IsInvalid)
                {
                    throw new Exception("Unable to start simulatelocation service.");
                }
                if (service2.service_client_new(device, service, out client2) != 0)
                {
                    throw new Exception("Unable to create simulatelocation service client.");
                }
                if (!target.HasValue)
                {
                    byte[] array = ToBytesBE(1);
                    uint   sent  = 0u;
                    if (service2.service_send(client2, array, (uint)array.Length, ref sent) != 0)
                    {
                        throw new Exception("Unable to send stop message to device.");
                    }
                }
                else
                {
                    byte[] array2 = ToBytesBE(0);
                    byte[] bytes  = Encoding.ASCII.GetBytes(target.Value.Lat.ToString(CultureInfo.InvariantCulture));
                    byte[] bytes2 = Encoding.ASCII.GetBytes(target.Value.Lng.ToString(CultureInfo.InvariantCulture));
                    byte[] array3 = ToBytesBE(bytes.Length);
                    byte[] array4 = ToBytesBE(bytes2.Length);
                    uint   sent2  = 0u;
                    if (service2.service_send(client2, array2, (uint)array2.Length, ref sent2) != 0 || service2.service_send(client2, array3, (uint)array3.Length, ref sent2) != 0 || service2.service_send(client2, bytes, (uint)bytes.Length, ref sent2) != 0 || service2.service_send(client2, array4, (uint)array4.Length, ref sent2) != 0 || service2.service_send(client2, bytes2, (uint)bytes2.Length, ref sent2) != 0)
                    {
                        throw new Exception("Unable to send co-ordinates to device.");
                    }
                }
            }
            finally
            {
                if (client2 != null)
                {
                    client2.Close();
                }
                if (service != null)
                {
                    service.Close();
                }
                if (client != null)
                {
                    client.Close();
                }
                if (device != null)
                {
                    device.Close();
                }
            }
        }
예제 #8
0
        //主要业务逻辑处理
        public void ListeningDevice()
        {
            var num         = 0;
            var deviceError = iDevice.idevice_get_device_list(out var devices, ref num);

            if (deviceError != iDeviceError.Success)
            {
                PrintMessage("Cannot continue! Maybe you don't install the itunes or lighting-line is fake!");
                PrintMessage("the error message is :" + deviceError);
                return;
            }
            ThreadPool.QueueUserWorkItem(o =>
            {
                while (true)
                {
                    deviceError = iDevice.idevice_get_device_list(out devices, ref num);
                    if (devices.Count > 0)
                    {
                        var lst = Devices.Select(s => s.UDID).ToList().Except(devices).ToList();

                        var dst = devices.Except(Devices.Select(s => s.UDID)).ToList();

                        foreach (string udid in dst)
                        {
                            iDeviceHandle iDeviceHandle;
                            iDevice.idevice_new(out iDeviceHandle, udid).ThrowOnError();
                            //获取UUID
                            String uuid;
                            iDevice.idevice_get_udid(iDeviceHandle, out uuid);
                            Uid = uuid;

                            LockdownClientHandle lockdownClientHandle;

                            lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "Quamotion").ThrowOnError("无法读取设备Quamotion");

                            lockdown.lockdownd_get_device_name(lockdownClientHandle, out var deviceName).ThrowOnError("获取设备名称失败.");

                            lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "waua").ThrowOnError("无法读取设备waua");

                            lockdown.lockdownd_get_value(lockdownClientHandle, null, "ProductVersion", out var node).ThrowOnError("获取设备系统版本失败.");

                            LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out var version);

                            iDeviceHandle.Dispose();
                            lockdownClientHandle.Dispose();
                            var device = new DeviceModel
                            {
                                UDID    = udid,
                                Name    = deviceName,
                                Version = version
                            };

                            PrintMessage($"发现设备: {deviceName}  {version}");
                            LoadDevelopmentTool(device);
                            Devices.Add(device);
                        }
                    }
                    else
                    {
                        Devices.ForEach(itm => PrintMessage($"设备 {itm.Name} {itm.Version} 已断开连接."));
                        Devices.Clear();
                    }
                    Thread.Sleep(1000);
                }
            });
        }