/// <summary> /// Connects to the file_relay service on the specified device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Reference that will point to a newly allocated /// file_relay_client_t upon successful return. /// </param> /// <returns> /// FILE_RELAY_E_SUCCESS on success, /// FILE_RELAY_E_INVALID_ARG when one of the parameters is invalid, /// or FILE_RELAY_E_MUX_ERROR when the connection failed. /// </returns> public virtual FileRelayError file_relay_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out FileRelayClientHandle client) { FileRelayError returnValue; returnValue = FileRelayNativeMethods.file_relay_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Connects to the mobilesync service on the specified device. /// MOBILESYNC_E_SUCCESS on success /// MOBILESYNC_E_INVALID_ARG if one or more parameters are invalid /// DEVICE_LINK_SERVICE_E_BAD_VERSION if the mobilesync version on /// the device is newer. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will be set to a newly allocated /// #mobilesync_client_t upon successful return. /// </param> public virtual MobileSyncError mobilesync_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out MobileSyncClientHandle client) { MobileSyncError returnValue; returnValue = MobileSyncNativeMethods.mobilesync_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Connects to the debugserver service on the specified device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will point to a newly allocated /// debugserver_client_t upon successful return. Must be freed using /// debugserver_client_free() after use. /// </param> /// <returns> /// DEBUGSERVER_E_SUCCESS on success, DEBUGSERVER_E_INVALID_ARG when /// client is NULL, or an DEBUGSERVER_E_* error code otherwise. /// </returns> public virtual DebugServerError debugserver_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out DebugServerClientHandle client) { DebugServerError returnValue; returnValue = DebugServerNativeMethods.debugserver_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Connects to the notification_proxy on the specified device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will be set to a newly allocated np_client_t /// upon successful return. /// </param> /// <returns> /// NP_E_SUCCESS on success, NP_E_INVALID_ARG when device is NULL, /// or NP_E_CONN_FAILED when the connection to the device could not be /// established. /// </returns> public virtual NotificationProxyError np_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out NotificationProxyClientHandle client) { NotificationProxyError returnValue; returnValue = NotificationProxyNativeMethods.np_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Connects to the screenshotr service on the specified device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will be set to a newly allocated /// screenshotr_client_t upon successful return. /// </param> /// <returns> /// SCREENSHOTR_E_SUCCESS on success, SCREENSHOTR_E_INVALID ARG if one /// or more parameters are invalid, or SCREENSHOTR_E_CONN_FAILED if the /// connection to the device could not be established. /// </returns> /// <remarks> /// This service is only available if a developer disk image has been /// mounted. /// </remarks> public virtual ScreenshotrError screenshotr_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out ScreenshotrClientHandle client) { ScreenshotrError returnValue; returnValue = ScreenshotrNativeMethods.screenshotr_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Connects to the preboard service on the specified device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will point to a newly allocated /// preboard_client_t upon successful return. Must be freed using /// preboard_client_free() after use. /// </param> /// <returns> /// PREBOARD_E_SUCCESS on success, PREBOARD_E_INVALID_ARG when /// client is NULL, or an PREBOARD_E_* error code otherwise. /// </returns> public virtual PreboardError preboard_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out PreboardClientHandle client) { PreboardError returnValue; returnValue = PreboardNativeMethods.preboard_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Makes a connection to the AFC service on the device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will be set to a newly allocated afc_client_t /// upon successful return. /// </param> /// <returns> /// AFC_E_SUCCESS on success, AFC_E_INVALID_ARG if device or service is /// invalid, AFC_E_MUX_ERROR if the connection cannot be established, /// or AFC_E_NO_MEM if there is a memory allocation problem. /// </returns> public virtual AfcError afc_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out AfcClientHandle client) { AfcError returnValue; returnValue = AfcNativeMethods.afc_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Connects to the misagent service on the specified device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will point to a newly allocated /// misagent_client_t upon successful return. /// </param> /// <returns> /// MISAGENT_E_SUCCESS on success, MISAGENT_E_INVALID_ARG when /// client is NULL, or an MISAGENT_E_* error code otherwise. /// </returns> public virtual MisagentError misagent_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out MisagentClientHandle client) { MisagentError returnValue; returnValue = MisagentNativeMethods.misagent_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Connects to the heartbeat service on the specified device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will point to a newly allocated /// heartbeat_client_t upon successful return. Must be freed using /// heartbeat_client_free() after use. /// </param> /// <returns> /// HEARTBEAT_E_SUCCESS on success, HEARTBEAT_E_INVALID_ARG when /// client is NULL, or an HEARTBEAT_E_* error code otherwise. /// </returns> public virtual HeartBeatError heartbeat_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out HeartBeatClientHandle client) { HeartBeatError returnValue; returnValue = HeartBeatNativeMethods.heartbeat_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Creates a new service for the specified service descriptor. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will be set to a newly allocated /// service_client_t upon successful return. /// </param> /// <returns> /// SERVICE_E_SUCCESS on success, /// SERVICE_E_INVALID_ARG when one of the arguments is invalid, /// or SERVICE_E_MUX_ERROR when connecting to the device failed. /// </returns> public virtual ServiceError service_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out ServiceClientHandle client) { ServiceError returnValue; returnValue = ServiceNativeMethods.service_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
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(); } } }
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 deviceHandle = null; LockdownClientHandle lockdownHandle = null; LockdownServiceDescriptorHandle serviceDescriptor = null; MobileImageMounterClientHandle mounterHandle = null; AfcClientHandle afcHandle = null; PlistHandle plistHandle = null; FileStream imageStream = null; // Use upload image for iOS 7 and above, otherwise use AFC DiskImageUploadMode mode = int.Parse(((string)Properties["ProductVersion"]).Split('.')[0]) >= 7 ? DiskImageUploadMode.UploadImage : DiskImageUploadMode.AFC; var idevice = LibiMobileDevice.Instance.iDevice; var lockdown = LibiMobileDevice.Instance.Lockdown; var service = LibiMobileDevice.Instance.Service; var mounter = LibiMobileDevice.Instance.MobileImageMounter; var afc = LibiMobileDevice.Instance.Afc; try { // Get device handle if (idevice.idevice_new(out deviceHandle, UDID) != iDeviceError.Success) { throw new Exception("Unable to open device, is it connected?"); } // Get lockdownd handle if (lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "iFakeLocation") != LockdownError.Success) { throw new Exception("Unable to connect to lockdownd."); } // Start image mounter service if (lockdown.lockdownd_start_service(lockdownHandle, "com.apple.mobile.mobile_image_mounter", out serviceDescriptor) != LockdownError.Success) { throw new Exception("Unable to start the mobile image mounter service."); } // Create mounter instance if (mounter.mobile_image_mounter_new(deviceHandle, serviceDescriptor, out mounterHandle) != MobileImageMounterError.Success) { throw new Exception("Unable to create mobile image mounter instance."); } // Close service descriptor serviceDescriptor.Close(); serviceDescriptor = null; // Start the AFC service if (mode == DiskImageUploadMode.AFC) { if (lockdown.lockdownd_start_service(lockdownHandle, "com.apple.afc", out serviceDescriptor) != LockdownError.Success) { throw new Exception("Unable to start AFC service."); } if (afc.afc_client_new(deviceHandle, serviceDescriptor, out afcHandle) != AfcError.Success) { throw new Exception("Unable to connect to AFC service."); } serviceDescriptor.Close(); serviceDescriptor = null; } // Close lockdown handle lockdownHandle.Close(); lockdownHandle = null; // Check if the developer image has already been mounted const string imageType = "Developer"; if (mounter.mobile_image_mounter_lookup_image(mounterHandle, imageType, out plistHandle) == MobileImageMounterError.Success) { var results = PlistReader.ReadPlistDictFromNode(plistHandle, new[] { "ImagePresent", "ImageSignature" }); // Some iOS use ImagePresent to verify presence, while others use ImageSignature instead // Ensure to check the content of the ImageSignature value as iOS 14 returns a value even // if it is empty. if ((results.ContainsKey("ImagePresent") && results["ImagePresent"] is bool && (bool)results["ImagePresent"]) || (results.ContainsKey("ImageSignature") && results["ImageSignature"] is string && ((string)results["ImageSignature"]).IndexOf("<data>", StringComparison.InvariantCulture) >= 0)) { return; } } plistHandle.Close(); plistHandle = null; // Configure paths for upload const string PkgPath = "PublicStaging"; const string PathPrefix = "/private/var/mobile/Media"; var targetName = PkgPath + "/staging.dimage"; var mountName = PathPrefix + "/" + targetName; imageStream = new FileStream(deviceImagePath, FileMode.Open, FileAccess.Read, FileShare.Read); var sig = File.ReadAllBytes(deviceImageSignaturePath); switch (mode) { case DiskImageUploadMode.UploadImage: // Create stream for device image and wrap as a pointer for callback var handle = GCHandle.Alloc(imageStream); // Upload the image and then free unmanaged wrapper mounter.mobile_image_mounter_upload_image(mounterHandle, imageType, (uint)imageStream.Length, sig, (ushort)sig.Length, MounterUploadCallback, GCHandle.ToIntPtr(handle)); handle.Free(); break; case DiskImageUploadMode.AFC: // Create directory for package ReadOnlyCollection <string> strs; if (afc.afc_get_file_info(afcHandle, PkgPath, out strs) != AfcError.Success || afc.afc_make_directory(afcHandle, PkgPath) != AfcError.Success) { throw new Exception("Unable to create directory '" + PkgPath + "' on the device."); } // Create the target file ulong af = 0; if (afc.afc_file_open(afcHandle, targetName, AfcFileMode.FopenWronly, ref af) != AfcError.Success) { throw new Exception("Unable to create file '" + targetName + "'."); } // Read the file in chunks and write via AFC uint amount = 0; byte[] buf = new byte[8192]; do { amount = (uint)imageStream.Read(buf, 0, buf.Length); if (amount > 0) { uint written = 0, total = 0; while (total < amount) { // Write and ensure that it succeeded if (afc.afc_file_write(afcHandle, af, buf, amount, ref written) != AfcError.Success) { afc.afc_file_close(afcHandle, af); throw new Exception("An AFC write error occurred."); } total += written; } if (total != amount) { afc.afc_file_close(afcHandle, af); throw new Exception("The developer image was not written completely."); } } } while (amount > 0); afc.afc_file_close(afcHandle, af); break; } // Mount the image if (mounter.mobile_image_mounter_mount_image(mounterHandle, mountName, sig, (ushort)sig.Length, imageType, out plistHandle) != MobileImageMounterError.Success) { throw new Exception("Unable to mount developer image."); } // Parse the plist result var result = PlistReader.ReadPlistDictFromNode(plistHandle); if (!result.ContainsKey("Status") || result["Status"] as string != "Complete") { throw new Exception("Mount failed with status: " + (result.ContainsKey("Status") ? result["Status"] : "N/A") + " and error: " + (result.ContainsKey("Error") ? result["Error"] : "N/A")); } } finally { if (imageStream != null) { imageStream.Close(); } if (plistHandle != null) { plistHandle.Close(); } if (afcHandle != null) { afcHandle.Close(); } if (mounterHandle != null) { mounterHandle.Close(); } if (serviceDescriptor != null) { serviceDescriptor.Close(); } if (lockdownHandle != null) { lockdownHandle.Close(); } if (deviceHandle != null) { deviceHandle.Close(); } } }
/// <summary> /// Connects to the installation_proxy service on the specified device. /// </summary> /// <param name="device"> /// The device to connect to /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will be set to a newly allocated /// instproxy_client_t upon successful return. /// </param> /// <returns> /// INSTPROXY_E_SUCCESS on success, or an INSTPROXY_E_* error value /// when an error occured. /// </returns> public virtual InstallationProxyError instproxy_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out InstallationProxyClientHandle client) { InstallationProxyError returnValue; returnValue = InstallationProxyNativeMethods.instproxy_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
/// <summary> /// Connects to the syslog_relay service on the specified device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will point to a newly allocated /// syslog_relay_client_t upon successful return. Must be freed using /// syslog_relay_client_free() after use. /// </param> /// <returns> /// SYSLOG_RELAY_E_SUCCESS on success, SYSLOG_RELAY_E_INVALID_ARG when /// client is NULL, or an SYSLOG_RELAY_E_* error code otherwise. /// </returns> public virtual SyslogRelayError syslog_relay_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out SyslogRelayClientHandle client) { SyslogRelayError returnValue; returnValue = SyslogRelayNativeMethods.syslog_relay_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
public static extern DiagnosticsRelayError diagnostics_relay_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out DiagnosticsRelayClientHandle client);
public static extern InstallationProxyError instproxy_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out InstallationProxyClientHandle client);
public static extern DebugServerError debugserver_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out DebugServerClientHandle client);
public static extern PropertyListServiceError property_list_service_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out PropertyListServiceClientHandle client);
public static extern MobileBackup2Error mobilebackup2_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out MobileBackup2ClientHandle client);
public static extern WebInspectorError webinspector_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out WebInspectorClientHandle client);
/// <summary> /// Creates a new property list service for the specified port. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will be set to a newly allocated /// property_list_service_client_t upon successful return. /// </param> /// <returns> /// PROPERTY_LIST_SERVICE_E_SUCCESS on success, /// PROPERTY_LIST_SERVICE_E_INVALID_ARG when one of the arguments is invalid, /// or PROPERTY_LIST_SERVICE_E_MUX_ERROR when connecting to the device failed. /// </returns> public virtual PropertyListServiceError property_list_service_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out PropertyListServiceClientHandle client) { PropertyListServiceError returnValue; returnValue = PropertyListServiceNativeMethods.property_list_service_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
public static extern MobileactivationError mobileactivation_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out MobileactivationClientHandle client);
public static extern NotificationProxyError np_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out NotificationProxyClientHandle client);
public static extern MobileSyncError mobilesync_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out MobileSyncClientHandle client);
/// <summary> /// Connects to the house_arrest service on the specified device. /// </summary> /// <param name="device"> /// The device to connect to. /// </param> /// <param name="service"> /// The service descriptor returned by lockdownd_start_service. /// </param> /// <param name="client"> /// Pointer that will point to a newly allocated /// housearrest_client_t upon successful return. /// </param> /// <returns> /// HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when /// client is NULL, or an HOUSE_ARREST_E_* error code otherwise. /// </returns> public virtual HouseArrestError house_arrest_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out HouseArrestClientHandle client) { HouseArrestError returnValue; returnValue = HouseArrestNativeMethods.house_arrest_client_new(device, service, out client); client.Api = this.Parent; return(returnValue); }
public static extern SpringBoardServicesError sbservices_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out SpringBoardServicesClientHandle client);
public static extern HouseArrestError house_arrest_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out HouseArrestClientHandle client);
public static extern SyslogRelayError syslog_relay_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out SyslogRelayClientHandle client);
public static extern MobileImageMounterError mobile_image_mounter_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out MobileImageMounterClientHandle client);
public static extern HeartBeatError heartbeat_client_new(iDeviceHandle device, LockdownServiceDescriptorHandle service, out HeartBeatClientHandle client);