private static ServiceError SendString(ServiceClientHandle serviceClientHandle, string str) { var service = iMobileDevice.LibiMobileDevice.Instance.Service; uint num2 = 0; var sLat = Encoding.UTF8.GetBytes(str); byte[] dataLen = BitConverter.GetBytes(sLat.Length); if (BitConverter.IsLittleEndian) { Array.Reverse(dataLen); } byte[] data = sLat; var serviceError = service.service_send(serviceClientHandle, dataLen, (uint)dataLen.Length, ref num2); if (serviceError != ServiceError.Success) { Console.WriteLine("send len:" + serviceError); return(serviceError); } serviceError = service.service_send(serviceClientHandle, data, (uint)data.Length, ref num2); if (serviceError != ServiceError.Success) { Console.WriteLine("send data:" + serviceError); return(serviceError); } return(serviceError); }
private static void Restore(ServiceClientHandle serviceClientHandle) { //还原 Console.WriteLine("Restore"); if (SendCmd(serviceClientHandle, 1) != ServiceError.Success) { Console.WriteLine("Restore failed"); return; } Console.WriteLine("Restore success"); }
private static ServiceError SendCmd(ServiceClientHandle serviceClientHandle, uint cmd) { var service = iMobileDevice.LibiMobileDevice.Instance.Service; byte[] bytes = BitConverter.GetBytes(cmd); if (BitConverter.IsLittleEndian) { Array.Reverse(bytes); } uint num = 0; Console.WriteLine("SendCmd: " + cmd); var serviceError = service.service_send(serviceClientHandle, bytes, (uint)bytes.Length, ref num); if (serviceError != ServiceError.Success) { Console.WriteLine("SendCmd: " + serviceError.ToString()); return(serviceError); } return(serviceError); }
private static void SendLocation(ServiceClientHandle serviceClientHandle, string lat, string lon) { Console.WriteLine($"SendLocation {lat},{lon}"); var serviceError = SendCmd(serviceClientHandle, 0); if (serviceError != ServiceError.Success) { return; } serviceError = SendString(serviceClientHandle, lon); if (serviceError != ServiceError.Success) { return; } serviceError = SendString(serviceClientHandle, lat); if (serviceError != ServiceError.Success) { Console.WriteLine("SendLocation failed"); return; } Console.WriteLine("SendLocation success"); }
private static void SetLocation(DeviceInformation deviceInfo, PointLatLng?target) { iDeviceHandle deviceHandle = null; LockdownClientHandle lockdownHandle = null; LockdownServiceDescriptorHandle simulateDescriptor = null; ServiceClientHandle serviceClientHandle = null; var idevice = LibiMobileDevice.Instance.iDevice; var lockdown = LibiMobileDevice.Instance.Lockdown; var service = LibiMobileDevice.Instance.Service; try { // Get device handle var err = idevice.idevice_new(out deviceHandle, deviceInfo.UDID); if (err != iDeviceError.Success) { throw new Exception("Unable to connect to the device. Make sure it is connected."); } // Obtain a lockdown client handle if (lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "iFakeLocation") != LockdownError.Success) { throw new Exception("Unable to connect to lockdownd."); } // Start the simulatelocation service if (lockdown.lockdownd_start_service(lockdownHandle, "com.apple.dt.simulatelocation", out simulateDescriptor) != LockdownError.Success || simulateDescriptor.IsInvalid) { throw new Exception("Unable to start simulatelocation service."); } // Create new service client if (service.service_client_new(deviceHandle, simulateDescriptor, out serviceClientHandle) != ServiceError.Success) { throw new Exception("Unable to create simulatelocation service client."); } if (!target.HasValue) { // Send stop var stopMessage = ToBytesBE(1); // 0x1 (32-bit big-endian uint) uint sent = 0; if (service.service_send(serviceClientHandle, stopMessage, (uint)stopMessage.Length, ref sent) != ServiceError.Success) { throw new Exception("Unable to send stop message to device."); } } else { // Send start var startMessage = ToBytesBE(0); // 0x0 (32-bit big-endian uint) var lat = Encoding.ASCII.GetBytes(target.Value.Lat.ToString(CultureInfo.InvariantCulture)); var lng = Encoding.ASCII.GetBytes(target.Value.Lng.ToString(CultureInfo.InvariantCulture)); var latLen = ToBytesBE(lat.Length); var lngLen = ToBytesBE(lng.Length); uint sent = 0; if (service.service_send(serviceClientHandle, startMessage, (uint)startMessage.Length, ref sent) != ServiceError.Success || service.service_send(serviceClientHandle, latLen, (uint)latLen.Length, ref sent) != ServiceError.Success || service.service_send(serviceClientHandle, lat, (uint)lat.Length, ref sent) != ServiceError.Success || service.service_send(serviceClientHandle, lngLen, (uint)lngLen.Length, ref sent) != ServiceError.Success || service.service_send(serviceClientHandle, lng, (uint)lng.Length, ref sent) != ServiceError.Success) { throw new Exception("Unable to send co-ordinates to device."); } } } finally { // Cleanup if (serviceClientHandle != null) { serviceClientHandle.Close(); } if (simulateDescriptor != null) { simulateDescriptor.Close(); } if (lockdownHandle != null) { lockdownHandle.Close(); } if (deviceHandle != null) { deviceHandle.Close(); } } }
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(); } } }