diff options
48 files changed, 373 insertions, 187 deletions
| diff --git a/dev/afccheck.c b/dev/afccheck.c index 2dab6db..ead0ca0 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[])  {  	lockdownd_client_t client = NULL;  	idevice_t phone = NULL; -	uint16_t port = 0; +	lockdownd_service_descriptor_t service = NULL;  	afc_client_t afc = NULL;  	if (argc > 1 && !strcasecmp(argv[1], "--debug")) { @@ -111,14 +111,19 @@ int main(int argc, char *argv[])  		return 1;  	} -	if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &port) && !port) { +	if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &service) && !service->port) {  		lockdownd_client_free(client);  		idevice_free(phone);  		fprintf(stderr, "Something went wrong when starting AFC.");  		return 1;  	} -	afc_client_new(phone, port, &afc); +	afc_client_new(phone, service, &afc); + +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	}  	pthread_t threads[NB_THREADS];  	param data[NB_THREADS]; diff --git a/dev/filerelaytest.c b/dev/filerelaytest.c index 8c9514b..9094130 100644 --- a/dev/filerelaytest.c +++ b/dev/filerelaytest.c @@ -27,6 +27,7 @@ int main(int argc, char **argv)  {  	idevice_t dev = NULL;  	lockdownd_client_t client = NULL; +	lockdownd_service_descriptor_t service = NULL;  	file_relay_client_t frc = NULL;  	if (idevice_new(&dev, NULL) != IDEVICE_E_SUCCESS) { @@ -40,8 +41,7 @@ int main(int argc, char **argv)  		goto leave_cleanup;  	} -	uint16_t port = 0; -	if (lockdownd_start_service(client, "com.apple.mobile.file_relay", &port) != LOCKDOWN_E_SUCCESS) { +	if (lockdownd_start_service(client, "com.apple.mobile.file_relay", &service) != LOCKDOWN_E_SUCCESS) {  		printf("could not start file_relay service!\n");  		goto leave_cleanup;  	} @@ -51,11 +51,16 @@ int main(int argc, char **argv)  		client = NULL;  	} -	if (file_relay_client_new(dev, port, &frc) != FILE_RELAY_E_SUCCESS) { +	if (file_relay_client_new(dev, service, &frc) != FILE_RELAY_E_SUCCESS) {  		printf("could not connect to file_relay service!\n");  		goto leave_cleanup;  	} +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	} +  	idevice_connection_t dump = NULL;  	const char *sources[] = {"AppleSupport", "Network", "VPN", "WiFi", "UserDatabases", "CrashReporter", "tmp", "SystemConfiguration", NULL}; diff --git a/dev/housearresttest.c b/dev/housearresttest.c index 951ebe4..2e24670 100644 --- a/dev/housearresttest.c +++ b/dev/housearresttest.c @@ -96,8 +96,8 @@ int main(int argc, char **argv)  		goto leave_cleanup;  	} -	uint16_t port = 0; -	if (lockdownd_start_service(client, "com.apple.mobile.house_arrest", &port) != LOCKDOWN_E_SUCCESS) { +	lockdownd_service_descriptor_t service = NULL; +	if (lockdownd_start_service(client, "com.apple.mobile.house_arrest", &service) != LOCKDOWN_E_SUCCESS) {  		printf("could not start house_arrest service!\n");  		goto leave_cleanup;  	} @@ -107,11 +107,16 @@ int main(int argc, char **argv)  		client = NULL;  	} -	if (house_arrest_client_new(dev, port, &hac) != HOUSE_ARREST_E_SUCCESS) { +	if (house_arrest_client_new(dev, service, &hac) != HOUSE_ARREST_E_SUCCESS) {  		printf("could not connect to house_arrest service!\n");  		goto leave_cleanup;  	} +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	} +  	res = house_arrest_send_command(hac, "VendDocuments", appid);  	if (res != HOUSE_ARREST_E_SUCCESS) {  		printf("error %d when trying to get VendDocuments\n", res); diff --git a/dev/ideviceclient.c b/dev/ideviceclient.c index d467ee8..c8635d8 100644 --- a/dev/ideviceclient.c +++ b/dev/ideviceclient.c @@ -45,13 +45,13 @@ static void notifier(const char *notification, void *userdata)  static void perform_notification(idevice_t phone, lockdownd_client_t client, const char *notification)  { -	uint16_t nport = 0; +	lockdownd_service_descriptor_t service = NULL;  	np_client_t np; -	lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); -	if (nport) { +	lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service); +	if (service->port) {  		printf("::::::::::::::: np was started ::::::::::::\n"); -		np_client_new(phone, nport, &np); +		np_client_new(phone, service, &np);  		if (np) {  			printf("::::::::: PostNotification %s\n", notification);  			np_post_notification(np, notification); @@ -60,13 +60,18 @@ static void perform_notification(idevice_t phone, lockdownd_client_t client, con  	} else {  		printf("::::::::::::::: np was NOT started ::::::::::::\n");  	} + +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	}  }  int main(int argc, char *argv[])  {  	unsigned int bytes = 0; -	uint16_t port = 0, i = 0; -	uint16_t npp; +	uint16_t i = 0; +	lockdownd_service_descriptor_t service = NULL;  	lockdownd_client_t client = NULL;  	idevice_t phone = NULL;  	uint64_t lockfile = 0; @@ -102,19 +107,33 @@ int main(int argc, char *argv[])  		free(nnn);  	} -	lockdownd_start_service(client, "com.apple.afc", &port); +	lockdownd_start_service(client, "com.apple.afc", &service); -	if (port) { +	if (service->port) {  		afc_client_t afc = NULL; -		afc_client_new(phone, port, &afc); +		afc_client_new(phone, service, &afc); + +		if (service) { +			lockdownd_service_descriptor_free(service); +			service = NULL; +		} +  		if (afc) { -			lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); -			if (npp) { +			service->port = 0; +			service->ssl_enabled = 0; +			lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service); +			if (service->port) {  				printf("Notification Proxy started.\n"); -				np_client_new(phone, npp, &gnp); +				np_client_new(phone, service, &gnp);  			} else {  				printf("ERROR: Notification proxy could not be started.\n");  			} + +			if (service) { +				lockdownd_service_descriptor_free(service); +				service = NULL; +			} +  			if (gnp) {  				const char *nspec[5] = {  					NP_SYNC_CANCEL_REQUEST, diff --git a/dev/lckdclient.c b/dev/lckdclient.c index cc89634..b9be4de 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -136,9 +136,13 @@ int main(int argc, char *argv[])  				}  				if (!strcmp(*args, "start") && len == 2) { -					uint16_t port = 0; -					if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &port)) { -						printf("started service %s on port %i\n", *(args + 1), port); +					lockdownd_service_descriptor_t service = NULL; +					if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &service)) { +						printf("started service %s on port %i\n", *(args + 1), service->port); +						if (service) { +							lockdownd_service_descriptor_free(service); +							service = NULL; +						}  					}  					else  					{ diff --git a/include/libimobiledevice/afc.h b/include/libimobiledevice/afc.h index 8d47696..1b4ad5b 100644 --- a/include/libimobiledevice/afc.h +++ b/include/libimobiledevice/afc.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -93,7 +94,7 @@ typedef afc_client_private *afc_client_t; /**< The client handle. */  /* Interface */  afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_client_t *client); -afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t *client); +afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t *client);  afc_error_t afc_client_free(afc_client_t client);  afc_error_t afc_get_device_info(afc_client_t client, char ***infos);  afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list); diff --git a/include/libimobiledevice/diagnostics_relay.h b/include/libimobiledevice/diagnostics_relay.h index bdb3f36..ec87732 100644 --- a/include/libimobiledevice/diagnostics_relay.h +++ b/include/libimobiledevice/diagnostics_relay.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -55,7 +56,7 @@ typedef int16_t diagnostics_relay_error_t;  typedef struct diagnostics_relay_client_private diagnostics_relay_client_private;  typedef diagnostics_relay_client_private *diagnostics_relay_client_t; /**< The client handle. */ -diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, uint16_t port, diagnostics_relay_client_t *client); +diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, diagnostics_relay_client_t *client);  diagnostics_relay_error_t diagnostics_relay_client_free(diagnostics_relay_client_t client);  diagnostics_relay_error_t diagnostics_relay_goodbye(diagnostics_relay_client_t client); diff --git a/include/libimobiledevice/file_relay.h b/include/libimobiledevice/file_relay.h index 52d4758..85f9213 100644 --- a/include/libimobiledevice/file_relay.h +++ b/include/libimobiledevice/file_relay.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -47,7 +48,7 @@ typedef int16_t file_relay_error_t;  typedef struct file_relay_client_private file_relay_client_private;  typedef file_relay_client_private *file_relay_client_t; /**< The client handle. */ -file_relay_error_t file_relay_client_new(idevice_t device, uint16_t port, file_relay_client_t *client); +file_relay_error_t file_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, file_relay_client_t *client);  file_relay_error_t file_relay_client_free(file_relay_client_t client);  file_relay_error_t file_relay_request_sources(file_relay_client_t client, const char **sources, idevice_connection_t *connection); diff --git a/include/libimobiledevice/house_arrest.h b/include/libimobiledevice/house_arrest.h index 04290f1..ee03072 100644 --- a/include/libimobiledevice/house_arrest.h +++ b/include/libimobiledevice/house_arrest.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  #include <libimobiledevice/afc.h>  /** @name Error Codes */ @@ -48,7 +49,7 @@ typedef struct house_arrest_client_private house_arrest_client_private;  typedef house_arrest_client_private *house_arrest_client_t; /**< The client handle. */  /* Interface */ -house_arrest_error_t house_arrest_client_new(idevice_t device, uint16_t port, house_arrest_client_t *client); +house_arrest_error_t house_arrest_client_new(idevice_t device, lockdownd_service_descriptor_t service, house_arrest_client_t *client);  house_arrest_error_t house_arrest_client_free(house_arrest_client_t client);  house_arrest_error_t house_arrest_send_request(house_arrest_client_t client, plist_t dict); diff --git a/include/libimobiledevice/installation_proxy.h b/include/libimobiledevice/installation_proxy.h index 11fb66e..6a20c0b 100644 --- a/include/libimobiledevice/installation_proxy.h +++ b/include/libimobiledevice/installation_proxy.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -51,7 +52,7 @@ typedef instproxy_client_private *instproxy_client_t; /**< The client handle. */  typedef void (*instproxy_status_cb_t) (const char *operation, plist_t status, void *user_data);  /* Interface */ -instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client); +instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, instproxy_client_t *client);  instproxy_error_t instproxy_client_free(instproxy_client_t client);  instproxy_error_t instproxy_browse(instproxy_client_t client, plist_t client_options, plist_t *result); diff --git a/include/libimobiledevice/lockdown.h b/include/libimobiledevice/lockdown.h index 4e7a4e8..287d3f6 100644 --- a/include/libimobiledevice/lockdown.h +++ b/include/libimobiledevice/lockdown.h @@ -29,6 +29,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -70,6 +71,12 @@ struct lockdownd_pair_record {  /** A pair record holding device, host and root certificates along the host_id */  typedef struct lockdownd_pair_record *lockdownd_pair_record_t; +struct lockdownd_service_descriptor { +	uint16_t port; +	uint8_t ssl_enabled; +}; +typedef struct lockdownd_service_descriptor *lockdownd_service_descriptor_t; +  /* Interface */  lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label);  lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label); @@ -79,7 +86,7 @@ lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type);  lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value);  lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value);  lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); -lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port); +lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service);  lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled);  lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id);  lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist); @@ -98,6 +105,7 @@ lockdownd_error_t lockdownd_get_device_udid(lockdownd_client_t control, char **u  lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name);  lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count);  lockdownd_error_t lockdownd_data_classes_free(char **classes); +lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service);  #ifdef __cplusplus  } diff --git a/include/libimobiledevice/misagent.h b/include/libimobiledevice/misagent.h index 7aa609b..3adfd9d 100644 --- a/include/libimobiledevice/misagent.h +++ b/include/libimobiledevice/misagent.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -47,7 +48,7 @@ typedef struct misagent_client_private misagent_client_private;  typedef misagent_client_private *misagent_client_t; /**< The client handle. */  /* Interface */ -misagent_error_t misagent_client_new(idevice_t device, uint16_t port, misagent_client_t *client); +misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client);  misagent_error_t misagent_client_free(misagent_client_t client);  misagent_error_t misagent_install(misagent_client_t client, plist_t profile); diff --git a/include/libimobiledevice/mobile_image_mounter.h b/include/libimobiledevice/mobile_image_mounter.h index 04c65d5..a9f500d 100644 --- a/include/libimobiledevice/mobile_image_mounter.h +++ b/include/libimobiledevice/mobile_image_mounter.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -46,7 +47,7 @@ typedef struct mobile_image_mounter_client_private mobile_image_mounter_client_p  typedef mobile_image_mounter_client_private *mobile_image_mounter_client_t; /**< The client handle. */  /* Interface */ -mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t port, mobile_image_mounter_client_t *client); +mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t service, mobile_image_mounter_client_t *client);  mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client);  mobile_image_mounter_error_t mobile_image_mounter_lookup_image(mobile_image_mounter_client_t client, const char *image_type, plist_t *result);  mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, const char *image_path, const char *image_signature, uint16_t signature_length, const char *image_type, plist_t *result); diff --git a/include/libimobiledevice/mobilebackup.h b/include/libimobiledevice/mobilebackup.h index 8f31cc4..358103d 100644 --- a/include/libimobiledevice/mobilebackup.h +++ b/include/libimobiledevice/mobilebackup.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -53,7 +54,7 @@ typedef enum {  	MB_RESTORE_PRESERVE_CAMERA_ROLL = 1 << 2  } mobilebackup_flags_t; -mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, mobilebackup_client_t * client); +mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup_client_t * client);  mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client);  mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t *plist);  mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist); diff --git a/include/libimobiledevice/mobilebackup2.h b/include/libimobiledevice/mobilebackup2.h index 6557f42..215c339 100644 --- a/include/libimobiledevice/mobilebackup2.h +++ b/include/libimobiledevice/mobilebackup2.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -48,7 +49,7 @@ typedef int16_t mobilebackup2_error_t;  typedef struct mobilebackup2_client_private mobilebackup2_client_private;  typedef mobilebackup2_client_private *mobilebackup2_client_t; /**< The client handle. */ -mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, uint16_t port, mobilebackup2_client_t * client); +mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup2_client_t * client);  mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client);  mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, const char *message, plist_t options);  mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage); diff --git a/include/libimobiledevice/mobilesync.h b/include/libimobiledevice/mobilesync.h index cfab8d9..ef1f4df 100644 --- a/include/libimobiledevice/mobilesync.h +++ b/include/libimobiledevice/mobilesync.h @@ -29,6 +29,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -65,7 +66,7 @@ typedef struct {  typedef mobilesync_anchors *mobilesync_anchors_t; /**< Anchors used by the device and computer. */  /* Interface */ -mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client); +mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilesync_client_t * client);  mobilesync_error_t mobilesync_client_free(mobilesync_client_t client);  mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t *plist); diff --git a/include/libimobiledevice/notification_proxy.h b/include/libimobiledevice/notification_proxy.h index 43c479d..3f883e5 100644 --- a/include/libimobiledevice/notification_proxy.h +++ b/include/libimobiledevice/notification_proxy.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -90,7 +91,7 @@ typedef np_client_private *np_client_t; /**< The client handle. */  typedef void (*np_notify_cb_t) (const char *notification, void *user_data);  /* Interface */ -np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client); +np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client);  np_error_t np_client_free(np_client_t client);  np_error_t np_post_notification(np_client_t client, const char *notification);  np_error_t np_observe_notification(np_client_t client, const char *notification); diff --git a/include/libimobiledevice/sbservices.h b/include/libimobiledevice/sbservices.h index 08cb740..55d8b93 100644 --- a/include/libimobiledevice/sbservices.h +++ b/include/libimobiledevice/sbservices.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -57,7 +58,7 @@ typedef struct sbservices_client_private sbservices_client_private;  typedef sbservices_client_private *sbservices_client_t; /**< The client handle. */  /* Interface */ -sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client); +sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t service, sbservices_client_t *client);  sbservices_error_t sbservices_client_free(sbservices_client_t client);  sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t *state, const char *format_version);  sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist_t newstate); diff --git a/include/libimobiledevice/screenshotr.h b/include/libimobiledevice/screenshotr.h index b3669ee..b9497d0 100644 --- a/include/libimobiledevice/screenshotr.h +++ b/include/libimobiledevice/screenshotr.h @@ -29,6 +29,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  /** @name Error Codes */  /*@{*/ @@ -47,7 +48,7 @@ typedef int16_t screenshotr_error_t;  typedef struct screenshotr_client_private screenshotr_client_private;  typedef screenshotr_client_private *screenshotr_client_t; /**< The client handle. */ -screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, screenshotr_client_t * client); +screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service, screenshotr_client_t * client);  screenshotr_error_t screenshotr_client_free(screenshotr_client_t client);  screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize); diff --git a/include/libimobiledevice/webinspector.h b/include/libimobiledevice/webinspector.h index d499d72..ed9faad 100644 --- a/include/libimobiledevice/webinspector.h +++ b/include/libimobiledevice/webinspector.h @@ -28,6 +28,7 @@ extern "C" {  #endif  #include <libimobiledevice/libimobiledevice.h> +#include <libimobiledevice/lockdown.h>  #define WEBINSPECTOR_SERVICE_NAME "com.apple.webinspector" @@ -47,7 +48,7 @@ typedef int16_t webinspector_error_t;  typedef struct webinspector_client_private webinspector_client_private;  typedef webinspector_client_private *webinspector_client_t; /**< The client handle. */ -webinspector_error_t webinspector_client_new(idevice_t device, uint16_t port, webinspector_client_t * client); +webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t service, webinspector_client_t * client);  webinspector_error_t webinspector_client_free(webinspector_client_t client);  webinspector_error_t webinspector_start_service(idevice_t device, webinspector_client_t * client); @@ -119,7 +119,7 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_   * @see afc_client_new_from_connection   *    * @param device The device to connect to. - * @param port The destination port. + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will be set to a newly allocated afc_client_t   *     upon successful return.   *  @@ -127,17 +127,21 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_   *  invalid, AFC_E_MUX_ERROR if the connection cannot be established,   *  or AFC_E_NO_MEM if there is a memory allocation problem.   */ -afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t * client) +afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t * client)  { -	if (!device || port==0) +	if (!device || service->port == 0)  		return AFC_E_INVALID_ARG;  	/* attempt connection */  	idevice_connection_t connection = NULL; -	if (idevice_connect(device, port, &connection) != IDEVICE_E_SUCCESS) { +	if (idevice_connect(device, service->port, &connection) != IDEVICE_E_SUCCESS) {  		return AFC_E_MUX_ERROR;  	} +	/* enable SSL if requested */ +	if (service->ssl_enabled) +		idevice_connection_enable_ssl(connection); +  	afc_error_t err = afc_client_new_from_connection(connection, client);  	if (err != AFC_E_SUCCESS) {  		idevice_disconnect(connection); diff --git a/src/device_link_service.c b/src/device_link_service.c index 5825f0c..ac89211 100644 --- a/src/device_link_service.c +++ b/src/device_link_service.c @@ -74,7 +74,7 @@ static int device_link_service_get_message(plist_t dl_msg, char **message)   * Creates a new device link service client.   *   * @param device The device to connect to. - * @param port Port on device to connect to. + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Reference that will point to a newly allocated   *     device_link_service_client_t upon successful return.   * @@ -82,14 +82,14 @@ static int device_link_service_get_message(plist_t dl_msg, char **message)   *     DEVICE_LINK_SERVICE_E_INVALID_ARG when one of the parameters is invalid,   *     or DEVICE_LINK_SERVICE_E_MUX_ERROR when the connection failed.   */ -device_link_service_error_t device_link_service_client_new(idevice_t device, uint16_t port, device_link_service_client_t *client) +device_link_service_error_t device_link_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, device_link_service_client_t *client)  { -	if (!device || port == 0 || !client || *client) { +	if (!device || service->port == 0 || !client || *client) {  		return DEVICE_LINK_SERVICE_E_INVALID_ARG;  	}  	property_list_service_client_t plistclient = NULL; -	if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { +	if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {  		return DEVICE_LINK_SERVICE_E_MUX_ERROR;  	} @@ -97,6 +97,10 @@ device_link_service_error_t device_link_service_client_new(idevice_t device, uin  	device_link_service_client_t client_loc = (device_link_service_client_t) malloc(sizeof(struct device_link_service_client_private));  	client_loc->parent = plistclient; +	/* enable SSL if requested */ +	if (service->ssl_enabled) +		property_list_service_enable_ssl(client_loc->parent); +  	/* all done, return success */  	*client = client_loc;  	return DEVICE_LINK_SERVICE_E_SUCCESS; diff --git a/src/device_link_service.h b/src/device_link_service.h index 8589428..d625341 100644 --- a/src/device_link_service.h +++ b/src/device_link_service.h @@ -41,7 +41,7 @@ struct device_link_service_client_private {  typedef struct device_link_service_client_private *device_link_service_client_t; -device_link_service_error_t device_link_service_client_new(idevice_t device, uint16_t port, device_link_service_client_t *client); +device_link_service_error_t device_link_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, device_link_service_client_t *client);  device_link_service_error_t device_link_service_client_free(device_link_service_client_t client);  device_link_service_error_t device_link_service_version_exchange(device_link_service_client_t client, uint64_t version_major, uint64_t version_minor);  device_link_service_error_t device_link_service_send_ping(device_link_service_client_t client, const char *message); diff --git a/src/diagnostics_relay.c b/src/diagnostics_relay.c index 7178952..3469ae4 100644 --- a/src/diagnostics_relay.c +++ b/src/diagnostics_relay.c @@ -73,7 +73,7 @@ static int diagnostics_relay_check_result(plist_t dict)   * Connects to the diagnostics_relay service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Reference that will point to a newly allocated   *     diagnostics_relay_client_t upon successful return.   * @@ -81,14 +81,14 @@ static int diagnostics_relay_check_result(plist_t dict)   *     DIAGNOSTICS_RELAY_E_INVALID_ARG when one of the parameters is invalid,   *     or DIAGNOSTICS_RELAY_E_MUX_ERROR when the connection failed.   */ -diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, uint16_t port, diagnostics_relay_client_t *client) +diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, diagnostics_relay_client_t *client)  { -	if (!device || port == 0 || !client || *client) { +	if (!device || service->port == 0 || !client || *client) {  		return DIAGNOSTICS_RELAY_E_INVALID_ARG;  	}  	property_list_service_client_t plistclient = NULL; -	if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { +	if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {  		return DIAGNOSTICS_RELAY_E_MUX_ERROR;  	} diff --git a/src/file_relay.c b/src/file_relay.c index 680e28d..e72be66 100644 --- a/src/file_relay.c +++ b/src/file_relay.c @@ -28,7 +28,7 @@   * Connects to the file_relay service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Reference that will point to a newly allocated   *     file_relay_client_t upon successful return.   * @@ -36,14 +36,14 @@   *     FILE_RELAY_E_INVALID_ARG when one of the parameters is invalid,   *     or FILE_RELAY_E_MUX_ERROR when the connection failed.   */ -file_relay_error_t file_relay_client_new(idevice_t device, uint16_t port, file_relay_client_t *client) +file_relay_error_t file_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, file_relay_client_t *client)  { -	if (!device || port == 0 || !client || *client) { +	if (!device || service->port == 0 || !client || *client) {  		return FILE_RELAY_E_INVALID_ARG;  	}  	property_list_service_client_t plistclient = NULL; -	if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { +	if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {  		return FILE_RELAY_E_MUX_ERROR;  	} diff --git a/src/house_arrest.c b/src/house_arrest.c index 5baa76e..e0d7771 100644 --- a/src/house_arrest.c +++ b/src/house_arrest.c @@ -59,20 +59,20 @@ static house_arrest_error_t house_arrest_error(property_list_service_error_t err   * Connects to the house_arrest service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will point to a newly allocated   *     housearrest_client_t upon successful return.   *   * @return HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when   *     client is NULL, or an HOUSE_ARREST_E_* error code otherwise.   */ -house_arrest_error_t house_arrest_client_new(idevice_t device, uint16_t port, house_arrest_client_t *client) +house_arrest_error_t house_arrest_client_new(idevice_t device, lockdownd_service_descriptor_t service, house_arrest_client_t *client)  {  	if (!device)  		return HOUSE_ARREST_E_INVALID_ARG;  	property_list_service_client_t plistclient = NULL; -	house_arrest_error_t err = house_arrest_error(property_list_service_client_new(device, port, &plistclient)); +	house_arrest_error_t err = house_arrest_error(property_list_service_client_new(device, service, &plistclient));  	if (err != HOUSE_ARREST_E_SUCCESS) {  		return err;  	} diff --git a/src/installation_proxy.c b/src/installation_proxy.c index bab6ab2..eacab9d 100644 --- a/src/installation_proxy.c +++ b/src/installation_proxy.c @@ -95,20 +95,20 @@ static instproxy_error_t instproxy_error(property_list_service_error_t err)   * Connects to the installation_proxy service on the specified device.   *   * @param device The device to connect to - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will be set to a newly allocated   *     instproxy_client_t upon successful return.   *   * @return INSTPROXY_E_SUCCESS on success, or an INSTPROXY_E_* error value   *     when an error occured.   */ -instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client) +instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, instproxy_client_t *client)  {  	if (!device)  		return INSTPROXY_E_INVALID_ARG;  	property_list_service_client_t plistclient = NULL; -	if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { +	if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {  		return INSTPROXY_E_CONN_FAILED;  	} diff --git a/src/lockdown.c b/src/lockdown.c index e899baa..df1f60f 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -646,8 +646,13 @@ lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *cli  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; +	static struct lockdownd_service_descriptor service = { +		.port = 0xf27e, +		.ssl_enabled = 0 +	}; +  	property_list_service_client_t plistclient = NULL; -	if (property_list_service_client_new(device, 0xf27e, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { +	if (property_list_service_client_new(device, (lockdownd_service_descriptor_t)&service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {  		debug_info("could not connect to lockdownd (device %s)", device->udid);  		return LOCKDOWN_E_MUX_ERROR;  	} @@ -1494,17 +1499,17 @@ lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char   * Requests to start a service and retrieve it's port on success.   *   * @param client The lockdownd client - * @param service The name of the service to start - * @param port The port number the service was started on + * @param identifier The identifier of the service to start + * @param descriptor The service descriptor on success or NULL on failure   * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG if a parameter   *  is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known   *  by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not because   *  started by the device   */ -lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port) +lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service)  { -	if (!client || !service || !port) +	if (!client || !identifier || !service)  		return LOCKDOWN_E_INVALID_ARG;  	char *host_id = NULL; @@ -1524,7 +1529,7 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char  	dict = plist_new_dict();  	plist_dict_add_label(dict, client->label);  	plist_dict_insert_item(dict,"Request", plist_new_string("StartService")); -	plist_dict_insert_item(dict,"Service", plist_new_string(service)); +	plist_dict_insert_item(dict,"Service", plist_new_string(identifier));  	/* send to device */  	ret = lockdownd_send(client, dict); @@ -1542,20 +1547,34 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char  	if (!dict)  		return LOCKDOWN_E_PLIST_ERROR; +	if (*service == NULL) +		*service = (lockdownd_service_descriptor_t)malloc(sizeof(struct lockdownd_service_descriptor)); +	(*service)->port = 0; +	(*service)->ssl_enabled = 0; +  	ret = LOCKDOWN_E_UNKNOWN_ERROR;  	if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { -		plist_t port_value_node = plist_dict_get_item(dict, "Port"); - -		if (port_value_node && (plist_get_node_type(port_value_node) == PLIST_UINT)) { +		/* read service port number */ +		plist_t node = plist_dict_get_item(dict, "Port"); +		if (node && (plist_get_node_type(node) == PLIST_UINT)) {  			uint64_t port_value = 0; -			plist_get_uint_val(port_value_node, &port_value); +			plist_get_uint_val(node, &port_value);  			if (port_value) {  				port_loc = port_value;  				ret = LOCKDOWN_E_SUCCESS;  			} -			if (port && ret == LOCKDOWN_E_SUCCESS) -				*port = port_loc; +			if (port_loc && ret == LOCKDOWN_E_SUCCESS) { +				(*service)->port = port_loc; +			} +		} + +		/* check if the service requires SSL */ +		node = plist_dict_get_item(dict, "EnableServiceSSL"); +		if (node && (plist_get_node_type(node) == PLIST_BOOLEAN)) { +			uint8_t b = 0; +			plist_get_bool_val(node, &b); +			(*service)->ssl_enabled = b;  		}  	} else {  		ret = LOCKDOWN_E_START_SERVICE_FAILED; @@ -1785,3 +1804,18 @@ lockdownd_error_t lockdownd_data_classes_free(char **classes)  	}  	return LOCKDOWN_E_SUCCESS;  } + +/** + * Frees memory of a service descriptor as returned by lockdownd_start_service() + * + * @param sevice A service descriptor instance to free. + * + * @return LOCKDOWN_E_SUCCESS on success + */ +lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service) +{ +	if (service) +		free(service); + +	return LOCKDOWN_E_SUCCESS; +} diff --git a/src/misagent.c b/src/misagent.c index 45f1391..c624603 100644 --- a/src/misagent.c +++ b/src/misagent.c @@ -91,20 +91,20 @@ static misagent_error_t misagent_check_result(plist_t response, int* status_code   * Connects to the misagent service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will point to a newly allocated   *     misagent_client_t upon successful return.   *   * @return MISAGENT_E_SUCCESS on success, MISAGENT_E_INVALID_ARG when   *     client is NULL, or an MISAGENT_E_* error code otherwise.   */ -misagent_error_t misagent_client_new(idevice_t device, uint16_t port, misagent_client_t *client) +misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client)  {  	if (!device)  		return MISAGENT_E_INVALID_ARG;  	property_list_service_client_t plistclient = NULL; -	misagent_error_t err = misagent_error(property_list_service_client_new(device, port, &plistclient)); +	misagent_error_t err = misagent_error(property_list_service_client_new(device, service, &plistclient));  	if (err != MISAGENT_E_SUCCESS) {  		return err;  	} diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c index 557fbda..3e31ef4 100644 --- a/src/mobile_image_mounter.c +++ b/src/mobile_image_mounter.c @@ -87,7 +87,7 @@ static mobile_image_mounter_error_t mobile_image_mounter_error(property_list_ser   * Connects to the mobile_image_mounter service on the specified device.   *    * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will be set to a newly allocated   *    mobile_image_mounter_client_t upon successful return.   *  @@ -96,13 +96,13 @@ static mobile_image_mounter_error_t mobile_image_mounter_error(property_list_ser   *    or MOBILE_IMAGE_MOUNTER_E_CONN_FAILED if the connection to the   *    device could not be established.   */ -mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t port, mobile_image_mounter_client_t *client) +mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t service, mobile_image_mounter_client_t *client)  {  	if (!device)  		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;  	property_list_service_client_t plistclient = NULL; -	if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { +	if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {  		return MOBILE_IMAGE_MOUNTER_E_CONN_FAILED;  	} diff --git a/src/mobilebackup.c b/src/mobilebackup.c index 78f9a5c..ab4dec0 100644 --- a/src/mobilebackup.c +++ b/src/mobilebackup.c @@ -64,7 +64,7 @@ static mobilebackup_error_t mobilebackup_error(device_link_service_error_t err)   * Connects to the mobilebackup service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will be set to a newly allocated   *     mobilebackup_client_t upon successful return.   * @@ -72,14 +72,14 @@ static mobilebackup_error_t mobilebackup_error(device_link_service_error_t err)   *     or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if   *     the mobilebackup version on the device is newer.   */ -mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, +mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service,  						   mobilebackup_client_t * client)  { -	if (!device || port == 0 || !client || *client) +	if (!device || service->port == 0 || !client || *client)  		return MOBILEBACKUP_E_INVALID_ARG;  	device_link_service_client_t dlclient = NULL; -	mobilebackup_error_t ret = mobilebackup_error(device_link_service_client_new(device, port, &dlclient)); +	mobilebackup_error_t ret = mobilebackup_error(device_link_service_client_new(device, service, &dlclient));  	if (ret != MOBILEBACKUP_E_SUCCESS) {  		return ret;  	} diff --git a/src/mobilebackup2.c b/src/mobilebackup2.c index 2089c87..bcf5944 100644 --- a/src/mobilebackup2.c +++ b/src/mobilebackup2.c @@ -65,7 +65,7 @@ static mobilebackup2_error_t mobilebackup2_error(device_link_service_error_t err   * Connects to the mobilebackup2 service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will be set to a newly allocated   *     mobilebackup2_client_t upon successful return.   * @@ -73,14 +73,14 @@ static mobilebackup2_error_t mobilebackup2_error(device_link_service_error_t err   *     if one or more parameter is invalid, or MOBILEBACKUP2_E_BAD_VERSION   *     if the mobilebackup2 version on the device is newer.   */ -mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, uint16_t port, +mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service,  						mobilebackup2_client_t * client)  { -	if (!device || port == 0 || !client || *client) +	if (!device || service->port == 0 || !client || *client)  		return MOBILEBACKUP2_E_INVALID_ARG;  	device_link_service_client_t dlclient = NULL; -	mobilebackup2_error_t ret = mobilebackup2_error(device_link_service_client_new(device, port, &dlclient)); +	mobilebackup2_error_t ret = mobilebackup2_error(device_link_service_client_new(device, service, &dlclient));  	if (ret != MOBILEBACKUP2_E_SUCCESS) {  		return ret;  	} diff --git a/src/mobilesync.c b/src/mobilesync.c index 39b1da8..4fe24b2 100644 --- a/src/mobilesync.c +++ b/src/mobilesync.c @@ -69,7 +69,7 @@ static mobilesync_error_t mobilesync_error(device_link_service_error_t err)   * Connects to the mobilesync service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service()). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will be set to a newly allocated   *     #mobilesync_client_t upon successful return.   * @@ -78,14 +78,14 @@ static mobilesync_error_t mobilesync_error(device_link_service_error_t err)   * @retval DEVICE_LINK_SERVICE_E_BAD_VERSION if the mobilesync version on   * the device is newer.   */ -mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, +mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service,  						   mobilesync_client_t * client)  { -	if (!device || port == 0 || !client || *client) +	if (!device || service->port == 0 || !client || *client)  		return MOBILESYNC_E_INVALID_ARG;  	device_link_service_client_t dlclient = NULL; -	mobilesync_error_t ret = mobilesync_error(device_link_service_client_new(device, port, &dlclient)); +	mobilesync_error_t ret = mobilesync_error(device_link_service_client_new(device, service, &dlclient));  	if (ret != MOBILESYNC_E_SUCCESS) {  		return ret;  	} diff --git a/src/notification_proxy.c b/src/notification_proxy.c index 6e09840..8fb9ad0 100644 --- a/src/notification_proxy.c +++ b/src/notification_proxy.c @@ -98,7 +98,7 @@ static np_error_t np_error(property_list_service_error_t err)   * Connects to the notification_proxy on the specified device.   *    * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will be set to a newly allocated np_client_t   *    upon successful return.   *  @@ -106,13 +106,13 @@ static np_error_t np_error(property_list_service_error_t err)   *   or NP_E_CONN_FAILED when the connection to the device could not be   *   established.   */ -np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) +np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client)  {  	if (!device)  		return NP_E_INVALID_ARG;  	property_list_service_client_t plistclient = NULL; -	if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { +	if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {  		return NP_E_CONN_FAILED;  	} diff --git a/src/property_list_service.c b/src/property_list_service.c index c9a8edf..15adbc8 100644 --- a/src/property_list_service.c +++ b/src/property_list_service.c @@ -57,8 +57,7 @@ static property_list_service_error_t idevice_to_property_list_service_error(idev   * Creates a new property list service for the specified port.   *    * @param device The device to connect to. - * @param port The port on the device to connect to, usually opened by a call to - *     lockdownd_start_service. + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will be set to a newly allocated   *     property_list_service_client_t upon successful return.   * @@ -66,14 +65,14 @@ static property_list_service_error_t idevice_to_property_list_service_error(idev   *     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.   */ -property_list_service_error_t property_list_service_client_new(idevice_t device, uint16_t port, property_list_service_client_t *client) +property_list_service_error_t property_list_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, property_list_service_client_t *client)  { -	if (!device || port == 0 || !client || *client) +	if (!device || (service->port == 0) || !client || *client)  		return PROPERTY_LIST_SERVICE_E_INVALID_ARG;  	/* Attempt connection */  	idevice_connection_t connection = NULL; -	if (idevice_connect(device, port, &connection) != IDEVICE_E_SUCCESS) { +	if (idevice_connect(device, service->port, &connection) != IDEVICE_E_SUCCESS) {  		return PROPERTY_LIST_SERVICE_E_MUX_ERROR;  	} @@ -81,8 +80,12 @@ property_list_service_error_t property_list_service_client_new(idevice_t device,  	property_list_service_client_t client_loc = (property_list_service_client_t)malloc(sizeof(struct property_list_service_client_private));  	client_loc->connection = connection; -	*client = client_loc; +	/* enable SSL if requested */ +	if (service->ssl_enabled == 1) +		property_list_service_enable_ssl(client_loc); +	/* all done, return success */ +	*client = client_loc;  	return PROPERTY_LIST_SERVICE_E_SUCCESS;  } diff --git a/src/property_list_service.h b/src/property_list_service.h index 037f9aa..db1c09d 100644 --- a/src/property_list_service.h +++ b/src/property_list_service.h @@ -21,6 +21,7 @@  #ifndef PROPERTY_LIST_SERVICE_H  #define PROPERTY_LIST_SERVICE_H +#include <libimobiledevice/lockdown.h>  #include "idevice.h"  /* Error Codes */ @@ -41,7 +42,7 @@ typedef struct property_list_service_client_private *property_list_service_clien  typedef int16_t property_list_service_error_t;  /* creation and destruction */ -property_list_service_error_t property_list_service_client_new(idevice_t device, uint16_t port, property_list_service_client_t *client); +property_list_service_error_t property_list_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, property_list_service_client_t *client);  property_list_service_error_t property_list_service_client_free(property_list_service_client_t client);  /* sending */ diff --git a/src/restore.c b/src/restore.c index 3474091..1b2ff78 100644 --- a/src/restore.c +++ b/src/restore.c @@ -368,8 +368,13 @@ restored_error_t restored_client_new(idevice_t device, restored_client_t *client  	restored_error_t ret = RESTORE_E_SUCCESS; +	static struct lockdownd_service_descriptor service = { +		.port = 0xf27e, +		.ssl_enabled = 0 +	}; +  	property_list_service_client_t plistclient = NULL; -	if (property_list_service_client_new(device, 0xf27e, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { +	if (property_list_service_client_new(device, (lockdownd_service_descriptor_t)&service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {  		debug_info("could not connect to restored (device %s)", device->udid);  		return RESTORE_E_MUX_ERROR;  	} diff --git a/src/sbservices.c b/src/sbservices.c index 2c17d8c..6b1a4d1 100644 --- a/src/sbservices.c +++ b/src/sbservices.c @@ -88,20 +88,20 @@ static sbservices_error_t sbservices_error(property_list_service_error_t err)   * Connects to the springboardservices service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will point to a newly allocated   *     sbservices_client_t upon successful return.   *   * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when   *     client is NULL, or an SBSERVICES_E_* error code otherwise.   */ -sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) +sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t service, sbservices_client_t *client)  {  	if (!device)  		return SBSERVICES_E_INVALID_ARG;  	property_list_service_client_t plistclient = NULL; -	sbservices_error_t err = sbservices_error(property_list_service_client_new(device, port, &plistclient)); +	sbservices_error_t err = sbservices_error(property_list_service_client_new(device, service, &plistclient));  	if (err != SBSERVICES_E_SUCCESS) {  		return err;  	} diff --git a/src/screenshotr.c b/src/screenshotr.c index 063d282..e2bc979 100644 --- a/src/screenshotr.c +++ b/src/screenshotr.c @@ -62,7 +62,7 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err)   * Connects to the screenshotr service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will be set to a newly allocated   *     screenshotr_client_t upon successful return.   * @@ -73,14 +73,14 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err)   *     or more parameters are invalid, or SCREENSHOTR_E_CONN_FAILED if the   *     connection to the device could not be established.   */ -screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, +screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service,  					   screenshotr_client_t * client)  { -	if (!device || port == 0 || !client || *client) +	if (!device || service->port == 0 || !client || *client)  		return SCREENSHOTR_E_INVALID_ARG;  	device_link_service_client_t dlclient = NULL; -	screenshotr_error_t ret = screenshotr_error(device_link_service_client_new(device, port, &dlclient)); +	screenshotr_error_t ret = screenshotr_error(device_link_service_client_new(device, service, &dlclient));  	if (ret != SCREENSHOTR_E_SUCCESS) {  		return ret;  	} diff --git a/src/webinspector.c b/src/webinspector.c index c3d57cc..eb12d4d 100644 --- a/src/webinspector.c +++ b/src/webinspector.c @@ -62,7 +62,7 @@ static webinspector_error_t webinspector_error(property_list_service_error_t err   * Connects to the webinspector service on the specified device.   *   * @param device The device to connect to. - * @param port Destination port (usually given by lockdownd_start_service). + * @param service The service descriptor returned by lockdownd_start_service.   * @param client Pointer that will point to a newly allocated   *     webinspector_client_t upon successful return. Must be freed using   *     webinspector_client_free() after use. @@ -70,19 +70,19 @@ static webinspector_error_t webinspector_error(property_list_service_error_t err   * @return WEBINSPECTOR_E_SUCCESS on success, WEBINSPECTOR_E_INVALID_ARG when   *     client is NULL, or an WEBINSPECTOR_E_* error code otherwise.   */ -webinspector_error_t webinspector_client_new(idevice_t device, uint16_t port, webinspector_client_t * client) +webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t service, webinspector_client_t * client)  {  	*client = NULL; -	debug_info("Creating webinspector_client, port = %d.", port); +	debug_info("Creating webinspector_client, port = %d.", service->port); -	if (!device || port == 0 || !client || *client) { +	if (!device || service->port == 0 || !client || *client) {  		debug_info("Incorrect parameter passed to webinspector_client_new.");  		return WEBINSPECTOR_E_INVALID_ARG;  	}  	property_list_service_client_t plclient = NULL; -	webinspector_error_t ret = webinspector_error(property_list_service_client_new(device, port, &plclient)); +	webinspector_error_t ret = webinspector_error(property_list_service_client_new(device, service, &plclient));  	if (ret != WEBINSPECTOR_E_SUCCESS) {  		debug_info("Creating a property list client failed. Error: %i", ret);  		return ret; @@ -118,22 +118,27 @@ webinspector_error_t webinspector_start_service(idevice_t device, webinspector_c  		debug_info("Could not create a lockdown client.");  		return WEBINSPECTOR_E_UNKNOWN_ERROR;  	} -	 -	uint16_t port = 0; -	lockdownd_start_service(lckd, WEBINSPECTOR_SERVICE_NAME, &port); + +	lockdownd_service_descriptor_t service = NULL; +	lockdownd_start_service(lckd, WEBINSPECTOR_SERVICE_NAME, &service);  	lockdownd_client_free(lckd); -	if (port <= 0) { +	if (service->port <= 0) {  		debug_info("Could not start webinspector service!");  		return WEBINSPECTOR_E_UNKNOWN_ERROR;  	} -	webinspector_error_t res = webinspector_client_new(device, port, client); +	webinspector_error_t res = webinspector_client_new(device, service, client);  	if (res != WEBINSPECTOR_E_SUCCESS) { -		debug_info("Could not connect to webinspector! Port: %i, error: %i", port, res); +		debug_info("Could not connect to webinspector! Port: %i, error: %i", service->port, res);  		return res;  	} +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	} +  	return WEBINSPECTOR_E_SUCCESS;  } diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index abd269a..95c5694 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c @@ -745,7 +745,7 @@ static int mobilebackup_check_file_integrity(const char *backup_directory, const  static void do_post_notification(const char *notification)  { -	uint16_t nport = 0; +	lockdownd_service_descriptor_t service = NULL;  	np_client_t np;  	if (!client) { @@ -754,9 +754,9 @@ static void do_post_notification(const char *notification)  		}  	} -	lockdownd_start_service(client, NP_SERVICE_NAME, &nport); -	if (nport) { -		np_client_new(device, nport, &np); +	lockdownd_start_service(client, NP_SERVICE_NAME, &service); +	if (service->port) { +		np_client_new(device, service, &np);  		if (np) {  			np_post_notification(np, notification);  			np_client_free(np); @@ -764,6 +764,11 @@ static void do_post_notification(const char *notification)  	} else {  		printf("Could not start %s\n", NP_SERVICE_NAME);  	} + +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	}  }  static void print_progress(double progress) @@ -819,7 +824,7 @@ int main(int argc, char *argv[])  	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;  	int i;  	char* udid = NULL; -	uint16_t port = 0; +	lockdownd_service_descriptor_t service = NULL;  	int cmd = -1;  	int is_full_backup = 0;  	char *backup_directory = NULL; @@ -931,9 +936,9 @@ int main(int argc, char *argv[])  	/* start notification_proxy */  	np_client_t np = NULL; -	ret = lockdownd_start_service(client, NP_SERVICE_NAME, &port); -	if ((ret == LOCKDOWN_E_SUCCESS) && port) { -		np_client_new(device, port, &np); +	ret = lockdownd_start_service(client, NP_SERVICE_NAME, &service); +	if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { +		np_client_new(device, service, &np);  		np_set_notify_callback(np, notify_cb, NULL);  		const char *noties[5] = {  			NP_SYNC_CANCEL_REQUEST, @@ -947,22 +952,37 @@ int main(int argc, char *argv[])  		printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME);  	} +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	} +  	afc_client_t afc = NULL;  	if (cmd == CMD_BACKUP) {  		/* start AFC, we need this for the lock file */ -		port = 0; -		ret = lockdownd_start_service(client, "com.apple.afc", &port); -		if ((ret == LOCKDOWN_E_SUCCESS) && port) { -			afc_client_new(device, port, &afc); +		service->port = 0; +		service->ssl_enabled = 0; +		ret = lockdownd_start_service(client, "com.apple.afc", &service); +		if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { +			afc_client_new(device, service, &afc);  		}  	} +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	} +  	/* start mobilebackup service and retrieve port */ -	port = 0; -	ret = lockdownd_start_service(client, MOBILEBACKUP_SERVICE_NAME, &port); -	if ((ret == LOCKDOWN_E_SUCCESS) && port) { -		printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, port); -		mobilebackup_client_new(device, port, &mobilebackup); +	ret = lockdownd_start_service(client, MOBILEBACKUP_SERVICE_NAME, &service); +	if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { +		printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, service->port); +		mobilebackup_client_new(device, service, &mobilebackup); + +		if (service) { +			lockdownd_service_descriptor_free(service); +			service = NULL; +		}  		/* check abort conditions */  		if (quit_flag > 0) { diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index a0e732d..0353c9b 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c @@ -479,7 +479,7 @@ static int mb2_status_check_snapshot_state(const char *path, const char *udid, c  static void do_post_notification(idevice_t device, const char *notification)  { -	uint16_t nport = 0; +	lockdownd_service_descriptor_t service = NULL;  	np_client_t np;  	lockdownd_client_t lockdown = NULL; @@ -488,9 +488,9 @@ static void do_post_notification(idevice_t device, const char *notification)  		return;  	} -	lockdownd_start_service(lockdown, NP_SERVICE_NAME, &nport); -	if (nport) { -		np_client_new(device, nport, &np); +	lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); +	if (service->port) { +		np_client_new(device, service, &np);  		if (np) {  			np_post_notification(np, notification);  			np_client_free(np); @@ -498,6 +498,11 @@ static void do_post_notification(idevice_t device, const char *notification)  	} else {  		printf("Could not start %s\n", NP_SERVICE_NAME);  	} + +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	}  }  static void print_progress_real(double progress, int flush) @@ -1277,7 +1282,7 @@ int main(int argc, char *argv[])  	int i;  	char* udid = NULL;  	char* source_udid = NULL; -	uint16_t port = 0; +	lockdownd_service_descriptor_t service = NULL;  	int cmd = -1;  	int cmd_flags = 0;  	int is_full_backup = 0; @@ -1551,9 +1556,9 @@ int main(int argc, char *argv[])  	/* start notification_proxy */  	np_client_t np = NULL; -	ret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &port); -	if ((ret == LOCKDOWN_E_SUCCESS) && port) { -		np_client_new(device, port, &np); +	ret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); +	if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { +		np_client_new(device, service, &np);  		np_set_notify_callback(np, notify_cb, NULL);  		const char *noties[5] = {  			NP_SYNC_CANCEL_REQUEST, @@ -1567,23 +1572,38 @@ int main(int argc, char *argv[])  		printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME);  	} +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	} +  	afc_client_t afc = NULL;  	if (cmd == CMD_BACKUP) {  		/* start AFC, we need this for the lock file */ -		port = 0; -		ret = lockdownd_start_service(lockdown, "com.apple.afc", &port); -		if ((ret == LOCKDOWN_E_SUCCESS) && port) { -			afc_client_new(device, port, &afc); +		service->port = 0; +		service->ssl_enabled = 0; +		ret = lockdownd_start_service(lockdown, "com.apple.afc", &service); +		if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { +			afc_client_new(device, service, &afc);  		}  	} +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	} +  	/* start mobilebackup service and retrieve port */  	mobilebackup2_client_t mobilebackup2 = NULL; -	port = 0; -	ret = lockdownd_start_service(lockdown, MOBILEBACKUP2_SERVICE_NAME, &port); -	if ((ret == LOCKDOWN_E_SUCCESS) && port) { -		PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, port); -		mobilebackup2_client_new(device, port, &mobilebackup2); +	ret = lockdownd_start_service(lockdown, MOBILEBACKUP2_SERVICE_NAME, &service); +	if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { +		PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, service->port); +		mobilebackup2_client_new(device, service, &mobilebackup2); + +		if (service) { +			lockdownd_service_descriptor_free(service); +			service = NULL; +		}  		/* send Hello message */  		double local_versions[2] = {2.0, 2.1}; diff --git a/tools/idevicedebugserverproxy.c b/tools/idevicedebugserverproxy.c index 3253e6a..32438ad 100644 --- a/tools/idevicedebugserverproxy.c +++ b/tools/idevicedebugserverproxy.c @@ -228,7 +228,7 @@ int main(int argc, char *argv[])  	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;  	thread_t th;  	const char* udid = NULL; -	uint16_t port = 0; +	lockdownd_service_descriptor_t service = NULL;  	uint16_t local_port = 0;  	int result = EXIT_SUCCESS;  	int i; @@ -297,14 +297,14 @@ int main(int argc, char *argv[])  		goto leave_cleanup;  	} -	if ((lockdownd_start_service(lockdown, "com.apple.debugserver", &port) != LOCKDOWN_E_SUCCESS) || !port) { +	if ((lockdownd_start_service(lockdown, "com.apple.debugserver", &service) != LOCKDOWN_E_SUCCESS) || !service->port) {  		fprintf(stderr, "Could not start com.apple.debugserver!\nPlease make sure to mount the developer disk image first.\n");  		result = EXIT_FAILURE;  		goto leave_cleanup;  	} -	if (idevice_connect(device, port, &connection) != IDEVICE_E_SUCCESS) { -		fprintf(stderr, "Connection to debugserver port %d failed!\n", (int)port); +	if (idevice_connect(device, service->port, &connection) != IDEVICE_E_SUCCESS) { +		fprintf(stderr, "Connection to debugserver port %d failed!\n", (int)service->port);  		result = EXIT_FAILURE;  		goto leave_cleanup;  	} @@ -320,7 +320,12 @@ int main(int argc, char *argv[])  	socket_info.device_connection = connection;  	socket_info.local_port = local_port; -	socket_info.remote_port = port; +	socket_info.remote_port = service->port; + +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	}  	/* create local socket */  	socket_info.server_fd = socket_create(socket_info.local_port); diff --git a/tools/idevicediagnostics.c b/tools/idevicediagnostics.c index 10dab77..410d054 100644 --- a/tools/idevicediagnostics.c +++ b/tools/idevicediagnostics.c @@ -57,7 +57,7 @@ int main(int argc, char **argv)  	lockdownd_client_t lockdown_client = NULL;  	diagnostics_relay_client_t diagnostics_client = NULL;  	lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; -	uint16_t port = 0; +	lockdownd_service_descriptor_t service = NULL;  	int result = -1;  	int i;  	const char *udid = NULL; @@ -173,23 +173,23 @@ int main(int argc, char **argv)  		goto cleanup;  	} -	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown_client, NULL)) { +	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown_client, "idevicediagnostics")) {  		idevice_free(device);  		printf("Unable to connect to lockdownd.\n");  		goto cleanup;  	}  	/*  attempt to use newer diagnostics service available on iOS 5 and later */ -	ret = lockdownd_start_service(lockdown_client, "com.apple.mobile.diagnostics_relay", &port); +	ret = lockdownd_start_service(lockdown_client, "com.apple.mobile.diagnostics_relay", &service);  	if (ret != LOCKDOWN_E_SUCCESS) {  		/*  attempt to use older diagnostics service */ -		ret = lockdownd_start_service(lockdown_client, "com.apple.iosdiagnostics.relay", &port); +		ret = lockdownd_start_service(lockdown_client, "com.apple.iosdiagnostics.relay", &service);  	}  	lockdownd_client_free(lockdown_client); -	if ((ret == LOCKDOWN_E_SUCCESS) && (port > 0)) { -		if (diagnostics_relay_client_new(device, port, &diagnostics_client) != DIAGNOSTICS_RELAY_E_SUCCESS) { +	if ((ret == LOCKDOWN_E_SUCCESS) && (service->port > 0)) { +		if (diagnostics_relay_client_new(device, service, &diagnostics_client) != DIAGNOSTICS_RELAY_E_SUCCESS) {  			printf("Could not connect to diagnostics_relay!\n");  			result = -1;  		} else { @@ -258,6 +258,11 @@ int main(int argc, char **argv)  		printf("Could not start diagnostics service!\n");  	} +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	} +  	idevice_free(device);  cleanup: diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c index 9b65a0e..57a2e27 100644 --- a/tools/ideviceimagemounter.c +++ b/tools/ideviceimagemounter.c @@ -267,7 +267,7 @@ int main(int argc, char **argv)  	lockdownd_client_t lckd = NULL;  	mobile_image_mounter_client_t mim = NULL;  	afc_client_t afc = NULL; -	uint16_t port = 0; +	lockdownd_service_descriptor_t service = NULL;  	int res = -1;  	char *image_path = NULL;  	char *image_sig_path = NULL; @@ -303,30 +303,38 @@ int main(int argc, char **argv)  		goto leave;  	} -	lockdownd_start_service(lckd, "com.apple.mobile.mobile_image_mounter", &port); +	lockdownd_start_service(lckd, "com.apple.mobile.mobile_image_mounter", &service); -	if (port == 0) { +	if (service->port == 0) {  		printf("ERROR: Could not start mobile_image_mounter service!\n");  		goto leave;  	} -	if (mobile_image_mounter_new(device, port, &mim) != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +	if (mobile_image_mounter_new(device, service, &mim) != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {  		printf("ERROR: Could not connect to mobile_image_mounter!\n");  		goto leave;  	}	 +	if (service) { +		lockdownd_service_descriptor_free(service); +		service = NULL; +	} +  	if (!list_mode) {  		struct stat fst; -		port = 0; -		if ((lockdownd_start_service(lckd, "com.apple.afc", &port) != -			 LOCKDOWN_E_SUCCESS) || !port) { +		if ((lockdownd_start_service(lckd, "com.apple.afc", &service) != +			 LOCKDOWN_E_SUCCESS) || !service->port) {  			fprintf(stderr, "Could not start com.apple.afc!\n");  			goto leave;  		} -		if (afc_client_new(device, port, &afc) != AFC_E_SUCCESS) { +		if (afc_client_new(device, service, &afc) != AFC_E_SUCCESS) {  			fprintf(stderr, "Could not connect to AFC!\n");  			goto leave;  		} +		if (service) { +			lockdownd_service_descriptor_free(service); +			service = NULL; +		}  		if (stat(image_path, &fst) != 0) {  			fprintf(stderr, "ERROR: stat: %s: %s\n", image_path, strerror(errno));  			goto leave; diff --git a/tools/ideviceprovision.c b/tools/ideviceprovision.c index 1c6866d..13fd239 100644 --- a/tools/ideviceprovision.c +++ b/tools/ideviceprovision.c @@ -193,6 +193,7 @@ static plist_t profile_get_embedded_plist(plist_t profile)  int main(int argc, char *argv[])  {  	lockdownd_client_t client = NULL; +	lockdownd_service_descriptor_t service = NULL;  	idevice_t device = NULL;  	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;  	int i; @@ -278,8 +279,7 @@ int main(int argc, char *argv[])  		return -1;  	} -	uint16_t port = 0; -	if (LOCKDOWN_E_SUCCESS != lockdownd_start_service(client, "com.apple.misagent", &port)) { +	if (LOCKDOWN_E_SUCCESS != lockdownd_start_service(client, "com.apple.misagent", &service)) {  		fprintf(stderr, "Could not start service \"com.apple.misagent\"\n");  		lockdownd_client_free(client);  		idevice_free(device); @@ -289,13 +289,18 @@ int main(int argc, char *argv[])  	client = NULL;  	misagent_client_t mis = NULL; -	if (misagent_client_new(device, port, &mis) != MISAGENT_E_SUCCESS) { +	if (misagent_client_new(device, service, &mis) != MISAGENT_E_SUCCESS) {  		fprintf(stderr, "Could not connect to \"com.apple.misagent\" on device\n"); +		if (service) +			lockdownd_service_descriptor_free(service);  		lockdownd_client_free(client);  		idevice_free(device);  		return -1;  	} +	if (service) +		lockdownd_service_descriptor_free(service); +  	switch (op) {  		case OP_INSTALL:  		{ diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c index cba62a2..23e7b41 100644 --- a/tools/idevicescreenshot.c +++ b/tools/idevicescreenshot.c @@ -36,7 +36,7 @@ int main(int argc, char **argv)  	idevice_t device = NULL;  	lockdownd_client_t lckd = NULL;  	screenshotr_client_t shotr = NULL; -	uint16_t port = 0; +	lockdownd_service_descriptor_t service = NULL;  	int result = -1;  	int i;  	const char *udid = NULL; @@ -81,10 +81,10 @@ int main(int argc, char **argv)  		return -1;  	} -	lockdownd_start_service(lckd, "com.apple.mobile.screenshotr", &port); +	lockdownd_start_service(lckd, "com.apple.mobile.screenshotr", &service);  	lockdownd_client_free(lckd); -	if (port > 0) { -		if (screenshotr_client_new(device, port, &shotr) != SCREENSHOTR_E_SUCCESS) { +	if (service->port > 0) { +		if (screenshotr_client_new(device, service, &shotr) != SCREENSHOTR_E_SUCCESS) {  			printf("Could not connect to screenshotr!\n");  		} else {  			char *imgdata = NULL; @@ -113,8 +113,12 @@ int main(int argc, char **argv)  	} else {  		printf("Could not start screenshotr service! Remember that you have to mount the Developer disk image on your device if you want to use the screenshotr service.\n");  	} + +	if (service) +		lockdownd_service_descriptor_free(service); +  	idevice_free(device); -	 +  	return result;  } diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c index a17999c..6ce6d0e 100644 --- a/tools/idevicesyslog.c +++ b/tools/idevicesyslog.c @@ -49,7 +49,7 @@ int main(int argc, char *argv[])  	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;  	int i;  	const char* udid = NULL; -	uint16_t port = 0; +	lockdownd_service_descriptor_t service = NULL;  	signal(SIGINT, clean_exit);  	signal(SIGTERM, clean_exit); @@ -99,13 +99,13 @@ int main(int argc, char *argv[])  	}  	/* start syslog_relay service and retrieve port */ -	ret = lockdownd_start_service(client, "com.apple.syslog_relay", &port); -	if ((ret == LOCKDOWN_E_SUCCESS) && port) { +	ret = lockdownd_start_service(client, "com.apple.syslog_relay", &service); +	if ((ret == LOCKDOWN_E_SUCCESS) && service->port) {  		lockdownd_client_free(client); -		 +  		/* connect to socket relay messages */  		idevice_connection_t conn = NULL; -		if ((idevice_connect(device, port, &conn) != IDEVICE_E_SUCCESS) || !conn) { +		if ((idevice_connect(device, service->port, &conn) != IDEVICE_E_SUCCESS) || !conn) {  			printf("ERROR: Could not open usbmux connection.\n");  		} else {  			while (!quit_flag) { @@ -126,6 +126,9 @@ int main(int argc, char *argv[])  		printf("ERROR: Could not start service com.apple.syslog_relay.\n");  	} +	if (service) +		lockdownd_service_descriptor_free(service); +  	idevice_free(device);  	return 0; | 
