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); }
/// <summary> /// 加载开发者工具 /// </summary> /// <param name="device"></param> public void LoadDevelopmentTool(DeviceModel device) { var shortVersion = string.Join(".", device.Version.Split('.').Take(2)); PrintMessage($"为设备加载驱动版本 {shortVersion}。"); var basePath = AppDomain.CurrentDomain.BaseDirectory + "/drivers/"; if (!File.Exists($"{basePath}{shortVersion}/inject.dmg")) { PrintMessage($"未找到 {shortVersion} 驱动版本,请下载驱动后重新加载设备。"); //PrintMessage($"请前往:https://pan.baidu.com/s/1MPUTYJTdv7yXEtE8nMIRbQ 提取码:p9ep 按版本自行下载后放入drivers目录。"); return; } Process.Start(new ProcessStartInfo { FileName = "injecttool", UseShellExecute = false, RedirectStandardOutput = false, CreateNoWindow = true, Arguments = ".\\drivers\\" + shortVersion + "\\inject.dmg" }) .WaitForExit(); }
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); } }); }
//主要业务逻辑处理 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); } }); }