diff options
Diffstat (limited to 'src')
58 files changed, 1502 insertions, 458 deletions
| diff --git a/src/Makefile.am b/src/Makefile.am index 1c80ed6..1ee9be8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,19 +6,19 @@ AM_CPPFLAGS = \  AM_CFLAGS = \  	$(GLOBAL_CFLAGS) \ -	$(libusbmuxd_CFLAGS) \ -	$(libplist_CFLAGS) \ -	$(limd_glue_CFLAGS) \  	$(ssl_lib_CFLAGS) \  	$(LFS_CFLAGS) \ -	$(PTHREAD_CFLAGS) +	$(PTHREAD_CFLAGS) \ +	$(libusbmuxd_CFLAGS) \ +	$(libplist_CFLAGS) \ +	$(limd_glue_CFLAGS)  AM_LDFLAGS = \ +	$(ssl_lib_LIBS) \ +	$(PTHREAD_LIBS) \  	$(libusbmuxd_LIBS) \  	$(libplist_LIBS) \ -	$(limd_glue_LIBS) \ -	$(ssl_lib_LIBS) \ -	$(PTHREAD_LIBS) +	$(limd_glue_LIBS)  lib_LTLIBRARIES = libimobiledevice-1.0.la  libimobiledevice_1_0_la_LIBADD = $(top_builddir)/common/libinternalcommon.la @@ -58,6 +58,7 @@ libimobiledevice_1_0_la_SOURCES = \  	companion_proxy.c companion_proxy.h \  	reverse_proxy.c reverse_proxy.h \  	syslog_relay.c syslog_relay.h \ +	ostrace.c ostrace.h \  	bt_packet_logger.c bt_packet_logger.h  if WIN32 @@ -26,11 +26,14 @@  #endif  #include <stdio.h>  #include <stdlib.h> -#include <unistd.h>  #include <string.h> -#include "afc.h" +#ifndef _MSC_VER +#include <unistd.h> +#endif +  #include "idevice.h" +#include "afc.h"  #include "common/debug.h"  #include "endianness.h" @@ -68,7 +71,7 @@ static void afc_unlock(afc_client_t client)   *  invalid, or AFC_E_NO_MEM if there is a memory allocation problem.   */ -LIBIMOBILEDEVICE_API afc_error_t afc_client_new_with_service_client(service_client_t service_client, afc_client_t *client) +afc_error_t afc_client_new_with_service_client(service_client_t service_client, afc_client_t *client)  {  	if (!service_client)  		return AFC_E_INVALID_ARG; @@ -94,7 +97,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_client_new_with_service_client(service_clie  	return AFC_E_SUCCESS;  } -LIBIMOBILEDEVICE_API afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t * client) +afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t * client)  {  	if (!device || !service || service->port == 0)  		return AFC_E_INVALID_ARG; @@ -113,14 +116,14 @@ LIBIMOBILEDEVICE_API afc_error_t afc_client_new(idevice_t device, lockdownd_serv  	return err;  } -LIBIMOBILEDEVICE_API afc_error_t afc_client_start_service(idevice_t device, afc_client_t * client, const char* label) +afc_error_t afc_client_start_service(idevice_t device, afc_client_t * client, const char* label)  { -	afc_error_t err = AFC_E_UNKNOWN_ERROR; +	int32_t err = AFC_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, AFC_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(afc_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API afc_error_t afc_client_free(afc_client_t client) +afc_error_t afc_client_free(afc_client_t client)  {  	if (!client || !client->afc_packet)  		return AFC_E_INVALID_ARG; @@ -338,7 +341,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **bytes, uint32_t  		free(buf);  		debug_info("WARNING: Unknown operation code received 0x%llx param1=%lld", header.operation, param1); -#ifndef WIN32 +#ifndef _WIN32  		fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld", __func__, (long long)header.operation, (long long)param1);  #endif @@ -399,6 +402,50 @@ static char **make_strings_list(char *tokens, uint32_t length)  	return list;  } +static plist_t *make_dictionary(char *tokens, size_t length) +{ +	size_t j = 0; +	plist_t dict = NULL; + +	if (!tokens || !length) +		return NULL; + +	dict = plist_new_dict(); + +	while (j < length) { +		size_t key_len = strnlen(tokens + j, length - j); +		if (j + key_len >= length) { +			plist_free(dict); +			return NULL; +		} +		char* key = tokens + j; +		j += key_len + 1; + +		if (j >= length) { +			plist_free(dict); +			return NULL; +		} + +		size_t val_len = strnlen(tokens + j, length - j); +		if (j + val_len >= length) { +			plist_free(dict); +			return NULL; +		} +		char* val = tokens + j; +		j += val_len + 1; + +		char* endp = NULL; +		unsigned long long u64val = strtoull(val, &endp, 10); +		if (endp && *endp == '\0') { +			plist_dict_set_item(dict, key, plist_new_uint(u64val)); +		} else { +			plist_dict_set_item(dict, key, plist_new_string(val)); +		} +	} + +	return dict; +} +  static int _afc_check_packet_buffer(afc_client_t client, uint32_t data_len)  {  	if (data_len > client->packet_extra) { @@ -414,7 +461,7 @@ static int _afc_check_packet_buffer(afc_client_t client, uint32_t data_len)  #define AFC_PACKET_DATA_PTR ((char*)client->afc_packet + sizeof(AFCPacket)) -LIBIMOBILEDEVICE_API afc_error_t afc_read_directory(afc_client_t client, const char *path, char ***directory_information) +afc_error_t afc_read_directory(afc_client_t client, const char *path, char ***directory_information)  {  	uint32_t bytes = 0;  	char *data = NULL, **list_loc = NULL; @@ -458,7 +505,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_read_directory(afc_client_t client, const c  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_get_device_info(afc_client_t client, char ***device_information) +afc_error_t afc_get_device_info(afc_client_t client, char ***device_information)  {  	uint32_t bytes = 0;  	char *data = NULL, **list = NULL; @@ -495,7 +542,41 @@ LIBIMOBILEDEVICE_API afc_error_t afc_get_device_info(afc_client_t client, char *  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char **value) +afc_error_t afc_get_device_info_plist(afc_client_t client, plist_t *device_information) +{ +	uint32_t bytes = 0; +	char *data = NULL; +	afc_error_t ret = AFC_E_UNKNOWN_ERROR; + +	if (!client || !device_information) +		return AFC_E_INVALID_ARG; + +	afc_lock(client); + +	/* Send the command */ +	ret = afc_dispatch_packet(client, AFC_OP_GET_DEVINFO, 0, NULL, 0, &bytes); +	if (ret != AFC_E_SUCCESS) { +		afc_unlock(client); +		return AFC_E_NOT_ENOUGH_DATA; +	} +	/* Receive the data */ +	ret = afc_receive_data(client, &data, &bytes); +	if (ret != AFC_E_SUCCESS) { +		if (data) +			free(data); +		afc_unlock(client); +		return ret; +	} +	/* Parse the data */ +	*device_information = make_dictionary(data, bytes); +	free(data); + +	afc_unlock(client); + +	return ret; +} + +afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char **value)  {  	afc_error_t ret = AFC_E_INTERNAL_ERROR;  	char **kvps, **ptr; @@ -522,7 +603,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_get_device_info_key(afc_client_t client, co  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_remove_path(afc_client_t client, const char *path) +afc_error_t afc_remove_path(afc_client_t client, const char *path)  {  	uint32_t bytes = 0;  	afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -558,7 +639,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_remove_path(afc_client_t client, const char  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to) +afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *to)  {  	if (!client || !from || !to || !client->afc_packet || !client->parent)  		return AFC_E_INVALID_ARG; @@ -594,7 +675,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_rename_path(afc_client_t client, const char  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_make_directory(afc_client_t client, const char *path) +afc_error_t afc_make_directory(afc_client_t client, const char *path)  {  	uint32_t bytes = 0;  	afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -626,7 +707,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_make_directory(afc_client_t client, const c  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***file_information) +afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***file_information)  {  	char *received = NULL;  	uint32_t bytes = 0; @@ -644,8 +725,6 @@ LIBIMOBILEDEVICE_API afc_error_t afc_get_file_info(afc_client_t client, const ch  		return AFC_E_NO_MEM;  	} -	debug_info("We got %p and %p", client->afc_packet, AFC_PACKET_DATA_PTR); -  	/* Send command */  	memcpy(AFC_PACKET_DATA_PTR, path, data_len);  	ret = afc_dispatch_packet(client, AFC_OP_GET_FILE_INFO, data_len, NULL, 0, &bytes); @@ -666,7 +745,45 @@ LIBIMOBILEDEVICE_API afc_error_t afc_get_file_info(afc_client_t client, const ch  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle) +afc_error_t afc_get_file_info_plist(afc_client_t client, const char *path, plist_t *file_information) +{ +	char *received = NULL; +	uint32_t bytes = 0; +	afc_error_t ret = AFC_E_UNKNOWN_ERROR; + +	if (!client || !path || !file_information) +		return AFC_E_INVALID_ARG; + +	afc_lock(client); + +	uint32_t data_len = (uint32_t)strlen(path)+1; +	if (_afc_check_packet_buffer(client, data_len) < 0) { +		afc_unlock(client); +		debug_info("Failed to realloc packet buffer"); +		return AFC_E_NO_MEM; +	} + +	/* Send command */ +	memcpy(AFC_PACKET_DATA_PTR, path, data_len); +	ret = afc_dispatch_packet(client, AFC_OP_GET_FILE_INFO, data_len, NULL, 0, &bytes); +	if (ret != AFC_E_SUCCESS) { +		afc_unlock(client); +		return AFC_E_NOT_ENOUGH_DATA; +	} + +	/* Receive data */ +	ret = afc_receive_data(client, &received, &bytes); +	if (received) { +		*file_information = make_dictionary(received, bytes); +		free(received); +	} + +	afc_unlock(client); + +	return ret; +} + +afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle)  {  	if (!client || !client->parent || !client->afc_packet)  		return AFC_E_INVALID_ARG; @@ -718,7 +835,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_open(afc_client_t client, const char *  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read) +afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read)  {  	char *input = NULL;  	uint32_t current_count = 0, bytes_loc = 0; @@ -774,7 +891,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_read(afc_client_t client, uint64_t han  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written) +afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written)  {  	uint32_t current_count = 0;  	uint32_t bytes_loc = 0; @@ -809,7 +926,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_write(afc_client_t client, uint64_t ha  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_file_close(afc_client_t client, uint64_t handle) +afc_error_t afc_file_close(afc_client_t client, uint64_t handle)  {  	uint32_t bytes = 0;  	afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -840,7 +957,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_close(afc_client_t client, uint64_t ha  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation) +afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation)  {  	uint32_t bytes = 0;  	struct lockinfo { @@ -874,7 +991,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_lock(afc_client_t client, uint64_t han  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence) +afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence)  {  	uint32_t bytes = 0;  	struct seekinfo { @@ -908,7 +1025,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_seek(afc_client_t client, uint64_t han  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) +afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position)  {  	char *buffer = NULL;  	uint32_t bytes = 0; @@ -943,7 +1060,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_tell(afc_client_t client, uint64_t han  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize) +afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize)  {  	uint32_t bytes = 0;  	struct truncinfo { @@ -975,7 +1092,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_file_truncate(afc_client_t client, uint64_t  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize) +afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize)  {  	if (!client || !path || !client->afc_packet || !client->parent)  		return AFC_E_INVALID_ARG; @@ -1008,7 +1125,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_truncate(afc_client_t client, const char *p  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname) +afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname)  {  	if (!client || !target || !linkname || !client->afc_packet || !client->parent)  		return AFC_E_INVALID_ARG; @@ -1049,7 +1166,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_make_link(afc_client_t client, afc_link_typ  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime) +afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mtime)  {  	if (!client || !path || !client->afc_packet || !client->parent)  		return AFC_E_INVALID_ARG; @@ -1082,7 +1199,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_set_file_time(afc_client_t client, const ch  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_remove_path_and_contents(afc_client_t client, const char *path) +afc_error_t afc_remove_path_and_contents(afc_client_t client, const char *path)  {  	uint32_t bytes = 0;  	afc_error_t ret = AFC_E_UNKNOWN_ERROR; @@ -1114,7 +1231,7 @@ LIBIMOBILEDEVICE_API afc_error_t afc_remove_path_and_contents(afc_client_t clien  	return ret;  } -LIBIMOBILEDEVICE_API afc_error_t afc_dictionary_free(char **dictionary) +afc_error_t afc_dictionary_free(char **dictionary)  {  	int i = 0; @@ -1128,3 +1245,70 @@ LIBIMOBILEDEVICE_API afc_error_t afc_dictionary_free(char **dictionary)  	return AFC_E_SUCCESS;  } + +const char* afc_strerror(afc_error_t err) +{ +	switch (err) { +		case AFC_E_SUCCESS: +			return "Success"; +		case AFC_E_UNKNOWN_ERROR: +			return "Unknown Error"; +		case AFC_E_OP_HEADER_INVALID: +			return "Operation header invalid"; +		case AFC_E_NO_RESOURCES: +			return "No resources"; +		case AFC_E_READ_ERROR: +			return "Read error"; +		case AFC_E_WRITE_ERROR: +			return "Write error"; +		case AFC_E_UNKNOWN_PACKET_TYPE: +			return "Unknown packet type"; +		case AFC_E_INVALID_ARG: +			return "Invalid argument"; +		case AFC_E_OBJECT_NOT_FOUND: +			return "Not found"; +		case AFC_E_OBJECT_IS_DIR: +			return "Object is a directory"; +		case AFC_E_PERM_DENIED: +			return "Permission denied"; +		case AFC_E_SERVICE_NOT_CONNECTED: +			return "Service not connected"; +		case AFC_E_OP_TIMEOUT: +			return "Timeout"; +		case AFC_E_TOO_MUCH_DATA: +			return "Too much data"; +		case AFC_E_END_OF_DATA: +			return "End of data"; +		case AFC_E_OP_NOT_SUPPORTED: +			return "Operation not supported"; +		case AFC_E_OBJECT_EXISTS: +			return "Object exists"; +		case AFC_E_OBJECT_BUSY: +			return "Object busy"; +		case AFC_E_NO_SPACE_LEFT: +			return "No space left on device"; +		case AFC_E_OP_WOULD_BLOCK: +			return "Operation would block"; +		case AFC_E_IO_ERROR: +			return "I/O error"; +		case AFC_E_OP_INTERRUPTED: +			return "Operation interrupted"; +		case AFC_E_OP_IN_PROGRESS: +			return "Operation on progress"; +		case AFC_E_INTERNAL_ERROR: +			return "Internal error"; +		case AFC_E_MUX_ERROR: +			return "MUX error"; +		case AFC_E_NO_MEM: +			return "Out of memory"; +		case AFC_E_NOT_ENOUGH_DATA: +			return "Not enough data"; +		case AFC_E_DIR_NOT_EMPTY: +			return "Directory not empty"; +		case AFC_E_FORCE_SIGNED_TYPE: +			return "Force signed type"; +		default: +			break; +	} +	return "Unknown Error"; +} diff --git a/src/bt_packet_logger.c b/src/bt_packet_logger.c index 5f7bdeb..937747c 100644 --- a/src/bt_packet_logger.c +++ b/src/bt_packet_logger.c @@ -69,7 +69,7 @@ static bt_packet_logger_error_t bt_packet_logger_error(service_error_t err)  	return BT_PACKET_LOGGER_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_new(idevice_t device, lockdownd_service_descriptor_t service, bt_packet_logger_client_t * client) +bt_packet_logger_error_t bt_packet_logger_client_new(idevice_t device, lockdownd_service_descriptor_t service, bt_packet_logger_client_t * client)  {  	if (!device || !service || service->port == 0 || !client || *client) {  		debug_info("Incorrect parameter passed to bt_packet_logger_client_new."); @@ -95,14 +95,14 @@ LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_new(idevic  	return 0;  } -LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_start_service(idevice_t device, bt_packet_logger_client_t * client, const char* label) +bt_packet_logger_error_t bt_packet_logger_client_start_service(idevice_t device, bt_packet_logger_client_t * client, const char* label)  {  	bt_packet_logger_error_t err = BT_PACKET_LOGGER_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, BT_PACKETLOGGER_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(bt_packet_logger_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_free(bt_packet_logger_client_t client) +bt_packet_logger_error_t bt_packet_logger_client_free(bt_packet_logger_client_t client)  {  	if (!client)  		return BT_PACKET_LOGGER_E_INVALID_ARG; @@ -113,7 +113,7 @@ LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_client_free(bt_pa  	return err;  } -LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_receive_with_timeout(bt_packet_logger_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout) +bt_packet_logger_error_t bt_packet_logger_receive_with_timeout(bt_packet_logger_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout)  {  	bt_packet_logger_error_t res = BT_PACKET_LOGGER_E_UNKNOWN_ERROR;  	int bytes = 0; @@ -186,7 +186,7 @@ void *bt_packet_logger_worker(void *arg)  	return NULL;  } -LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_start_capture(bt_packet_logger_client_t client, bt_packet_logger_receive_cb_t callback, void* user_data) +bt_packet_logger_error_t bt_packet_logger_start_capture(bt_packet_logger_client_t client, bt_packet_logger_receive_cb_t callback, void* user_data)  {  	if (!client || !callback)  		return BT_PACKET_LOGGER_E_INVALID_ARG; @@ -214,7 +214,7 @@ LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_start_capture(bt_  } -LIBIMOBILEDEVICE_API bt_packet_logger_error_t bt_packet_logger_stop_capture(bt_packet_logger_client_t client) +bt_packet_logger_error_t bt_packet_logger_stop_capture(bt_packet_logger_client_t client)  {  	if (client->worker) {  		/* notify thread to finish */ diff --git a/src/bt_packet_logger.h b/src/bt_packet_logger.h index 95990d5..620555e 100644 --- a/src/bt_packet_logger.h +++ b/src/bt_packet_logger.h @@ -22,6 +22,7 @@  #ifndef _BR_PACKET_LOGGER_H  #define _BR_PACKET_LOGGER_H +#include "idevice.h"  #include "libimobiledevice/bt_packet_logger.h"  #include "service.h"  #include <libimobiledevice-glue/thread.h> diff --git a/src/companion_proxy.c b/src/companion_proxy.c index 5852904..421fa9a 100644 --- a/src/companion_proxy.c +++ b/src/companion_proxy.c @@ -62,7 +62,7 @@ static companion_proxy_error_t companion_proxy_error(property_list_service_error  	return COMPANION_PROXY_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, companion_proxy_client_t * client) +companion_proxy_error_t companion_proxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, companion_proxy_client_t * client)  {  	*client = NULL; @@ -90,14 +90,14 @@ LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_new(idevice_  	return COMPANION_PROXY_E_SUCCESS;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_start_service(idevice_t device, companion_proxy_client_t * client, const char* label) +companion_proxy_error_t companion_proxy_client_start_service(idevice_t device, companion_proxy_client_t * client, const char* label)  {  	companion_proxy_error_t err = COMPANION_PROXY_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, COMPANION_PROXY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(companion_proxy_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_free(companion_proxy_client_t client) +companion_proxy_error_t companion_proxy_client_free(companion_proxy_client_t client)  {  	if (!client)  		return COMPANION_PROXY_E_INVALID_ARG; @@ -116,7 +116,7 @@ LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_free(compani  	return err;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_send(companion_proxy_client_t client, plist_t plist) +companion_proxy_error_t companion_proxy_send(companion_proxy_client_t client, plist_t plist)  {  	companion_proxy_error_t res = COMPANION_PROXY_E_UNKNOWN_ERROR; @@ -129,7 +129,7 @@ LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_send(companion_prox  	return res;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_receive(companion_proxy_client_t client, plist_t * plist) +companion_proxy_error_t companion_proxy_receive(companion_proxy_client_t client, plist_t * plist)  {  	companion_proxy_error_t res = COMPANION_PROXY_E_UNKNOWN_ERROR;  	plist_t outplist = NULL; @@ -143,7 +143,7 @@ LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_receive(companion_p  	return res;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_get_device_registry(companion_proxy_client_t client, plist_t* paired_devices) +companion_proxy_error_t companion_proxy_get_device_registry(companion_proxy_client_t client, plist_t* paired_devices)  {  	if (!client || !paired_devices) {  		return COMPANION_PROXY_E_INVALID_ARG; @@ -226,7 +226,7 @@ static void* companion_proxy_event_thread(void* arg)  	return NULL;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_start_listening_for_devices(companion_proxy_client_t client, companion_proxy_device_event_cb_t callback, void* userdata) +companion_proxy_error_t companion_proxy_start_listening_for_devices(companion_proxy_client_t client, companion_proxy_device_event_cb_t callback, void* userdata)  {  	if (!client || !client->parent || !callback) {  		return COMPANION_PROXY_E_INVALID_ARG; @@ -252,7 +252,7 @@ LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_start_listening_for  	return res;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_stop_listening_for_devices(companion_proxy_client_t client) +companion_proxy_error_t companion_proxy_stop_listening_for_devices(companion_proxy_client_t client)  {  	property_list_service_client_t parent = client->parent;  	client->parent = NULL; @@ -266,7 +266,7 @@ LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_stop_listening_for_  	return COMPANION_PROXY_E_SUCCESS;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_get_value_from_registry(companion_proxy_client_t client, const char* companion_udid, const char* key, plist_t* value) +companion_proxy_error_t companion_proxy_get_value_from_registry(companion_proxy_client_t client, const char* companion_udid, const char* key, plist_t* value)  {  	if (!client || !companion_udid || !key || !value) {  		return COMPANION_PROXY_E_INVALID_ARG; @@ -310,7 +310,7 @@ LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_get_value_from_regi  	return res;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_start_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port, const char* service_name, uint16_t* forward_port, plist_t options) +companion_proxy_error_t companion_proxy_start_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port, const char* service_name, uint16_t* forward_port, plist_t options)  {  	if (!client) {  		return COMPANION_PROXY_E_INVALID_ARG; @@ -353,7 +353,7 @@ LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_start_forwarding_se  	return res;  } -LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_stop_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port) +companion_proxy_error_t companion_proxy_stop_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port)  {  	if (!client) {  		return COMPANION_PROXY_E_INVALID_ARG; diff --git a/src/companion_proxy.h b/src/companion_proxy.h index 0226640..e36932a 100644 --- a/src/companion_proxy.h +++ b/src/companion_proxy.h @@ -22,6 +22,7 @@  #ifndef __COMPANION_PROXY_H  #define __COMPANION_PROXY_H +#include "idevice.h"  #include "libimobiledevice/companion_proxy.h"  #include "property_list_service.h"  #include <libimobiledevice-glue/thread.h> diff --git a/src/debugserver.c b/src/debugserver.c index 39c1bdc..74ade8a 100644 --- a/src/debugserver.c +++ b/src/debugserver.c @@ -64,7 +64,7 @@ static debugserver_error_t debugserver_error(service_error_t err)  	return DEBUGSERVER_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_new(idevice_t device, lockdownd_service_descriptor_t service, debugserver_client_t* client) +debugserver_error_t debugserver_client_new(idevice_t device, lockdownd_service_descriptor_t service, debugserver_client_t* client)  {  	*client = NULL; @@ -98,7 +98,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_new(idevice_t device  	return DEBUGSERVER_E_SUCCESS;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_start_service(idevice_t device, debugserver_client_t * client, const char* label) +debugserver_error_t debugserver_client_start_service(idevice_t device, debugserver_client_t * client, const char* label)  {  	debugserver_error_t err = DEBUGSERVER_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, DEBUGSERVER_SECURE_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(debugserver_client_new), &err); @@ -109,7 +109,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_start_service(idevic  	return err;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_free(debugserver_client_t client) +debugserver_error_t debugserver_client_free(debugserver_client_t client)  {  	if (!client)  		return DEBUGSERVER_E_INVALID_ARG; @@ -121,7 +121,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_free(debugserver_cli  	return err;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_send(debugserver_client_t client, const char* data, uint32_t size, uint32_t *sent) +debugserver_error_t debugserver_client_send(debugserver_client_t client, const char* data, uint32_t size, uint32_t *sent)  {  	debugserver_error_t res = DEBUGSERVER_E_UNKNOWN_ERROR;  	int bytes = 0; @@ -142,7 +142,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_send(debugserver_cli  	return res;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_with_timeout(debugserver_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout) +debugserver_error_t debugserver_client_receive_with_timeout(debugserver_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout)  {  	debugserver_error_t res = DEBUGSERVER_E_UNKNOWN_ERROR;  	int bytes = 0; @@ -162,7 +162,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_with_timeout  	return (bytes > 0) ? DEBUGSERVER_E_SUCCESS : res;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive(debugserver_client_t client, char* data, uint32_t size, uint32_t *received) +debugserver_error_t debugserver_client_receive(debugserver_client_t client, char* data, uint32_t size, uint32_t *received)  {  	debugserver_error_t res = DEBUGSERVER_E_UNKNOWN_ERROR;  	do { @@ -172,7 +172,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive(debugserver_  	return res;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_command_new(const char* name, int argc, char* argv[], debugserver_command_t* command) +debugserver_error_t debugserver_command_new(const char* name, int argc, char* argv[], debugserver_command_t* command)  {  	int i;  	debugserver_command_t tmp = (debugserver_command_t) malloc(sizeof(struct debugserver_command_private)); @@ -197,7 +197,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_command_new(const char* nam  	return DEBUGSERVER_E_SUCCESS;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_command_free(debugserver_command_t command) +debugserver_error_t debugserver_command_free(debugserver_command_t command)  {  	int i;  	debugserver_error_t res = DEBUGSERVER_E_UNKNOWN_ERROR; @@ -275,7 +275,7 @@ static int debugserver_response_is_checksum_valid(const char* response, uint32_t  	return 1;  } -LIBIMOBILEDEVICE_API void debugserver_encode_string(const char* buffer, char** encoded_buffer, uint32_t* encoded_length) +void debugserver_encode_string(const char* buffer, char** encoded_buffer, uint32_t* encoded_length)  {  	uint32_t position;  	uint32_t index; @@ -291,7 +291,7 @@ LIBIMOBILEDEVICE_API void debugserver_encode_string(const char* buffer, char** e  	}  } -LIBIMOBILEDEVICE_API void debugserver_decode_string(const char *encoded_buffer, size_t encoded_length, char** buffer) +void debugserver_decode_string(const char *encoded_buffer, size_t encoded_length, char** buffer)  {  	*buffer = malloc(sizeof(char) * ((encoded_length / 2)+1));  	char* t = *buffer; @@ -350,7 +350,7 @@ static debugserver_error_t debugserver_client_send_noack(debugserver_client_t cl  	return debugserver_client_send(client, "-", sizeof(char), NULL);  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_ack_mode(debugserver_client_t client, int enabled) +debugserver_error_t debugserver_client_set_ack_mode(debugserver_client_t client, int enabled)  {  	if (!client)  		return DEBUGSERVER_E_INVALID_ARG; @@ -362,7 +362,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_ack_mode(debugse  	return DEBUGSERVER_E_SUCCESS;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_receive_params(debugserver_client_t client, int (*cancel_receive)(), int receive_loop_timeout) +debugserver_error_t debugserver_client_set_receive_params(debugserver_client_t client, int (*cancel_receive)(), int receive_loop_timeout)  {  	if (!client)  		return DEBUGSERVER_E_INVALID_ARG; @@ -392,7 +392,7 @@ static debugserver_error_t debugserver_client_receive_internal_char(debugserver_  	return res;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_receive_response(debugserver_client_t client, char** response, size_t* response_size) +debugserver_error_t debugserver_client_receive_response(debugserver_client_t client, char** response, size_t* response_size)  {  	debugserver_error_t res = DEBUGSERVER_E_SUCCESS; @@ -503,7 +503,7 @@ cleanup:  	return res;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_send_command(debugserver_client_t client, debugserver_command_t command, char** response, size_t* response_size) +debugserver_error_t debugserver_client_send_command(debugserver_client_t client, debugserver_command_t command, char** response, size_t* response_size)  {  	debugserver_error_t res = DEBUGSERVER_E_SUCCESS;  	int i; @@ -559,7 +559,7 @@ cleanup:  	return res;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_environment_hex_encoded(debugserver_client_t client, const char* env, char** response) +debugserver_error_t debugserver_client_set_environment_hex_encoded(debugserver_client_t client, const char* env, char** response)  {  	if (!client || !env)  		return DEBUGSERVER_E_INVALID_ARG; @@ -578,7 +578,7 @@ LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_environment_hex_  	return result;  } -LIBIMOBILEDEVICE_API debugserver_error_t debugserver_client_set_argv(debugserver_client_t client, int argc, char* argv[], char** response) +debugserver_error_t debugserver_client_set_argv(debugserver_client_t client, int argc, char* argv[], char** response)  {  	if (!client || !argc)  		return DEBUGSERVER_E_INVALID_ARG; diff --git a/src/debugserver.h b/src/debugserver.h index ee3ba62..ce9c255 100644 --- a/src/debugserver.h +++ b/src/debugserver.h @@ -22,6 +22,7 @@  #ifndef _DEBUGSERVER_H  #define _DEBUGSERVER_H +#include "idevice.h"  #include "libimobiledevice/debugserver.h"  #include "service.h" diff --git a/src/device_link_service.h b/src/device_link_service.h index eae912a..0255b21 100644 --- a/src/device_link_service.h +++ b/src/device_link_service.h @@ -22,6 +22,7 @@  #ifndef __DEVICE_LINK_SERVICE_H  #define __DEVICE_LINK_SERVICE_H +#include "idevice.h"  #include "property_list_service.h"  /* Error Codes */ diff --git a/src/diagnostics_relay.c b/src/diagnostics_relay.c index 5444fcc..6ee3150 100644 --- a/src/diagnostics_relay.c +++ b/src/diagnostics_relay.c @@ -73,7 +73,7 @@ static int diagnostics_relay_check_result(plist_t dict)  	return ret;  } -LIBIMOBILEDEVICE_API 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_new(idevice_t device, lockdownd_service_descriptor_t service, diagnostics_relay_client_t *client)  {  	if (!device || !service || service->port == 0 || !client || *client) {  		return DIAGNOSTICS_RELAY_E_INVALID_ARG; @@ -93,14 +93,14 @@ LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_client_new(idev  	return DIAGNOSTICS_RELAY_E_SUCCESS;  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_client_start_service(idevice_t device, diagnostics_relay_client_t * client, const char* label) +diagnostics_relay_error_t diagnostics_relay_client_start_service(idevice_t device, diagnostics_relay_client_t * client, const char* label)  {  	diagnostics_relay_error_t err = DIAGNOSTICS_RELAY_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, DIAGNOSTICS_RELAY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(diagnostics_relay_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_client_free(diagnostics_relay_client_t client) +diagnostics_relay_error_t diagnostics_relay_client_free(diagnostics_relay_client_t client)  {  	if (!client)  		return DIAGNOSTICS_RELAY_E_INVALID_ARG; @@ -167,7 +167,7 @@ static diagnostics_relay_error_t diagnostics_relay_send(diagnostics_relay_client  	return ret;  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_goodbye(diagnostics_relay_client_t client) +diagnostics_relay_error_t diagnostics_relay_goodbye(diagnostics_relay_client_t client)  {  	if (!client)  		return DIAGNOSTICS_RELAY_E_INVALID_ARG; @@ -201,7 +201,7 @@ LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_goodbye(diagnos  	return ret;  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_sleep(diagnostics_relay_client_t client) +diagnostics_relay_error_t diagnostics_relay_sleep(diagnostics_relay_client_t client)  {  	if (!client)  		return DIAGNOSTICS_RELAY_E_INVALID_ARG; @@ -277,17 +277,17 @@ static diagnostics_relay_error_t internal_diagnostics_relay_action(diagnostics_r  	return ret;  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_restart(diagnostics_relay_client_t client, diagnostics_relay_action_t flags) +diagnostics_relay_error_t diagnostics_relay_restart(diagnostics_relay_client_t client, diagnostics_relay_action_t flags)  {  	return internal_diagnostics_relay_action(client, "Restart", flags);  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_shutdown(diagnostics_relay_client_t client, diagnostics_relay_action_t flags) +diagnostics_relay_error_t diagnostics_relay_shutdown(diagnostics_relay_client_t client, diagnostics_relay_action_t flags)  {  	return internal_diagnostics_relay_action(client, "Shutdown", flags);  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_request_diagnostics(diagnostics_relay_client_t client, const char* type, plist_t* diagnostics) +diagnostics_relay_error_t diagnostics_relay_request_diagnostics(diagnostics_relay_client_t client, const char* type, plist_t* diagnostics)  {  	if (!client || diagnostics == NULL)  		return DIAGNOSTICS_RELAY_E_INVALID_ARG; @@ -331,7 +331,7 @@ LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_request_diagnos  	return ret;  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_query_mobilegestalt(diagnostics_relay_client_t client, plist_t keys, plist_t* result) +diagnostics_relay_error_t diagnostics_relay_query_mobilegestalt(diagnostics_relay_client_t client, plist_t keys, plist_t* result)  {  	if (!client || plist_get_node_type(keys) != PLIST_ARRAY || result == NULL)  		return DIAGNOSTICS_RELAY_E_INVALID_ARG; @@ -376,7 +376,7 @@ LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_query_mobileges  	return ret;  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_query_ioregistry_entry(diagnostics_relay_client_t client, const char* entry_name, const char* entry_class, plist_t* result) +diagnostics_relay_error_t diagnostics_relay_query_ioregistry_entry(diagnostics_relay_client_t client, const char* entry_name, const char* entry_class, plist_t* result)  {  	if (!client || (entry_name == NULL && entry_class == NULL) || result == NULL)  		return DIAGNOSTICS_RELAY_E_INVALID_ARG; @@ -424,7 +424,7 @@ LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_query_ioregistr  	return ret;  } -LIBIMOBILEDEVICE_API diagnostics_relay_error_t diagnostics_relay_query_ioregistry_plane(diagnostics_relay_client_t client, const char* plane, plist_t* result) +diagnostics_relay_error_t diagnostics_relay_query_ioregistry_plane(diagnostics_relay_client_t client, const char* plane, plist_t* result)  {  	if (!client || plane == NULL || result == NULL)  		return DIAGNOSTICS_RELAY_E_INVALID_ARG; diff --git a/src/diagnostics_relay.h b/src/diagnostics_relay.h index 6d11ea1..3bb543a 100644 --- a/src/diagnostics_relay.h +++ b/src/diagnostics_relay.h @@ -22,6 +22,7 @@  #ifndef __DIAGNOSTICS_RELAY_H  #define __DIAGNOSTICS_RELAY_H +#include "idevice.h"  #include "libimobiledevice/diagnostics_relay.h"  #include "property_list_service.h" diff --git a/src/file_relay.c b/src/file_relay.c index aa77ae6..fbe7cbf 100644 --- a/src/file_relay.c +++ b/src/file_relay.c @@ -28,7 +28,7 @@  #include "property_list_service.h"  #include "common/debug.h" -LIBIMOBILEDEVICE_API 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_new(idevice_t device, lockdownd_service_descriptor_t service, file_relay_client_t *client)  {  	if (!device || !service || service->port == 0 || !client || *client) {  		return FILE_RELAY_E_INVALID_ARG; @@ -48,14 +48,14 @@ LIBIMOBILEDEVICE_API file_relay_error_t file_relay_client_new(idevice_t device,  	return FILE_RELAY_E_SUCCESS;  } -LIBIMOBILEDEVICE_API file_relay_error_t file_relay_client_start_service(idevice_t device, file_relay_client_t * client, const char* label) +file_relay_error_t file_relay_client_start_service(idevice_t device, file_relay_client_t * client, const char* label)  {  	file_relay_error_t err = FILE_RELAY_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, FILE_RELAY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(file_relay_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API file_relay_error_t file_relay_client_free(file_relay_client_t client) +file_relay_error_t file_relay_client_free(file_relay_client_t client)  {  	if (!client)  		return FILE_RELAY_E_INVALID_ARG; @@ -67,7 +67,7 @@ LIBIMOBILEDEVICE_API file_relay_error_t file_relay_client_free(file_relay_client  	return FILE_RELAY_E_SUCCESS;  } -LIBIMOBILEDEVICE_API file_relay_error_t file_relay_request_sources_timeout(file_relay_client_t client, const char **sources, idevice_connection_t *connection, unsigned int timeout) +file_relay_error_t file_relay_request_sources_timeout(file_relay_client_t client, const char **sources, idevice_connection_t *connection, unsigned int timeout)  {  	if (!client || !client->parent || !sources || !sources[0]) {  		return FILE_RELAY_E_INVALID_ARG; @@ -159,7 +159,7 @@ leave:  	return err;  } -LIBIMOBILEDEVICE_API file_relay_error_t file_relay_request_sources(file_relay_client_t client, const char **sources, idevice_connection_t *connection) +file_relay_error_t file_relay_request_sources(file_relay_client_t client, const char **sources, idevice_connection_t *connection)  {  	return file_relay_request_sources_timeout(client, sources, connection, 60000);  } diff --git a/src/file_relay.h b/src/file_relay.h index 626fab8..65bf460 100644 --- a/src/file_relay.h +++ b/src/file_relay.h @@ -22,6 +22,7 @@  #ifndef __FILE_RELAY_H  #define __FILE_RELAY_H +#include "idevice.h"  #include "libimobiledevice/file_relay.h"  #include "property_list_service.h" diff --git a/src/heartbeat.c b/src/heartbeat.c index 9a527cc..3945d73 100644 --- a/src/heartbeat.c +++ b/src/heartbeat.c @@ -62,7 +62,7 @@ static heartbeat_error_t heartbeat_error(property_list_service_error_t err)  	return HEARTBEAT_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_client_new(idevice_t device, lockdownd_service_descriptor_t service, heartbeat_client_t * client) +heartbeat_error_t heartbeat_client_new(idevice_t device, lockdownd_service_descriptor_t service, heartbeat_client_t * client)  {  	*client = NULL; @@ -89,14 +89,14 @@ LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_client_new(idevice_t device, lo  	return 0;  } -LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_client_start_service(idevice_t device, heartbeat_client_t * client, const char* label) +heartbeat_error_t heartbeat_client_start_service(idevice_t device, heartbeat_client_t * client, const char* label)  {  	heartbeat_error_t err = HEARTBEAT_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, HEARTBEAT_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(heartbeat_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_client_free(heartbeat_client_t client) +heartbeat_error_t heartbeat_client_free(heartbeat_client_t client)  {  	if (!client)  		return HEARTBEAT_E_INVALID_ARG; @@ -107,7 +107,7 @@ LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_client_free(heartbeat_client_t  	return err;  } -LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_send(heartbeat_client_t client, plist_t plist) +heartbeat_error_t heartbeat_send(heartbeat_client_t client, plist_t plist)  {  	heartbeat_error_t res = HEARTBEAT_E_UNKNOWN_ERROR; @@ -122,12 +122,12 @@ LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_send(heartbeat_client_t client,  	return res;  } -LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_receive(heartbeat_client_t client, plist_t * plist) +heartbeat_error_t heartbeat_receive(heartbeat_client_t client, plist_t * plist)  {  	return heartbeat_receive_with_timeout(client, plist, 1000);  } -LIBIMOBILEDEVICE_API heartbeat_error_t heartbeat_receive_with_timeout(heartbeat_client_t client, plist_t * plist, uint32_t timeout_ms) +heartbeat_error_t heartbeat_receive_with_timeout(heartbeat_client_t client, plist_t * plist, uint32_t timeout_ms)  {  	heartbeat_error_t res = HEARTBEAT_E_UNKNOWN_ERROR;  	plist_t outplist = NULL; diff --git a/src/heartbeat.h b/src/heartbeat.h index f648681..379ecc1 100644 --- a/src/heartbeat.h +++ b/src/heartbeat.h @@ -22,6 +22,7 @@  #ifndef __HEARTBEAT_H  #define __HEARTBEAT_H +#include "idevice.h"  #include "libimobiledevice/heartbeat.h"  #include "property_list_service.h" diff --git a/src/house_arrest.c b/src/house_arrest.c index ac92130..06068c6 100644 --- a/src/house_arrest.c +++ b/src/house_arrest.c @@ -24,7 +24,11 @@  #endif  #include <string.h>  #include <stdlib.h> + +#ifndef _MSC_VER  #include <unistd.h> +#endif +  #include <plist/plist.h>  #include "house_arrest.h" @@ -58,7 +62,7 @@ static house_arrest_error_t house_arrest_error(property_list_service_error_t err  	return HOUSE_ARREST_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API 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_new(idevice_t device, lockdownd_service_descriptor_t service, house_arrest_client_t *client)  {  	property_list_service_client_t plistclient = NULL;  	house_arrest_error_t err = house_arrest_error(property_list_service_client_new(device, service, &plistclient)); @@ -74,14 +78,14 @@ LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_client_new(idevice_t devi  	return HOUSE_ARREST_E_SUCCESS;  } -LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_client_start_service(idevice_t device, house_arrest_client_t * client, const char* label) +house_arrest_error_t house_arrest_client_start_service(idevice_t device, house_arrest_client_t * client, const char* label)  {  	house_arrest_error_t err = HOUSE_ARREST_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, HOUSE_ARREST_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(house_arrest_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_client_free(house_arrest_client_t client) +house_arrest_error_t house_arrest_client_free(house_arrest_client_t client)  {  	if (!client)  		return HOUSE_ARREST_E_INVALID_ARG; @@ -96,7 +100,7 @@ LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_client_free(house_arrest_  	return err;  } -LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_send_request(house_arrest_client_t client, plist_t dict) +house_arrest_error_t house_arrest_send_request(house_arrest_client_t client, plist_t dict)  {  	if (!client || !client->parent || !dict)  		return HOUSE_ARREST_E_INVALID_ARG; @@ -112,7 +116,7 @@ LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_send_request(house_arrest  	return res;  } -LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_send_command(house_arrest_client_t client, const char *command, const char *appid) +house_arrest_error_t house_arrest_send_command(house_arrest_client_t client, const char *command, const char *appid)  {  	if (!client || !client->parent || !command || !appid)  		return HOUSE_ARREST_E_INVALID_ARG; @@ -132,7 +136,7 @@ LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_send_command(house_arrest  	return res;  } -LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_get_result(house_arrest_client_t client, plist_t *dict) +house_arrest_error_t house_arrest_get_result(house_arrest_client_t client, plist_t *dict)  {  	if (!client || !client->parent)  		return HOUSE_ARREST_E_INVALID_ARG; @@ -150,7 +154,7 @@ LIBIMOBILEDEVICE_API house_arrest_error_t house_arrest_get_result(house_arrest_c  	return res;  } -LIBIMOBILEDEVICE_API afc_error_t afc_client_new_from_house_arrest_client(house_arrest_client_t client, afc_client_t *afc_client) +afc_error_t afc_client_new_from_house_arrest_client(house_arrest_client_t client, afc_client_t *afc_client)  {  	if (!client || !client->parent || (client->mode == HOUSE_ARREST_CLIENT_MODE_AFC)) {  		return AFC_E_INVALID_ARG; diff --git a/src/house_arrest.h b/src/house_arrest.h index 387594f..5612a29 100644 --- a/src/house_arrest.h +++ b/src/house_arrest.h @@ -22,6 +22,7 @@  #ifndef __HOUSE_ARREST_H  #define __HOUSE_ARREST_H +#include "idevice.h"  #include "libimobiledevice/house_arrest.h"  #include "property_list_service.h" diff --git a/src/idevice.c b/src/idevice.c index 719cd28..0af27fd 100644 --- a/src/idevice.c +++ b/src/idevice.c @@ -30,7 +30,7 @@  #include <errno.h>  #include <time.h> -#ifdef WIN32 +#ifdef _WIN32  #include <winsock2.h>  #include <ws2tcpip.h>  #include <windows.h> @@ -124,32 +124,32 @@ static void id_function(CRYPTO_THREADID *thread)  #endif  #endif /* HAVE_OPENSSL */ -static void internal_idevice_init(void) -{ -#if defined(HAVE_OPENSSL) -#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) -	int i; -	SSL_library_init(); - -	mutex_buf = malloc(CRYPTO_num_locks() * sizeof(mutex_t)); -	if (!mutex_buf) -		return; -	for (i = 0; i < CRYPTO_num_locks(); i++) -		mutex_init(&mutex_buf[i]); - -#if OPENSSL_VERSION_NUMBER < 0x10000000L -	CRYPTO_set_id_callback(id_function); +// Reference: https://stackoverflow.com/a/2390626/1806760 +// Initializer/finalizer sample for MSVC and GCC/Clang. +// 2010-2016 Joe Lowe. Released into the public domain. + +#ifdef __cplusplus +    #define INITIALIZER(f) \ +        static void f(void); \ +        struct f##_t_ { f##_t_(void) { f(); } }; static f##_t_ f##_; \ +        static void f(void) +#elif defined(_MSC_VER) +    #pragma section(".CRT$XCU",read) +    #define INITIALIZER2_(f,p) \ +        static void f(void); \ +        __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ +        __pragma(comment(linker,"/include:" p #f "_")) \ +        static void f(void) +    #ifdef _WIN64 +        #define INITIALIZER(f) INITIALIZER2_(f,"") +    #else +        #define INITIALIZER(f) INITIALIZER2_(f,"_") +    #endif  #else -	CRYPTO_THREADID_set_callback(id_function); -#endif -	CRYPTO_set_locking_callback(locking_function); -#endif -#elif defined(HAVE_GNUTLS) -	gnutls_global_init(); -#elif defined(HAVE_MBEDTLS) -	// NO-OP +    #define INITIALIZER(f) \ +        static void f(void) __attribute__((__constructor__)); \ +        static void f(void)  #endif -}  static void internal_idevice_deinit(void)  { @@ -181,43 +181,41 @@ static void internal_idevice_deinit(void)  #endif  } -static thread_once_t init_once = THREAD_ONCE_INIT; -static thread_once_t deinit_once = THREAD_ONCE_INIT; +INITIALIZER(internal_idevice_init) +{ +#if defined(HAVE_OPENSSL) +#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) +	int i; +	SSL_library_init(); -#ifndef HAVE_ATTRIBUTE_CONSTRUCTOR -  #if defined(__llvm__) || defined(__GNUC__) -    #define HAVE_ATTRIBUTE_CONSTRUCTOR -  #endif -#endif +	mutex_buf = malloc(CRYPTO_num_locks() * sizeof(mutex_t)); +	if (!mutex_buf) +		return; +	for (i = 0; i < CRYPTO_num_locks(); i++) +		mutex_init(&mutex_buf[i]); -#ifdef HAVE_ATTRIBUTE_CONSTRUCTOR -static void __attribute__((constructor)) libimobiledevice_initialize(void) -{ -	thread_once(&init_once, internal_idevice_init); +#if OPENSSL_VERSION_NUMBER < 0x10000000L +	CRYPTO_set_id_callback(id_function); +#else +	CRYPTO_THREADID_set_callback(id_function); +#endif +	CRYPTO_set_locking_callback(locking_function); +#endif +#elif defined(HAVE_GNUTLS) +	gnutls_global_init(); +#elif defined(HAVE_MBEDTLS) +	// NO-OP +#endif +	atexit(internal_idevice_deinit);  } -static void __attribute__((destructor)) libimobiledevice_deinitialize(void) +const char* libimobiledevice_version()  { -	thread_once(&deinit_once, internal_idevice_deinit); -} -#elif defined(WIN32) -BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) -{ -	switch (dwReason) { -	case DLL_PROCESS_ATTACH: -		thread_once(&init_once,	internal_idevice_init); -		break; -	case DLL_PROCESS_DETACH: -		thread_once(&deinit_once, internal_idevice_deinit); -		break; -	default: -		break; -	} -	return 1; -} -#else -#warning No compiler support for constructor/destructor attributes, some features might not be available. +#ifndef PACKAGE_VERSION +#error PACKAGE_VERSION is not defined!  #endif +	return PACKAGE_VERSION; +}  struct idevice_subscription_context {  	idevice_event_cb_t callback; @@ -248,7 +246,7 @@ static void usbmux_event_cb(const usbmuxd_event_t *event, void *user_data)  	}  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_events_subscribe(idevice_subscription_context_t *context, idevice_event_cb_t callback, void *user_data) +idevice_error_t idevice_events_subscribe(idevice_subscription_context_t *context, idevice_event_cb_t callback, void *user_data)  {  	if (!context || !callback) {  		return IDEVICE_E_INVALID_ARG; @@ -270,7 +268,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_events_subscribe(idevice_subscripti  	return IDEVICE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_events_unsubscribe(idevice_subscription_context_t context) +idevice_error_t idevice_events_unsubscribe(idevice_subscription_context_t context)  {  	if (!context) {  		return IDEVICE_E_INVALID_ARG; @@ -287,7 +285,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_events_unsubscribe(idevice_subscrip  	return IDEVICE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data) +idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data)  {  	if (event_ctx) {  		idevice_events_unsubscribe(event_ctx); @@ -295,7 +293,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_event_subscribe(idevice_event_cb_t  	return idevice_events_subscribe(&event_ctx, callback, user_data);  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_event_unsubscribe(void) +idevice_error_t idevice_event_unsubscribe(void)  {  	if (!event_ctx) {  		return IDEVICE_E_SUCCESS; @@ -304,7 +302,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_event_unsubscribe(void)  	return idevice_events_unsubscribe(event_ctx);  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list_extended(idevice_info_t **devices, int *count) +idevice_error_t idevice_get_device_list_extended(idevice_info_t **devices, int *count)  {  	usbmuxd_device_info_t *dev_list; @@ -359,7 +357,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list_extended(idevice_in  	return IDEVICE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_device_list_extended_free(idevice_info_t *devices) +idevice_error_t idevice_device_list_extended_free(idevice_info_t *devices)  {  	if (devices) {  		int i = 0; @@ -374,7 +372,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_device_list_extended_free(idevice_i  	return IDEVICE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list(char ***devices, int *count) +idevice_error_t idevice_get_device_list(char ***devices, int *count)  {  	usbmuxd_device_info_t *dev_list; @@ -406,7 +404,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list(char ***devices, in  	return IDEVICE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_device_list_free(char **devices) +idevice_error_t idevice_device_list_free(char **devices)  {  	if (devices) {  		int i = 0; @@ -419,7 +417,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_device_list_free(char **devices)  	return IDEVICE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API void idevice_set_debug_level(int level) +void idevice_set_debug_level(int level)  {  	internal_set_debug_level(level);  } @@ -472,7 +470,7 @@ static idevice_t idevice_from_mux_device(usbmuxd_device_info_t *muxdev)  	return device;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_new_with_options(idevice_t * device, const char *udid, enum idevice_options options) +idevice_error_t idevice_new_with_options(idevice_t * device, const char *udid, enum idevice_options options)  {  	usbmuxd_device_info_t muxdev;  	int usbmux_options = 0; @@ -496,12 +494,12 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_new_with_options(idevice_t * device  	return IDEVICE_E_NO_DEVICE;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_new(idevice_t * device, const char *udid) +idevice_error_t idevice_new(idevice_t * device, const char *udid)  {  	return idevice_new_with_options(device, udid, 0);  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_free(idevice_t device) +idevice_error_t idevice_free(idevice_t device)  {  	if (!device)  		return IDEVICE_E_INVALID_ARG; @@ -518,7 +516,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_free(idevice_t device)  	return ret;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t port, idevice_connection_t *connection) +idevice_error_t idevice_connect(idevice_t device, uint16_t port, idevice_connection_t *connection)  {  	if (!device) {  		return IDEVICE_E_INVALID_ARG; @@ -540,7 +538,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t  		}  		idevice_connection_t new_connection = (idevice_connection_t)malloc(sizeof(struct idevice_connection_private));  		new_connection->type = CONNECTION_USBMUXD; -		new_connection->data = (void*)(long)sfd; +		new_connection->data = (void*)(uintptr_t)sfd;  		new_connection->ssl_data = NULL;  		new_connection->device = device;  		new_connection->ssl_recv_timeout = (unsigned int)-1; @@ -585,7 +583,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t  		idevice_connection_t new_connection = (idevice_connection_t)malloc(sizeof(struct idevice_connection_private));  		new_connection->type = CONNECTION_NETWORK; -		new_connection->data = (void*)(long)sfd; +		new_connection->data = (void*)(uintptr_t)sfd;  		new_connection->ssl_data = NULL;  		new_connection->device = device;  		new_connection->ssl_recv_timeout = (unsigned int)-1; @@ -599,7 +597,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t  	return IDEVICE_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_disconnect(idevice_connection_t connection) +idevice_error_t idevice_disconnect(idevice_connection_t connection)  {  	if (!connection) {  		return IDEVICE_E_INVALID_ARG; @@ -610,11 +608,11 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_disconnect(idevice_connection_t con  	}  	idevice_error_t result = IDEVICE_E_UNKNOWN_ERROR;  	if (connection->type == CONNECTION_USBMUXD) { -		usbmuxd_disconnect((int)(long)connection->data); +		usbmuxd_disconnect((int)(uintptr_t)connection->data);  		connection->data = NULL;  		result = IDEVICE_E_SUCCESS;  	} else if (connection->type == CONNECTION_NETWORK) { -		socket_close((int)(long)connection->data); +		socket_close((int)(uintptr_t)connection->data);  		connection->data = NULL;  		result = IDEVICE_E_SUCCESS;  	} else { @@ -639,7 +637,7 @@ static idevice_error_t internal_connection_send(idevice_connection_t connection,  	if (connection->type == CONNECTION_USBMUXD) {  		int res;  		do { -			res = usbmuxd_send((int)(long)connection->data, data, len, sent_bytes); +			res = usbmuxd_send((int)(uintptr_t)connection->data, data, len, sent_bytes);  		} while (res == -EAGAIN);  		if (res < 0) {  			debug_info("ERROR: usbmuxd_send returned %d (%s)", res, strerror(-res)); @@ -648,7 +646,7 @@ static idevice_error_t internal_connection_send(idevice_connection_t connection,  		return IDEVICE_E_SUCCESS;  	}  	if (connection->type == CONNECTION_NETWORK) { -		int s = socket_send((int)(long)connection->data, (void*)data, len); +		int s = socket_send((int)(uintptr_t)connection->data, (void*)data, len);  		if (s < 0) {  			*sent_bytes = 0;  			return IDEVICE_E_UNKNOWN_ERROR; @@ -662,7 +660,7 @@ static idevice_error_t internal_connection_send(idevice_connection_t connection,  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_send(idevice_connection_t connection, const char *data, uint32_t len, uint32_t *sent_bytes) +idevice_error_t idevice_connection_send(idevice_connection_t connection, const char *data, uint32_t len, uint32_t *sent_bytes)  {  	if (!connection || !data  #if defined(HAVE_OPENSSL) || defined(HAVE_GNUTLS) @@ -755,7 +753,7 @@ static idevice_error_t internal_connection_receive_timeout(idevice_connection_t  	}  	if (connection->type == CONNECTION_USBMUXD) { -		int conn_error = usbmuxd_recv_timeout((int)(long)connection->data, data, len, recv_bytes, timeout); +		int conn_error = usbmuxd_recv_timeout((int)(uintptr_t)connection->data, data, len, recv_bytes, timeout);  		idevice_error_t error = socket_recv_to_idevice_error(conn_error, len, *recv_bytes);  		if (error == IDEVICE_E_UNKNOWN_ERROR) {  			debug_info("ERROR: usbmuxd_recv_timeout returned %d (%s)", conn_error, strerror(-conn_error)); @@ -763,7 +761,7 @@ static idevice_error_t internal_connection_receive_timeout(idevice_connection_t  		return error;  	}  	if (connection->type == CONNECTION_NETWORK) { -		int res = socket_receive_timeout((int)(long)connection->data, data, len, 0, timeout); +		int res = socket_receive_timeout((int)(uintptr_t)connection->data, data, len, 0, timeout);  		idevice_error_t error = socket_recv_to_idevice_error(res, 0, 0);  		if (error == IDEVICE_E_SUCCESS) {  			*recv_bytes = (uint32_t)res; @@ -777,7 +775,7 @@ static idevice_error_t internal_connection_receive_timeout(idevice_connection_t  	return IDEVICE_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_receive_timeout(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout) +idevice_error_t idevice_connection_receive_timeout(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout)  {  	if (!connection  #if defined(HAVE_OPENSSL) || defined(HAVE_GNUTLS) @@ -855,7 +853,7 @@ static idevice_error_t internal_connection_receive(idevice_connection_t connecti  	}  	if (connection->type == CONNECTION_USBMUXD) { -		int res = usbmuxd_recv((int)(long)connection->data, data, len, recv_bytes); +		int res = usbmuxd_recv((int)(uintptr_t)connection->data, data, len, recv_bytes);  		if (res < 0) {  			debug_info("ERROR: usbmuxd_recv returned %d (%s)", res, strerror(-res));  			return IDEVICE_E_UNKNOWN_ERROR; @@ -863,7 +861,7 @@ static idevice_error_t internal_connection_receive(idevice_connection_t connecti  		return IDEVICE_E_SUCCESS;  	}  	if (connection->type == CONNECTION_NETWORK) { -		int res = socket_receive((int)(long)connection->data, data, len); +		int res = socket_receive((int)(uintptr_t)connection->data, data, len);  		if (res < 0) {  			debug_info("ERROR: socket_receive returned %d (%s)", res, strerror(-res));  			return IDEVICE_E_UNKNOWN_ERROR; @@ -876,7 +874,7 @@ static idevice_error_t internal_connection_receive(idevice_connection_t connecti  	return IDEVICE_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_receive(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes) +idevice_error_t idevice_connection_receive(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes)  {  	if (!connection  #if defined(HAVE_OPENSSL) || defined(HAVE_GNUTLS) @@ -909,18 +907,18 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_receive(idevice_connecti  	return internal_connection_receive(connection, data, len, recv_bytes);  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_get_fd(idevice_connection_t connection, int *fd) +idevice_error_t idevice_connection_get_fd(idevice_connection_t connection, int *fd)  {  	if (!connection || !fd) {  		return IDEVICE_E_INVALID_ARG;  	}  	if (connection->type == CONNECTION_USBMUXD) { -		*fd = (int)(long)connection->data; +		*fd = (int)(uintptr_t)connection->data;  		return IDEVICE_E_SUCCESS;  	}  	if (connection->type == CONNECTION_NETWORK) { -		*fd = (int)(long)connection->data; +		*fd = (int)(uintptr_t)connection->data;  		return IDEVICE_E_SUCCESS;  	} @@ -928,7 +926,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_get_fd(idevice_connectio  	return IDEVICE_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle) +idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle)  {  	if (!device || !handle)  		return IDEVICE_E_INVALID_ARG; @@ -937,7 +935,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32  	return IDEVICE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_get_udid(idevice_t device, char **udid) +idevice_error_t idevice_get_udid(idevice_t device, char **udid)  {  	if (!device || !udid)  		return IDEVICE_E_INVALID_ARG; @@ -948,6 +946,20 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_get_udid(idevice_t device, char **u  	return IDEVICE_E_SUCCESS;  } +unsigned int idevice_get_device_version(idevice_t device) +{ +	if (!device) { +		return 0; +	} +	if (!device->version) { +		lockdownd_client_t lockdown = NULL; +		lockdownd_client_new(device, &lockdown, NULL); +		// we don't handle any errors here. We should have the product version cached now. +		lockdownd_client_free(lockdown); +	} +	return device->version; +} +  #if defined(HAVE_OPENSSL) || defined(HAVE_GNUTLS)  typedef ssize_t ssl_cb_ret_type_t;  #elif defined(HAVE_MBEDTLS) @@ -1067,13 +1079,14 @@ static long ssl_idevice_bio_callback(BIO *b, int oper, const char *argp, int arg  	idevice_connection_t conn = (idevice_connection_t)BIO_get_callback_arg(b);  #if OPENSSL_VERSION_NUMBER < 0x30000000L  	size_t len = (size_t)argi; -	size_t *processed = (size_t*)&bytes;  #endif  	switch (oper) {  	case (BIO_CB_READ|BIO_CB_RETURN):  		if (argp) {  			bytes = internal_ssl_read(conn, (char *)argp, len); -			*processed = bytes; +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +			*processed = (size_t)(bytes < 0) ? 0 : bytes; +#endif  			return (long)bytes;  		}  		return 0; @@ -1082,7 +1095,9 @@ static long ssl_idevice_bio_callback(BIO *b, int oper, const char *argp, int arg  		// fallthrough  	case (BIO_CB_WRITE|BIO_CB_RETURN):  		bytes = internal_ssl_write(conn, argp, len); -		*processed = bytes; +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +		*processed = (size_t)(bytes < 0) ? 0 : bytes; +#endif  		return (long)bytes;  	default:  		return retvalue; @@ -1186,7 +1201,7 @@ static int _mbedtls_f_rng(void* p_rng, unsigned char* buf, size_t len)  }  #endif -LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection) +idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection)  {  	if (!connection || connection->ssl_data)  		return IDEVICE_E_INVALID_ARG; @@ -1223,14 +1238,15 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne  		return ret;  	} -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) +#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) || \ +	(defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER >= 0x3060000fL))  	SSL_CTX_set_security_level(ssl_ctx, 0);  #endif  #if OPENSSL_VERSION_NUMBER < 0x10100002L || \  	(defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x2060000fL))  	/* force use of TLSv1 for older devices */ -	if (connection->device->version < DEVICE_VERSION(10,0,0)) { +	if (connection->device->version < IDEVICE_DEVICE_VERSION(10,0,0)) {  #ifdef SSL_OP_NO_TLSv1_1  		SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_TLSv1_1);  #endif @@ -1243,8 +1259,22 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne  	}  #else  	SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_VERSION); -	if (connection->device->version < DEVICE_VERSION(10,0,0)) { +	if (connection->device->version < IDEVICE_DEVICE_VERSION(10,0,0)) {  		SSL_CTX_set_max_proto_version(ssl_ctx, TLS1_VERSION); +		if (connection->device->version == 0) { +			/* +				iOS 1 doesn't understand TLS1_VERSION, it can only speak SSL3_VERSION. +				However, modern OpenSSL is usually compiled without SSLv3 support. +				So if we set min_proto_version to SSL3_VERSION on an OpenSSL instance which doesn't support it, +				it will just ignore min_proto_version altogether and fall back to an even higher version. +				To avoid accidentally breaking iOS 2.0+, we set min version to 0 instead. +				Here is what documentation says: +					Setting the minimum or maximum version to 0, +					will enable protocol versions down to the lowest version, +					or up to the highest version supported by the library, respectively. +			*/ +			SSL_CTX_set_min_proto_version(ssl_ctx, 0); +		}  	}  #endif  #if OPENSSL_VERSION_NUMBER >= 0x30000000L @@ -1315,7 +1345,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne  		if (ssl_error == 0 || ssl_error != SSL_ERROR_WANT_READ) {  			break;  		} -#ifdef WIN32 +#ifdef _WIN32  		Sleep(100);  #else  		struct timespec ts = { 0, 100000000 }; @@ -1474,12 +1504,12 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne  	return ret;  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_disable_ssl(idevice_connection_t connection) +idevice_error_t idevice_connection_disable_ssl(idevice_connection_t connection)  {  	return idevice_connection_disable_bypass_ssl(connection, 0);  } -LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_disable_bypass_ssl(idevice_connection_t connection, uint8_t sslBypass) +idevice_error_t idevice_connection_disable_bypass_ssl(idevice_connection_t connection, uint8_t sslBypass)  {  	if (!connection)  		return IDEVICE_E_INVALID_ARG; @@ -1521,3 +1551,28 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_disable_bypass_ssl(idevi  	return IDEVICE_E_SUCCESS;  } + +const char* idevice_strerror(idevice_error_t err) +{ +	switch (err) { +		case IDEVICE_E_SUCCESS: +			return "Success"; +		case IDEVICE_E_INVALID_ARG: +			return "Invalid argument"; +		case IDEVICE_E_UNKNOWN_ERROR: +			return "Unknown Error"; +		case IDEVICE_E_NO_DEVICE: +			return "No device"; +		case IDEVICE_E_NOT_ENOUGH_DATA: +			return "Not enough data"; +		case IDEVICE_E_CONNREFUSED: +			return "Connection refused"; +		case IDEVICE_E_SSL_ERROR: +			return "SSL error"; +		case IDEVICE_E_TIMEOUT: +			return "Timeout"; +		default: +			break; +	} +	return "Unknown Error"; +} diff --git a/src/idevice.h b/src/idevice.h index 2509e48..e05338e 100644 --- a/src/idevice.h +++ b/src/idevice.h @@ -37,21 +37,21 @@  #include <mbedtls/ctr_drbg.h>  #endif -#ifdef WIN32 -#define LIBIMOBILEDEVICE_API __declspec( dllexport ) +#ifdef LIBIMOBILEDEVICE_STATIC +  #define LIBIMOBILEDEVICE_API +#elif defined(_WIN32) +  #define LIBIMOBILEDEVICE_API __declspec( dllexport )  #else -#ifdef HAVE_FVISIBILITY -#define LIBIMOBILEDEVICE_API __attribute__((visibility("default"))) -#else -#define LIBIMOBILEDEVICE_API -#endif +  #if __GNUC__ >= 4 +    #define LIBIMOBILEDEVICE_API __attribute__((visibility("default"))) +  #else +    #define LIBIMOBILEDEVICE_API +  #endif  #endif  #include "common/userpref.h"  #include "libimobiledevice/libimobiledevice.h" -#define DEVICE_VERSION(maj, min, patch) (((maj & 0xFF) << 16) | ((min & 0xFF) << 8) | (patch & 0xFF)) -  #define DEVICE_CLASS_IPHONE  1  #define DEVICE_CLASS_IPAD    2  #define DEVICE_CLASS_IPOD    3 diff --git a/src/installation_proxy.c b/src/installation_proxy.c index 9602876..bb6ef01 100644 --- a/src/installation_proxy.c +++ b/src/installation_proxy.c @@ -26,7 +26,11 @@  #include <string.h>  #include <stdlib.h>  #include <inttypes.h> + +#ifndef _MSC_VER  #include <unistd.h> +#endif +  #include <plist/plist.h>  #include "installation_proxy.h" @@ -232,7 +236,7 @@ static instproxy_error_t instproxy_error(property_list_service_error_t err)  	return INSTPROXY_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, instproxy_client_t *client) +instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, instproxy_client_t *client)  {  	property_list_service_client_t plistclient = NULL;  	instproxy_error_t err = instproxy_error(property_list_service_client_new(device, service, &plistclient)); @@ -249,14 +253,14 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_client_new(idevice_t device, lo  	return INSTPROXY_E_SUCCESS;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_client_start_service(idevice_t device, instproxy_client_t * client, const char* label) +instproxy_error_t instproxy_client_start_service(idevice_t device, instproxy_client_t * client, const char* label)  { -	instproxy_error_t err = INSTPROXY_E_UNKNOWN_ERROR; +	int32_t err = INSTPROXY_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, INSTPROXY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(instproxy_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_client_free(instproxy_client_t client) +instproxy_error_t instproxy_client_free(instproxy_client_t client)  {  	if (!client)  		return INSTPROXY_E_INVALID_ARG; @@ -525,7 +529,7 @@ static instproxy_error_t instproxy_perform_command(instproxy_client_t client, pl  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_browse_with_callback(instproxy_client_t client, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) +instproxy_error_t instproxy_browse_with_callback(instproxy_client_t client, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data)  {  	if (!client || !client->parent || !status_cb)  		return INSTPROXY_E_INVALID_ARG; @@ -566,7 +570,7 @@ static void instproxy_append_current_list_to_result_cb(plist_t command, plist_t  		plist_free(current_list);  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_browse(instproxy_client_t client, plist_t client_options, plist_t *result) +instproxy_error_t instproxy_browse(instproxy_client_t client, plist_t client_options, plist_t *result)  {  	if (!client || !client->parent || !result)  		return INSTPROXY_E_INVALID_ARG; @@ -603,7 +607,7 @@ static void instproxy_copy_lookup_result_cb(plist_t command, plist_t status, voi  	}  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_lookup(instproxy_client_t client, const char** appids, plist_t client_options, plist_t *result) +instproxy_error_t instproxy_lookup(instproxy_client_t client, const char** appids, plist_t client_options, plist_t *result)  {  	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR;  	int i = 0; @@ -650,7 +654,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_lookup(instproxy_client_t clien  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_install(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) +instproxy_error_t instproxy_install(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data)  {  	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; @@ -667,7 +671,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_install(instproxy_client_t clie  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) +instproxy_error_t instproxy_upgrade(instproxy_client_t client, const char *pkg_path, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data)  {  	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; @@ -684,7 +688,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_upgrade(instproxy_client_t clie  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_uninstall(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) +instproxy_error_t instproxy_uninstall(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data)  {  	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; @@ -701,7 +705,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_uninstall(instproxy_client_t cl  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_lookup_archives(instproxy_client_t client, plist_t client_options, plist_t *result) +instproxy_error_t instproxy_lookup_archives(instproxy_client_t client, plist_t client_options, plist_t *result)  {  	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; @@ -717,7 +721,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_lookup_archives(instproxy_clien  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) +instproxy_error_t instproxy_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data)  {  	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; @@ -734,7 +738,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_archive(instproxy_client_t clie  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) +instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data)  {  	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; @@ -751,7 +755,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_restore(instproxy_client_t clie  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) +instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data)  {  	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; @@ -768,7 +772,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_remove_archive(instproxy_client  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_check_capabilities_match(instproxy_client_t client, const char** capabilities, plist_t client_options, plist_t *result) +instproxy_error_t instproxy_check_capabilities_match(instproxy_client_t client, const char** capabilities, plist_t client_options, plist_t *result)  {  	if (!client || !capabilities || !result)  		return INSTPROXY_E_INVALID_ARG; @@ -805,7 +809,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_check_capabilities_match(instpr  	return res;  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_status_get_error(plist_t status, char **name, char** description, uint64_t* code) +instproxy_error_t instproxy_status_get_error(plist_t status, char **name, char** description, uint64_t* code)  {  	instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; @@ -843,7 +847,7 @@ LIBIMOBILEDEVICE_API instproxy_error_t instproxy_status_get_error(plist_t status  	return res;  } -LIBIMOBILEDEVICE_API void instproxy_status_get_name(plist_t status, char **name) +void instproxy_status_get_name(plist_t status, char **name)  {  	if (name) {  		plist_t node = plist_dict_get_item(status, "Status"); @@ -855,7 +859,7 @@ LIBIMOBILEDEVICE_API void instproxy_status_get_name(plist_t status, char **name)  	}  } -LIBIMOBILEDEVICE_API void instproxy_status_get_percent_complete(plist_t status, int *percent) +void instproxy_status_get_percent_complete(plist_t status, int *percent)  {  	uint64_t val = 0;  	if (percent) { @@ -867,7 +871,7 @@ LIBIMOBILEDEVICE_API void instproxy_status_get_percent_complete(plist_t status,  	}  } -LIBIMOBILEDEVICE_API void instproxy_status_get_current_list(plist_t status, uint64_t* total, uint64_t* current_index, uint64_t* current_amount, plist_t* list) +void instproxy_status_get_current_list(plist_t status, uint64_t* total, uint64_t* current_index, uint64_t* current_amount, plist_t* list)  {  	plist_t node = NULL; @@ -904,7 +908,7 @@ LIBIMOBILEDEVICE_API void instproxy_status_get_current_list(plist_t status, uint  	}  } -LIBIMOBILEDEVICE_API void instproxy_command_get_name(plist_t command, char** name) +void instproxy_command_get_name(plist_t command, char** name)  {  	if (name) {  		plist_t node = plist_dict_get_item(command, "Command"); @@ -916,12 +920,12 @@ LIBIMOBILEDEVICE_API void instproxy_command_get_name(plist_t command, char** nam  	}  } -LIBIMOBILEDEVICE_API plist_t instproxy_client_options_new(void) +plist_t instproxy_client_options_new(void)  {  	return plist_new_dict();  } -LIBIMOBILEDEVICE_API void instproxy_client_options_add(plist_t client_options, ...) +void instproxy_client_options_add(plist_t client_options, ...)  {  	if (!client_options)  		return; @@ -955,7 +959,7 @@ LIBIMOBILEDEVICE_API void instproxy_client_options_add(plist_t client_options, .  	va_end(args);  } -LIBIMOBILEDEVICE_API void instproxy_client_options_set_return_attributes(plist_t client_options, ...) +void instproxy_client_options_set_return_attributes(plist_t client_options, ...)  {  	if (!client_options)  		return; @@ -976,14 +980,14 @@ LIBIMOBILEDEVICE_API void instproxy_client_options_set_return_attributes(plist_t  	plist_dict_set_item(client_options, "ReturnAttributes", return_attributes);  } -LIBIMOBILEDEVICE_API void instproxy_client_options_free(plist_t client_options) +void instproxy_client_options_free(plist_t client_options)  {  	if (client_options) {  		plist_free(client_options);  	}  } -LIBIMOBILEDEVICE_API instproxy_error_t instproxy_client_get_path_for_bundle_identifier(instproxy_client_t client, const char* bundle_id, char** path) +instproxy_error_t instproxy_client_get_path_for_bundle_identifier(instproxy_client_t client, const char* bundle_id, char** path)  {  	if (!client || !client->parent || !bundle_id)  		return INSTPROXY_E_INVALID_ARG; diff --git a/src/installation_proxy.h b/src/installation_proxy.h index 033bdef..5bdbb71 100644 --- a/src/installation_proxy.h +++ b/src/installation_proxy.h @@ -23,6 +23,7 @@  #ifndef __INSTALLATION_PROXY_H  #define __INSTALLATION_PROXY_H +#include "idevice.h"  #include "libimobiledevice/installation_proxy.h"  #include "property_list_service.h"  #include <libimobiledevice-glue/thread.h> diff --git a/src/lockdown-cu.c b/src/lockdown-cu.c index d8d7f42..c457cb2 100644 --- a/src/lockdown-cu.c +++ b/src/lockdown-cu.c @@ -29,7 +29,11 @@  #define __USE_GNU 1  #include <stdio.h>  #include <ctype.h> + +#ifndef _MSC_VER  #include <unistd.h> +#endif +  #include <plist/plist.h>  #include "idevice.h" @@ -294,7 +298,7 @@ poly1305_update_with_pad16(poly1305_state *poly1305,  static void chacha20_poly1305_encrypt_96(unsigned char* key, unsigned char* nonce, unsigned char* ad, size_t ad_len, unsigned char* in, size_t in_len, unsigned char* out, size_t* out_len)  {  #if defined(HAVE_OPENSSL) -#if defined(LIBRESSL_VERSION_NUMBER) +#if defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x3050000fL)  #if (LIBRESSL_VERSION_NUMBER >= 0x2040000fL)  	const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();  	EVP_AEAD_CTX ctx; @@ -378,7 +382,7 @@ static void chacha20_poly1305_encrypt_64(unsigned char* key, unsigned char* nonc  static void chacha20_poly1305_decrypt_96(unsigned char* key, unsigned char* nonce, unsigned char* ad, size_t ad_len, unsigned char* in, size_t in_len, unsigned char* out, size_t* out_len)  {  #if defined(HAVE_OPENSSL) -#if defined(LIBRESSL_VERSION_NUMBER) +#if defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x3050000fL)  #if (LIBRESSL_VERSION_NUMBER >= 0x2040000fL)  	const EVP_AEAD *aead = EVP_aead_chacha20_poly1305();  	EVP_AEAD_CTX ctx; @@ -490,7 +494,7 @@ static void chacha20_poly1305_decrypt_64(unsigned char* key, unsigned char* nonc  #endif /* HAVE_WIRELESS_PAIRING */ -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_client_t client, lockdownd_cu_pairing_cb_t pairing_callback, void* cb_user_data, plist_t host_info, plist_t acl) +lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_client_t client, lockdownd_cu_pairing_cb_t pairing_callback, void* cb_user_data, plist_t host_info, plist_t acl)  {  #ifdef HAVE_WIRELESS_PAIRING  	if (!client || !pairing_callback || (host_info && plist_get_node_type(host_info) != PLIST_DICT) || (acl && plist_get_node_type(acl) != PLIST_DICT)) @@ -505,7 +509,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_cli  			char *s_version = NULL;  			plist_get_string_val(p_version, &s_version);  			if (s_version && sscanf(s_version, "%d.%d.%d", &vers[0], &vers[1], &vers[2]) >= 2) { -				client->device->version = DEVICE_VERSION(vers[0], vers[1], vers[2]); +				client->device->version = IDEVICE_DEVICE_VERSION(vers[0], vers[1], vers[2]);  			}  			free(s_version);  		} @@ -653,7 +657,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_cli  			CFStringGetCString(cname, hostname, sizeof(hostname), kCFStringEncodingUTF8);  			CFRelease(cname);  #else -#ifdef WIN32 +#ifdef _WIN32  			DWORD hostname_len = sizeof(hostname);  			GetComputerName(hostname, &hostname_len);  #else @@ -932,7 +936,7 @@ debug_buffer(data, data_len);  #endif  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_send_request_and_get_reply(lockdownd_client_t client, const char* request, plist_t request_payload, plist_t* reply) +lockdownd_error_t lockdownd_cu_send_request_and_get_reply(lockdownd_client_t client, const char* request, plist_t request_payload, plist_t* reply)  {  #ifdef HAVE_WIRELESS_PAIRING  	if (!client || !request) @@ -957,12 +961,12 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_send_request_and_get_reply(l  	hkdf_md(MD_ALGO_SHA512, (unsigned char*)READ_KEY_SALT_MDLD, sizeof(READ_KEY_SALT_MDLD)-1, (unsigned char*)READ_KEY_INFO_MDLD, sizeof(READ_KEY_INFO_MDLD)-1, client->cu_key, client->cu_key_len, cu_read_key, &cu_read_key_len);  	// Starting with iOS/tvOS 11.2 and WatchOS 4.2, this nonce is random and sent along with the request. Before, the request doesn't have a nonce and it uses hardcoded nonce "sendone01234". -	unsigned char cu_nonce[12] = "sendone01234"; // guaranteed to be random by fair dice troll -        if (client->device->version >= DEVICE_VERSION(11,2,0)) { +	unsigned char cu_nonce[] = "sendone01234"; // guaranteed to be random by fair dice troll +        if (client->device->version >= IDEVICE_DEVICE_VERSION(11,2,0)) {  #if defined(HAVE_OPENSSL) -		RAND_bytes(cu_nonce, sizeof(cu_nonce)); +		RAND_bytes(cu_nonce, sizeof(cu_nonce)-1);  #elif defined(HAVE_GCRYPT) -		gcry_create_nonce(cu_nonce, sizeof(cu_nonce)); +		gcry_create_nonce(cu_nonce, sizeof(cu_nonce)-1);  #endif  	} @@ -1057,7 +1061,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_send_request_and_get_reply(l  #endif  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value_cu(lockdownd_client_t client, const char* domain, const char* key, plist_t* value) +lockdownd_error_t lockdownd_get_value_cu(lockdownd_client_t client, const char* domain, const char* key, plist_t* value)  {  #ifdef HAVE_WIRELESS_PAIRING  	if (!client) @@ -1097,7 +1101,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value_cu(lockdownd_client_t  #endif  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair_cu(lockdownd_client_t client) +lockdownd_error_t lockdownd_pair_cu(lockdownd_client_t client)  {  #ifdef HAVE_WIRELESS_PAIRING  	if (!client) @@ -1128,7 +1132,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair_cu(lockdownd_client_t clie  	plist_free(pubkey);	  	plist_t pair_record_plist = plist_new_dict(); -	pair_record_generate_keys_and_certs(pair_record_plist, public_key); +	pair_record_generate_keys_and_certs(pair_record_plist, public_key, client->device->version);  	char* host_id = NULL;  	char* system_buid = NULL; diff --git a/src/lockdown.c b/src/lockdown.c index 92af186..32389c9 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -32,7 +32,11 @@  #define __USE_GNU 1  #include <stdio.h>  #include <ctype.h> + +#ifndef _MSC_VER  #include <unistd.h> +#endif +  #include <plist/plist.h>  #include <libimobiledevice-glue/utils.h> @@ -43,7 +47,7 @@  #include "common/userpref.h"  #include "asprintf.h" -#ifdef WIN32 +#ifdef _WIN32  #include <windows.h>  #define sleep(x) Sleep(x*1000)  #endif @@ -226,7 +230,7 @@ static void plist_dict_add_label(plist_t plist, const char *label)  	}  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id) +lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -309,7 +313,7 @@ static lockdownd_error_t lockdownd_client_free_simple(lockdownd_client_t client)  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_free(lockdownd_client_t client) +lockdownd_error_t lockdownd_client_free(lockdownd_client_t client)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -325,7 +329,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_free(lockdownd_client_t  	return ret;  } -LIBIMOBILEDEVICE_API void lockdownd_client_set_label(lockdownd_client_t client, const char *label) +void lockdownd_client_set_label(lockdownd_client_t client, const char *label)  {  	if (client) {  		if (client->label) @@ -335,7 +339,7 @@ LIBIMOBILEDEVICE_API void lockdownd_client_set_label(lockdownd_client_t client,  	}  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist) +lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist)  {  	if (!client || !plist || (plist && *plist))  		return LOCKDOWN_E_INVALID_ARG; @@ -343,7 +347,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_receive(lockdownd_client_t clie  	return lockdownd_error(property_list_service_receive_plist(client->parent, plist));  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) +lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)  {  	if (!client || !plist)  		return LOCKDOWN_E_INVALID_ARG; @@ -351,7 +355,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_send(lockdownd_client_t client,  	return lockdownd_error(property_list_service_send_xml_plist(client->parent, plist));  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type) +lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -396,7 +400,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_query_type(lockdownd_client_t c  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) +lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -450,7 +454,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value(lockdownd_client_t cl  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_set_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)  {  	if (!client || !value)  		return LOCKDOWN_E_INVALID_ARG; @@ -498,7 +502,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_set_value(lockdownd_client_t cl  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) +lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -545,7 +549,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_remove_value(lockdownd_client_t  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_device_udid(lockdownd_client_t client, char **udid) +lockdownd_error_t lockdownd_get_device_udid(lockdownd_client_t client, char **udid)  {  	lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;  	plist_t value = NULL; @@ -591,7 +595,7 @@ static lockdownd_error_t lockdownd_get_device_public_key_as_key_data(lockdownd_c  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name) +lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name)  {  	lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;  	plist_t value = NULL; @@ -608,7 +612,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_device_name(lockdownd_clien  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label) +lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label)  {  	if (!device || !client)  		return LOCKDOWN_E_INVALID_ARG; @@ -617,6 +621,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new(idevice_t device, lo  		.port = 0xf27e,  		.ssl_enabled = 0  	}; +	char *type = NULL;  	property_list_service_client_t plistclient = NULL;  	if (property_list_service_client_new(device, (lockdownd_service_descriptor_t)&service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { @@ -638,51 +643,32 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new(idevice_t device, lo  	client_loc->label = label ? strdup(label) : NULL; -	*client = client_loc; - -	return LOCKDOWN_E_SUCCESS; -} - -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label) -{ -	if (!client) -		return LOCKDOWN_E_INVALID_ARG; - -	lockdownd_error_t ret = LOCKDOWN_E_SUCCESS; -	lockdownd_client_t client_loc = NULL; -	plist_t pair_record = NULL; -	char *host_id = NULL; -	char *type = NULL; - -	ret = lockdownd_client_new(device, &client_loc, label); -	if (LOCKDOWN_E_SUCCESS != ret) { -		debug_info("failed to create lockdownd client."); -		return ret; -	} - -	/* perform handshake */ -	ret = lockdownd_query_type(client_loc, &type); -	if (LOCKDOWN_E_SUCCESS != ret) { +	int is_lockdownd = 0; +	if (lockdownd_query_type(client_loc, &type) != LOCKDOWN_E_SUCCESS) {  		debug_info("QueryType failed in the lockdownd client."); -	} else if (strcmp("com.apple.mobile.lockdown", type) != 0) { -		debug_info("Warning QueryType request returned \"%s\".", type); +	} else if (!strcmp("com.apple.mobile.lockdown", type)) { +		is_lockdownd = 1; +	} else { +		debug_info("QueryType request returned \"%s\"", type);  	}  	free(type); -	if (device->version == 0) { +	*client = client_loc; + +	if (is_lockdownd && device->version == 0) {  		plist_t p_version = NULL;  		if (lockdownd_get_value(client_loc, NULL, "ProductVersion", &p_version) == LOCKDOWN_E_SUCCESS) {  			int vers[3] = {0, 0, 0};  			char *s_version = NULL;  			plist_get_string_val(p_version, &s_version);  			if (s_version && sscanf(s_version, "%d.%d.%d", &vers[0], &vers[1], &vers[2]) >= 2) { -				device->version = DEVICE_VERSION(vers[0], vers[1], vers[2]); +				device->version = IDEVICE_DEVICE_VERSION(vers[0], vers[1], vers[2]);  			}  			free(s_version);  		}  		plist_free(p_version);  	} -	if (device->device_class == 0) { +	if (is_lockdownd && device->device_class == 0) {  		plist_t p_device_class = NULL;  		if (lockdownd_get_value(client_loc, NULL, "DeviceClass", &p_device_class) == LOCKDOWN_E_SUCCESS) {  			char* s_device_class = NULL; @@ -707,6 +693,26 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi  		plist_free(p_device_class);  	} +	return LOCKDOWN_E_SUCCESS; +} + +lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label) +{ +	if (!client) +		return LOCKDOWN_E_INVALID_ARG; + +	lockdownd_error_t ret = LOCKDOWN_E_SUCCESS; +	lockdownd_client_t client_loc = NULL; +	plist_t pair_record = NULL; +	char *host_id = NULL; + +	ret = lockdownd_client_new(device, &client_loc, label); +	if (LOCKDOWN_E_SUCCESS != ret) { +		debug_info("failed to create lockdownd client."); +		return ret; +	} + +	/* perform handshake */  	userpref_error_t uerr = userpref_read_pair_record(client_loc->device->udid, &pair_record);  	if (uerr == USERPREF_E_READ_ERROR) {  		debug_info("ERROR: Failed to retrieve pair record for %s", client_loc->device->udid); @@ -730,7 +736,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi  	plist_free(pair_record);  	pair_record = NULL; -	if (device->version < DEVICE_VERSION(7,0,0) && device->device_class != DEVICE_CLASS_WATCH) { +	if (device->version < IDEVICE_DEVICE_VERSION(7,0,0) && device->device_class != DEVICE_CLASS_WATCH) {  		/* for older devices, we need to validate pairing to receive trusted host status */  		ret = lockdownd_validate_pair(client_loc, NULL); @@ -836,7 +842,7 @@ static lockdownd_error_t pair_record_generate(lockdownd_client_t client, plist_t  	/* generate keys and certificates into pair record */  	userpref_error_t uret = USERPREF_E_SUCCESS; -	uret = pair_record_generate_keys_and_certs(*pair_record, public_key); +	uret = pair_record_generate_keys_and_certs(*pair_record, public_key, client->device->version);  	switch(uret) {  		case USERPREF_E_INVALID_ARG:  			ret = LOCKDOWN_E_INVALID_ARG; @@ -846,6 +852,7 @@ static lockdownd_error_t pair_record_generate(lockdownd_client_t client, plist_t  			break;  		case USERPREF_E_SSL_ERROR:  			ret = LOCKDOWN_E_SSL_ERROR; +			break;  		default:  			break;  	} @@ -1056,7 +1063,7 @@ static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, lockdownd_  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) +lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record)  {  	plist_t options = plist_new_dict(); @@ -1069,22 +1076,22 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair(lockdownd_client_t client,  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair_with_options(lockdownd_client_t client, lockdownd_pair_record_t pair_record, plist_t options, plist_t *response) +lockdownd_error_t lockdownd_pair_with_options(lockdownd_client_t client, lockdownd_pair_record_t pair_record, plist_t options, plist_t *response)  {  	return lockdownd_do_pair(client, pair_record, "Pair", options, response);  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) +lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record)  {  	return lockdownd_do_pair(client, pair_record, "ValidatePair", NULL, NULL);  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) +lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record)  {  	return lockdownd_do_pair(client, pair_record, "Unpair", NULL, NULL);  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client) +lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -1114,7 +1121,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_enter_recovery(lockdownd_client  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client) +lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -1148,7 +1155,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_goodbye(lockdownd_client_t clie  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled) +lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled)  {  	lockdownd_error_t ret = LOCKDOWN_E_SUCCESS;  	plist_t dict = NULL; @@ -1392,17 +1399,17 @@ static lockdownd_error_t lockdownd_do_start_service(lockdownd_client_t client, c  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service) +lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service)  {  	return lockdownd_do_start_service(client, identifier, 0, service);  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_service_with_escrow_bag(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service) +lockdownd_error_t lockdownd_start_service_with_escrow_bag(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service)  {  	return lockdownd_do_start_service(client, identifier, 1, service);  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record) +lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -1441,7 +1448,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_activate(lockdownd_client_t cli  	return ret;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client) +lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -1488,7 +1495,7 @@ static void str_remove_spaces(char *source)  	*dest = 0;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count) +lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count)  {  	if (!client)  		return LOCKDOWN_E_INVALID_ARG; @@ -1543,7 +1550,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd  	return LOCKDOWN_E_SUCCESS;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_data_classes_free(char **classes) +lockdownd_error_t lockdownd_data_classes_free(char **classes)  {  	if (classes) {  		int i = 0; @@ -1555,7 +1562,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_data_classes_free(char **classe  	return LOCKDOWN_E_SUCCESS;  } -LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service) +lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service)  {  	if (service) {  		free(service->identifier); @@ -1565,7 +1572,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_service_descriptor_free(lockdow  	return LOCKDOWN_E_SUCCESS;  } -LIBIMOBILEDEVICE_API const char* lockdownd_strerror(lockdownd_error_t err) +const char* lockdownd_strerror(lockdownd_error_t err)  {  	switch (err) {  		case LOCKDOWN_E_SUCCESS: diff --git a/src/lockdown.h b/src/lockdown.h index bcd4717..ba291ec 100644 --- a/src/lockdown.h +++ b/src/lockdown.h @@ -23,6 +23,7 @@  #ifndef __LOCKDOWND_H  #define __LOCKDOWND_H +#include "idevice.h"  #include "libimobiledevice/lockdown.h"  #include "property_list_service.h" diff --git a/src/misagent.c b/src/misagent.c index af925f9..3fdca4d 100644 --- a/src/misagent.c +++ b/src/misagent.c @@ -24,9 +24,13 @@  #endif  #include <string.h>  #include <stdlib.h> +#include <stdio.h> + +#ifndef _MSC_VER  #include <unistd.h> +#endif +  #include <plist/plist.h> -#include <stdio.h>  #include "misagent.h"  #include "property_list_service.h" @@ -89,7 +93,7 @@ static misagent_error_t misagent_check_result(plist_t response, int* status_code  	return MISAGENT_E_REQUEST_FAILED;  } -LIBIMOBILEDEVICE_API misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client) +misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client)  {  	property_list_service_client_t plistclient = NULL;  	misagent_error_t err = misagent_error(property_list_service_client_new(device, service, &plistclient)); @@ -105,14 +109,14 @@ LIBIMOBILEDEVICE_API misagent_error_t misagent_client_new(idevice_t device, lock  	return MISAGENT_E_SUCCESS;  } -LIBIMOBILEDEVICE_API misagent_error_t misagent_client_start_service(idevice_t device, misagent_client_t * client, const char* label) +misagent_error_t misagent_client_start_service(idevice_t device, misagent_client_t * client, const char* label)  {  	misagent_error_t err = MISAGENT_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, MISAGENT_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(misagent_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API misagent_error_t misagent_client_free(misagent_client_t client) +misagent_error_t misagent_client_free(misagent_client_t client)  {  	if (!client)  		return MISAGENT_E_INVALID_ARG; @@ -127,7 +131,7 @@ LIBIMOBILEDEVICE_API misagent_error_t misagent_client_free(misagent_client_t cli  	return err;  } -LIBIMOBILEDEVICE_API misagent_error_t misagent_install(misagent_client_t client, plist_t profile) +misagent_error_t misagent_install(misagent_client_t client, plist_t profile)  {  	if (!client || !client->parent || !profile || (plist_get_node_type(profile) != PLIST_DATA))  		return MISAGENT_E_INVALID_ARG; @@ -164,7 +168,7 @@ LIBIMOBILEDEVICE_API misagent_error_t misagent_install(misagent_client_t client,  	return res;  } -LIBIMOBILEDEVICE_API misagent_error_t misagent_copy(misagent_client_t client, plist_t* profiles) +misagent_error_t misagent_copy(misagent_client_t client, plist_t* profiles)  {  	if (!client || !client->parent || !profiles)  		return MISAGENT_E_INVALID_ARG; @@ -204,7 +208,7 @@ LIBIMOBILEDEVICE_API misagent_error_t misagent_copy(misagent_client_t client, pl  } -LIBIMOBILEDEVICE_API misagent_error_t misagent_copy_all(misagent_client_t client, plist_t* profiles) +misagent_error_t misagent_copy_all(misagent_client_t client, plist_t* profiles)  {  	if (!client || !client->parent || !profiles)  		return MISAGENT_E_INVALID_ARG; @@ -244,7 +248,7 @@ LIBIMOBILEDEVICE_API misagent_error_t misagent_copy_all(misagent_client_t client  } -LIBIMOBILEDEVICE_API misagent_error_t misagent_remove(misagent_client_t client, const char* profileID) +misagent_error_t misagent_remove(misagent_client_t client, const char* profileID)  {  	if (!client || !client->parent || !profileID)  		return MISAGENT_E_INVALID_ARG; @@ -281,7 +285,7 @@ LIBIMOBILEDEVICE_API misagent_error_t misagent_remove(misagent_client_t client,  	return res;  } -LIBIMOBILEDEVICE_API int misagent_get_status_code(misagent_client_t client) +int misagent_get_status_code(misagent_client_t client)  {  	if (!client) {  		return -1; diff --git a/src/misagent.h b/src/misagent.h index 08ad063..e394087 100644 --- a/src/misagent.h +++ b/src/misagent.h @@ -22,6 +22,7 @@  #ifndef __MISAGENT_H  #define __MISAGENT_H +#include "idevice.h"  #include "libimobiledevice/misagent.h"  #include "property_list_service.h" diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c index 9ccfd85..6677882 100644 --- a/src/mobile_image_mounter.c +++ b/src/mobile_image_mounter.c @@ -24,7 +24,11 @@  #endif  #include <string.h>  #include <stdlib.h> + +#ifndef _MSC_VER  #include <unistd.h> +#endif +  #include <plist/plist.h>  #include "mobile_image_mounter.h" @@ -78,7 +82,7 @@ static mobile_image_mounter_error_t mobile_image_mounter_error(property_list_ser  	return MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API 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_new(idevice_t device, lockdownd_service_descriptor_t service, mobile_image_mounter_client_t *client)  {  	property_list_service_client_t plistclient = NULL;  	mobile_image_mounter_error_t err = mobile_image_mounter_error(property_list_service_client_new(device, service, &plistclient)); @@ -95,14 +99,14 @@ LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_new(idevi  	return MOBILE_IMAGE_MOUNTER_E_SUCCESS;  } -LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_start_service(idevice_t device, mobile_image_mounter_client_t * client, const char* label) +mobile_image_mounter_error_t mobile_image_mounter_start_service(idevice_t device, mobile_image_mounter_client_t * client, const char* label)  {  	mobile_image_mounter_error_t err = MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, MOBILE_IMAGE_MOUNTER_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobile_image_mounter_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client) +mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client)  {  	if (!client)  		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; @@ -115,7 +119,7 @@ LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_free(mobi  	return MOBILE_IMAGE_MOUNTER_E_SUCCESS;  } -LIBIMOBILEDEVICE_API 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_lookup_image(mobile_image_mounter_client_t client, const char *image_type, plist_t *result)  {  	if (!client || !image_type || !result) {  		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; @@ -181,7 +185,7 @@ static mobile_image_mounter_error_t process_result(plist_t result, const char *e  	return res;  } -LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_image(mobile_image_mounter_client_t client, const char *image_type, size_t image_size, const char *signature, uint16_t signature_size, mobile_image_mounter_upload_cb_t upload_cb, void* userdata) +mobile_image_mounter_error_t mobile_image_mounter_upload_image(mobile_image_mounter_client_t client, const char *image_type, size_t image_size, const unsigned char *signature, unsigned int signature_size, mobile_image_mounter_upload_cb_t upload_cb, void* userdata)  {  	if (!client || !image_type || (image_size == 0) || !upload_cb) {  		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; @@ -192,7 +196,7 @@ LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_im  	plist_t dict = plist_new_dict();  	plist_dict_set_item(dict, "Command", plist_new_string("ReceiveBytes"));  	if (signature && signature_size != 0) -		plist_dict_set_item(dict, "ImageSignature", plist_new_data(signature, signature_size)); +		plist_dict_set_item(dict, "ImageSignature", plist_new_data((char*)signature, signature_size));  	plist_dict_set_item(dict, "ImageSize", plist_new_uint(image_size));  	plist_dict_set_item(dict, "ImageType", plist_new_string(image_type)); @@ -241,6 +245,7 @@ LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_im  	free(buf);  	if (tx < image_size) {  		debug_info("Error: failed to upload image"); +		res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED;  		goto leave_unlock;  	}  	debug_info("image uploaded"); @@ -260,7 +265,7 @@ leave_unlock:  } -LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, const char *image_path, const char *signature, uint16_t signature_size, const char *image_type, plist_t *result) +mobile_image_mounter_error_t mobile_image_mounter_mount_image_with_options(mobile_image_mounter_client_t client, const char *image_path, const unsigned char *signature, unsigned int signature_size, const char *image_type, plist_t options, plist_t *result)  {  	if (!client || !image_path || !image_type || !result) {  		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; @@ -271,8 +276,11 @@ LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_mount_ima  	plist_dict_set_item(dict, "Command", plist_new_string("MountImage"));  	plist_dict_set_item(dict, "ImagePath", plist_new_string(image_path));  	if (signature && signature_size != 0) -		plist_dict_set_item(dict, "ImageSignature", plist_new_data(signature, signature_size)); +		plist_dict_set_item(dict, "ImageSignature", plist_new_data((char*)signature, signature_size));  	plist_dict_set_item(dict, "ImageType", plist_new_string(image_type)); +	if (PLIST_IS_DICT(options)) { +		plist_dict_merge(&dict, options); +	}  	mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));  	plist_free(dict); @@ -292,7 +300,57 @@ leave_unlock:  	return res;  } -LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_hangup(mobile_image_mounter_client_t client) +mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, const char *image_path, const unsigned char *signature, unsigned int signature_size, const char *image_type, plist_t *result) +{ +	return mobile_image_mounter_mount_image_with_options(client, image_path, signature, signature_size, image_type, NULL, result); +} + +mobile_image_mounter_error_t mobile_image_mounter_unmount_image(mobile_image_mounter_client_t client, const char *mount_path) +{ +	if (!client || !mount_path) { +		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; +	} +	mobile_image_mounter_lock(client); + +	plist_t dict = plist_new_dict(); +	plist_dict_set_item(dict, "Command", plist_new_string("UnmountImage")); +	plist_dict_set_item(dict, "MountPath", plist_new_string(mount_path)); +	mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict)); +	plist_free(dict); + +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error sending XML plist to device!", __func__); +		goto leave_unlock; +	} + +	plist_t result = NULL; +	res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result)); +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error receiving response from device!", __func__); +	} else { +		plist_t p_error = plist_dict_get_item(result, "Error"); +		if (p_error) { +			plist_t p_detailed = plist_dict_get_item(result, "DetailedError"); +			const char* detailederr = (p_detailed) ? plist_get_string_ptr(p_detailed, NULL) : ""; +			const char* errstr = plist_get_string_ptr(p_error, NULL); +			if (errstr && !strcmp(errstr, "UnknownCommand")) { +				res = MOBILE_IMAGE_MOUNTER_E_NOT_SUPPORTED; +			} else if (errstr && !strcmp(errstr, "DeviceLocked")) { +				res = MOBILE_IMAGE_MOUNTER_E_DEVICE_LOCKED; +			} else if (strstr(detailederr, "no matching entry")) { +				res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED; +			} else { +				res = MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR; +			} +		} +	} + +leave_unlock: +	mobile_image_mounter_unlock(client); +	return res; +} + +mobile_image_mounter_error_t mobile_image_mounter_hangup(mobile_image_mounter_client_t client)  {  	if (!client) {  		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; @@ -324,3 +382,215 @@ leave_unlock:  	mobile_image_mounter_unlock(client);  	return res;  } + +mobile_image_mounter_error_t mobile_image_mounter_query_developer_mode_status(mobile_image_mounter_client_t client, plist_t *result) +{ +	if (!client || !result) { +		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; +	} +	mobile_image_mounter_lock(client); + +	plist_t dict = plist_new_dict(); +	plist_dict_set_item(dict, "Command", plist_new_string("QueryDeveloperModeStatus")); +	mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict)); +	plist_free(dict); + +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error sending XML plist to device!", __func__); +		goto leave_unlock; +	} + +	res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, result)); +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error receiving response from device!", __func__); +	} + +leave_unlock: +	mobile_image_mounter_unlock(client); +	return res; +} + +mobile_image_mounter_error_t mobile_image_mounter_query_nonce(mobile_image_mounter_client_t client, const char* image_type, unsigned char** nonce, unsigned int* nonce_size) +{ +	if (!client || !nonce || !nonce_size) { +		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; +	} +	mobile_image_mounter_lock(client); + +	plist_t dict = plist_new_dict(); +	plist_dict_set_item(dict, "Command", plist_new_string("QueryNonce")); +	if (image_type) { +		plist_dict_set_item(dict, "PersonalizedImageType", plist_new_string(image_type)); +	} +	mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict)); +	plist_free(dict); + +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error sending XML plist to device!", __func__); +		goto leave_unlock; +	} + +	plist_t result = NULL; +	res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result)); +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error receiving response from device!", __func__); +	} else { +		plist_t p_nonce = plist_dict_get_item(result, "PersonalizationNonce"); +		if (!p_nonce) { +			res = MOBILE_IMAGE_MOUNTER_E_NOT_SUPPORTED; +		} else { +			uint64_t nonce_size_ = 0; +			plist_get_data_val(p_nonce, (char**)nonce, &nonce_size_); +			if (*nonce) { +				*nonce_size = (unsigned int)nonce_size_; +			} else { +				res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED; +			} +		} +	} +	plist_free(result); + +leave_unlock: +	mobile_image_mounter_unlock(client); +	return res; +} + +mobile_image_mounter_error_t mobile_image_mounter_query_personalization_identifiers(mobile_image_mounter_client_t client, const char* image_type, plist_t *result) +{ +	if (!client || !result) { +		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; +	} +	mobile_image_mounter_lock(client); + +	plist_t dict = plist_new_dict(); +	plist_dict_set_item(dict, "Command", plist_new_string("QueryPersonalizationIdentifiers")); +	if (image_type) { +		plist_dict_set_item(dict, "PersonalizedImageType", plist_new_string(image_type)); +	} +	mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict)); +	plist_free(dict); + +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error sending XML plist to device!", __func__); +		goto leave_unlock; +	} + +	plist_t _result = NULL; +	res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &_result)); +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error receiving response from device!", __func__); +	} +	*result = plist_copy(plist_dict_get_item(_result, "PersonalizationIdentifiers")); +	if (!*result) { +		debug_info("%s: Response did not contain PersonalizationIdentifiers!", __func__); +		res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED; +	} + +leave_unlock: +	mobile_image_mounter_unlock(client); +	return res; +} + +mobile_image_mounter_error_t mobile_image_mounter_query_personalization_manifest(mobile_image_mounter_client_t client, const char* image_type, const unsigned char* signature, unsigned int signature_size, unsigned char** manifest, unsigned int* manifest_size) +{ +	if (!client || !image_type || !signature || !signature_size || !manifest || !manifest_size) { +		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; +	} +	mobile_image_mounter_lock(client); + +	plist_t dict = plist_new_dict(); +	plist_dict_set_item(dict, "Command", plist_new_string("QueryPersonalizationManifest")); +	plist_dict_set_item(dict, "PersonalizedImageType", plist_new_string(image_type)); +	plist_dict_set_item(dict, "ImageType", plist_new_string(image_type)); +	plist_dict_set_item(dict, "ImageSignature", plist_new_data((char*)signature, signature_size)); + +	mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict)); +	plist_free(dict); + +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error sending XML plist to device!", __func__); +		goto leave_unlock; +	} + +	plist_t result = NULL; +	res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result)); +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error receiving response from device!", __func__); +	} else { +		plist_t p_manifest = plist_dict_get_item(result, "ImageSignature"); +		if (!p_manifest) { +			res = MOBILE_IMAGE_MOUNTER_E_NOT_SUPPORTED; +		} else { +			uint64_t manifest_size_ = 0; +			plist_get_data_val(p_manifest, (char**)manifest, &manifest_size_); +			if (*manifest) { +				*manifest_size = (unsigned int)manifest_size_; +			} else { +				res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED; +			} +		} +	} +	plist_free(result); + +leave_unlock: +	mobile_image_mounter_unlock(client); +	return res; +} + +mobile_image_mounter_error_t mobile_image_mounter_roll_personalization_nonce(mobile_image_mounter_client_t client) +{ +	if (!client) { +		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; +	} +	mobile_image_mounter_lock(client); + +	plist_t dict = plist_new_dict(); +	plist_dict_set_item(dict, "Command", plist_new_string("RollPersonalizationNonce")); +	mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict)); +	plist_free(dict); + +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error sending XML plist to device!", __func__); +		goto leave_unlock; +	} + +	plist_t result = NULL; +	res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result)); +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error receiving response from device!", __func__); +	} +	plist_free(result); + +leave_unlock: +	mobile_image_mounter_unlock(client); +	return res; +} + +mobile_image_mounter_error_t mobile_image_mounter_roll_cryptex_nonce(mobile_image_mounter_client_t client) +{ +	if (!client) { +		return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; +	} +	mobile_image_mounter_lock(client); + +	plist_t dict = plist_new_dict(); +	plist_dict_set_item(dict, "Command", plist_new_string("RollCryptexNonce")); +	mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict)); +	plist_free(dict); + +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error sending XML plist to device!", __func__); +		goto leave_unlock; +	} + +	plist_t result = NULL; +	res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result)); +	if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { +		debug_info("%s: Error receiving response from device!", __func__); +	} +	plist_free(result); + +leave_unlock: +	mobile_image_mounter_unlock(client); +	return res; +} diff --git a/src/mobile_image_mounter.h b/src/mobile_image_mounter.h index 55c9cf2..9a8fcdd 100644 --- a/src/mobile_image_mounter.h +++ b/src/mobile_image_mounter.h @@ -22,6 +22,7 @@  #ifndef __MOBILE_IMAGE_MOUNTER_H  #define __MOBILE_IMAGE_MOUNTER_H +#include "idevice.h"  #include "libimobiledevice/mobile_image_mounter.h"  #include "property_list_service.h"  #include <libimobiledevice-glue/thread.h> diff --git a/src/mobileactivation.c b/src/mobileactivation.c index 79c7003..fce5f16 100644 --- a/src/mobileactivation.c +++ b/src/mobileactivation.c @@ -54,7 +54,7 @@ static mobileactivation_error_t mobileactivation_error(property_list_service_err  	return MOBILEACTIVATION_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobileactivation_client_t *client) +mobileactivation_error_t mobileactivation_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobileactivation_client_t *client)  {  	if (!device || !service || service->port == 0 || !client || *client) {  		return MOBILEACTIVATION_E_INVALID_ARG; @@ -74,14 +74,14 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_client_new(idevic  	return MOBILEACTIVATION_E_SUCCESS;  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_client_start_service(idevice_t device, mobileactivation_client_t * client, const char* label) +mobileactivation_error_t mobileactivation_client_start_service(idevice_t device, mobileactivation_client_t * client, const char* label)  {  	mobileactivation_error_t err = MOBILEACTIVATION_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, MOBILEACTIVATION_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobileactivation_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_client_free(mobileactivation_client_t client) +mobileactivation_error_t mobileactivation_client_free(mobileactivation_client_t client)  {  	if (!client)  		return MOBILEACTIVATION_E_INVALID_ARG; @@ -176,7 +176,7 @@ static mobileactivation_error_t mobileactivation_send_command(mobileactivation_c  	return ret;  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_get_activation_state(mobileactivation_client_t client, plist_t *state) +mobileactivation_error_t mobileactivation_get_activation_state(mobileactivation_client_t client, plist_t *state)  {  	if (!client || !state)  		return MOBILEACTIVATION_E_INVALID_ARG; @@ -198,7 +198,7 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_get_activation_st  	return ret;  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation_session_info(mobileactivation_client_t client, plist_t *blob) +mobileactivation_error_t mobileactivation_create_activation_session_info(mobileactivation_client_t client, plist_t *blob)  {  	if (!client || !blob)  		return MOBILEACTIVATION_E_INVALID_ARG; @@ -218,7 +218,7 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation  	return ret;  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation_info(mobileactivation_client_t client, plist_t *info) +mobileactivation_error_t mobileactivation_create_activation_info(mobileactivation_client_t client, plist_t *info)  {  	if (!client || !info)  		return MOBILEACTIVATION_E_INVALID_ARG; @@ -240,7 +240,7 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation  	return ret;  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation_info_with_session(mobileactivation_client_t client, plist_t handshake_response, plist_t *info) +mobileactivation_error_t mobileactivation_create_activation_info_with_session(mobileactivation_client_t client, plist_t handshake_response, plist_t *info)  {  	if (!client || !info)  		return MOBILEACTIVATION_E_INVALID_ARG; @@ -264,7 +264,7 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_create_activation  	return ret;  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_activate(mobileactivation_client_t client, plist_t activation_record) +mobileactivation_error_t mobileactivation_activate(mobileactivation_client_t client, plist_t activation_record)  {  	if (!client || !activation_record)  		return MOBILEACTIVATION_E_INVALID_ARG; @@ -277,7 +277,7 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_activate(mobileac  	return ret;  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_activate_with_session(mobileactivation_client_t client, plist_t activation_record, plist_t headers) +mobileactivation_error_t mobileactivation_activate_with_session(mobileactivation_client_t client, plist_t activation_record, plist_t headers)  {  	if (!client || !activation_record)  		return MOBILEACTIVATION_E_INVALID_ARG; @@ -300,7 +300,7 @@ LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_activate_with_ses  } -LIBIMOBILEDEVICE_API mobileactivation_error_t mobileactivation_deactivate(mobileactivation_client_t client) +mobileactivation_error_t mobileactivation_deactivate(mobileactivation_client_t client)  {  	if (!client)  		return MOBILEACTIVATION_E_INVALID_ARG; diff --git a/src/mobileactivation.h b/src/mobileactivation.h index 49b9ebc..a8dff5d 100644 --- a/src/mobileactivation.h +++ b/src/mobileactivation.h @@ -22,6 +22,7 @@  #ifndef __MOBILEACTIVATION_H  #define __MOBILEACTIVATION_H +#include "idevice.h"  #include "libimobiledevice/mobileactivation.h"  #include "property_list_service.h" diff --git a/src/mobilebackup.c b/src/mobilebackup.c index 1505623..36986a4 100644 --- a/src/mobilebackup.c +++ b/src/mobilebackup.c @@ -26,6 +26,7 @@  #include <plist/plist.h>  #include <string.h>  #include <stdlib.h> +#include <stdio.h>  #include "mobilebackup.h"  #include "device_link_service.h" @@ -68,7 +69,7 @@ static mobilebackup_error_t mobilebackup_error(device_link_service_error_t err)  	return MOBILEBACKUP_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup_client_t * client) +mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup_client_t * client)  {  	if (!device || !service || service->port == 0 || !client || *client)  		return MOBILEBACKUP_E_INVALID_ARG; @@ -95,14 +96,14 @@ LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_client_new(idevice_t devi  	return ret;  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_client_start_service(idevice_t device, mobilebackup_client_t * client, const char* label) +mobilebackup_error_t mobilebackup_client_start_service(idevice_t device, mobilebackup_client_t * client, const char* label)  {  	mobilebackup_error_t err = MOBILEBACKUP_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, MOBILEBACKUP_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobilebackup_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client) +mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client)  {  	if (!client)  		return MOBILEBACKUP_E_INVALID_ARG; @@ -115,7 +116,7 @@ LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_client_free(mobilebackup_  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t * plist) +mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t * plist)  {  	if (!client)  		return MOBILEBACKUP_E_INVALID_ARG; @@ -123,7 +124,7 @@ LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_receive(mobilebackup_clie  	return ret;  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist) +mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist)  {  	if (!client || !plist)  		return MOBILEBACKUP_E_INVALID_ARG; @@ -240,7 +241,7 @@ leave:  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_request_backup(mobilebackup_client_t client, plist_t backup_manifest, const char *base_path, const char *proto_version) +mobilebackup_error_t mobilebackup_request_backup(mobilebackup_client_t client, plist_t backup_manifest, const char *base_path, const char *proto_version)  {  	if (!client || !client->parent || !base_path || !proto_version)  		return MOBILEBACKUP_E_INVALID_ARG; @@ -308,12 +309,12 @@ leave:  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_send_backup_file_received(mobilebackup_client_t client) +mobilebackup_error_t mobilebackup_send_backup_file_received(mobilebackup_client_t client)  {  	return mobilebackup_send_message(client, "kBackupMessageBackupFileReceived", NULL);  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_request_restore(mobilebackup_client_t client, plist_t backup_manifest, mobilebackup_flags_t flags, const char *proto_version) +mobilebackup_error_t mobilebackup_request_restore(mobilebackup_client_t client, plist_t backup_manifest, mobilebackup_flags_t flags, const char *proto_version)  {  	if (!client || !client->parent || !backup_manifest || !proto_version)  		return MOBILEBACKUP_E_INVALID_ARG; @@ -375,17 +376,17 @@ leave:  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_receive_restore_file_received(mobilebackup_client_t client, plist_t *result) +mobilebackup_error_t mobilebackup_receive_restore_file_received(mobilebackup_client_t client, plist_t *result)  {  	return mobilebackup_receive_message(client, "BackupMessageRestoreFileReceived", result);  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_receive_restore_application_received(mobilebackup_client_t client, plist_t *result) +mobilebackup_error_t mobilebackup_receive_restore_application_received(mobilebackup_client_t client, plist_t *result)  {  	return mobilebackup_receive_message(client, "BackupMessageRestoreApplicationReceived", result);  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_send_restore_complete(mobilebackup_client_t client) +mobilebackup_error_t mobilebackup_send_restore_complete(mobilebackup_client_t client)  {  	mobilebackup_error_t err = mobilebackup_send_message(client, "BackupMessageRestoreComplete", NULL);  	if (err != MOBILEBACKUP_E_SUCCESS) { @@ -430,7 +431,7 @@ LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_send_restore_complete(mob  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup_error_t mobilebackup_send_error(mobilebackup_client_t client, const char *reason) +mobilebackup_error_t mobilebackup_send_error(mobilebackup_client_t client, const char *reason)  {  	if (!client || !client->parent || !reason)  		return MOBILEBACKUP_E_INVALID_ARG; diff --git a/src/mobilebackup.h b/src/mobilebackup.h index edda70f..04ec479 100644 --- a/src/mobilebackup.h +++ b/src/mobilebackup.h @@ -23,6 +23,7 @@  #ifndef __MOBILEBACKUP_H  #define __MOBILEBACKUP_H +#include "idevice.h"  #include "libimobiledevice/mobilebackup.h"  #include "device_link_service.h" diff --git a/src/mobilebackup2.c b/src/mobilebackup2.c index 3726065..a8d673f 100644 --- a/src/mobilebackup2.c +++ b/src/mobilebackup2.c @@ -68,7 +68,7 @@ static mobilebackup2_error_t mobilebackup2_error(device_link_service_error_t err  	return MOBILEBACKUP2_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service, +mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service,  						mobilebackup2_client_t * client)  {  	if (!device || !service || service->port == 0 || !client || *client) @@ -96,14 +96,14 @@ LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_client_new(idevice_t de  	return ret;  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_client_start_service(idevice_t device, mobilebackup2_client_t * client, const char* label) +mobilebackup2_error_t mobilebackup2_client_start_service(idevice_t device, mobilebackup2_client_t * client, const char* label)  {  	mobilebackup2_error_t err = MOBILEBACKUP2_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, MOBILEBACKUP2_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobilebackup2_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client) +mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client)  {  	if (!client)  		return MOBILEBACKUP2_E_INVALID_ARG; @@ -116,7 +116,7 @@ LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_client_free(mobilebacku  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, const char *message, plist_t options) +mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, const char *message, plist_t options)  {  	if (!client || !client->parent || (!message && !options))  		return MOBILEBACKUP2_E_INVALID_ARG; @@ -214,12 +214,12 @@ leave:  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage) +mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage)  {  	return mobilebackup2_error(device_link_service_receive_message(client->parent, msg_plist, dlmessage));  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, const char *data, uint32_t length, uint32_t *bytes) +mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, const char *data, uint32_t length, uint32_t *bytes)  {  	if (!client || !client->parent || !data || (length == 0) || !bytes)  		return MOBILEBACKUP2_E_INVALID_ARG; @@ -244,7 +244,7 @@ LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_  	return MOBILEBACKUP2_E_MUX_ERROR;  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes) +mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes)  {  	if (!client || !client->parent || !data || (length == 0) || !bytes)  		return MOBILEBACKUP2_E_INVALID_ARG; @@ -271,7 +271,7 @@ LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_receive_raw(mobilebacku  	return MOBILEBACKUP2_E_MUX_ERROR;  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version) +mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version)  {  	int i; @@ -329,7 +329,7 @@ leave:  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, const char *request, const char *target_identifier, const char *source_identifier, plist_t options) +mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, const char *request, const char *target_identifier, const char *source_identifier, plist_t options)  {  	if (!client || !client->parent || !request || !target_identifier)  		return MOBILEBACKUP2_E_INVALID_ARG; @@ -360,7 +360,7 @@ LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_request(mobileback  	return err;  } -LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, const char *status1, plist_t status2) +mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, const char *status1, plist_t status2)  {  	if (!client || !client->parent)  		return MOBILEBACKUP2_E_INVALID_ARG; diff --git a/src/mobilebackup2.h b/src/mobilebackup2.h index 025b6bf..e232b97 100644 --- a/src/mobilebackup2.h +++ b/src/mobilebackup2.h @@ -22,6 +22,7 @@  #ifndef __MOBILEBACKUP2_H  #define __MOBILEBACKUP2_H +#include "idevice.h"  #include "libimobiledevice/mobilebackup2.h"  #include "device_link_service.h" diff --git a/src/mobilesync.c b/src/mobilesync.c index e50226c..9b81a49 100644 --- a/src/mobilesync.c +++ b/src/mobilesync.c @@ -71,7 +71,7 @@ static mobilesync_error_t mobilesync_error(device_link_service_error_t err)  	return MOBILESYNC_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service, +mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service,  						   mobilesync_client_t * client)  {  	if (!device || !service || service->port == 0 || !client || *client) @@ -101,14 +101,14 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_client_new(idevice_t device,  	return ret;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_client_start_service(idevice_t device, mobilesync_client_t * client, const char* label) +mobilesync_error_t mobilesync_client_start_service(idevice_t device, mobilesync_client_t * client, const char* label)  {  	mobilesync_error_t err = MOBILESYNC_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, MOBILESYNC_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobilesync_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_client_free(mobilesync_client_t client) +mobilesync_error_t mobilesync_client_free(mobilesync_client_t client)  {  	if (!client)  		return MOBILESYNC_E_INVALID_ARG; @@ -118,7 +118,7 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_client_free(mobilesync_client  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t * plist) +mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t * plist)  {  	if (!client)  		return MOBILESYNC_E_INVALID_ARG; @@ -126,14 +126,14 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_receive(mobilesync_client_t c  	return ret;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist_t plist) +mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist_t plist)  {  	if (!client || !plist)  		return MOBILESYNC_E_INVALID_ARG;  	return mobilesync_error(device_link_service_send(client->parent, plist));  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_start(mobilesync_client_t client, const char *data_class, mobilesync_anchors_t anchors, uint64_t computer_data_class_version, mobilesync_sync_type_t *sync_type, uint64_t *device_data_class_version, char** error_description) +mobilesync_error_t mobilesync_start(mobilesync_client_t client, const char *data_class, mobilesync_anchors_t anchors, uint64_t computer_data_class_version, mobilesync_sync_type_t *sync_type, uint64_t *device_data_class_version, char** error_description)  {  	if (!client || client->data_class || !data_class ||  		!anchors || !anchors->computer_anchor) { @@ -259,7 +259,7 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_start(mobilesync_client_t cli  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_finish(mobilesync_client_t client) +mobilesync_error_t mobilesync_finish(mobilesync_client_t client)  {  	if (!client || !client->data_class) {  		return MOBILESYNC_E_INVALID_ARG; @@ -344,17 +344,17 @@ static mobilesync_error_t mobilesync_get_records(mobilesync_client_t client, con  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client) +mobilesync_error_t mobilesync_get_all_records_from_device(mobilesync_client_t client)  {  	return mobilesync_get_records(client, "SDMessageGetAllRecordsFromDevice");  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client) +mobilesync_error_t mobilesync_get_changes_from_device(mobilesync_client_t client)  {  	return mobilesync_get_records(client, "SDMessageGetChangesFromDevice");  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions) +mobilesync_error_t mobilesync_receive_changes(mobilesync_client_t client, plist_t *entities, uint8_t *is_last_record, plist_t *actions)  {  	if (!client || !client->data_class) {  		return MOBILESYNC_E_INVALID_ARG; @@ -421,7 +421,7 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_receive_changes(mobilesync_cl  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client) +mobilesync_error_t mobilesync_clear_all_records_on_device(mobilesync_client_t client)  {  	if (!client || !client->data_class) {  		return MOBILESYNC_E_INVALID_ARG; @@ -490,7 +490,7 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_clear_all_records_on_device(m  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client) +mobilesync_error_t mobilesync_acknowledge_changes_from_device(mobilesync_client_t client)  {  	if (!client || !client->data_class) {  		return MOBILESYNC_E_INVALID_ARG; @@ -524,7 +524,7 @@ static plist_t create_process_changes_message(const char *data_class, plist_t en  	return msg;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client) +mobilesync_error_t mobilesync_ready_to_send_changes_from_computer(mobilesync_client_t client)  {  	if (!client || !client->data_class) {  		return MOBILESYNC_E_INVALID_ARG; @@ -591,7 +591,7 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_ready_to_send_changes_from_co  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t entities, uint8_t is_last_record, plist_t actions) +mobilesync_error_t mobilesync_send_changes(mobilesync_client_t client, plist_t entities, uint8_t is_last_record, plist_t actions)  {  	if (!client || !client->data_class || !entities) {  		return MOBILESYNC_E_INVALID_ARG; @@ -619,7 +619,7 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_send_changes(mobilesync_clien  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plist_t *mapping) +mobilesync_error_t mobilesync_remap_identifiers(mobilesync_client_t client, plist_t *mapping)  {  	if (!client || !client->data_class) {  		return MOBILESYNC_E_INVALID_ARG; @@ -688,7 +688,7 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_remap_identifiers(mobilesync_  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* reason) +mobilesync_error_t mobilesync_cancel(mobilesync_client_t client, const char* reason)  {  	if (!client || !client->data_class || !reason) {  		return MOBILESYNC_E_INVALID_ARG; @@ -714,7 +714,7 @@ LIBIMOBILEDEVICE_API mobilesync_error_t mobilesync_cancel(mobilesync_client_t cl  	return err;  } -LIBIMOBILEDEVICE_API mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const char *computer_anchor) +mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const char *computer_anchor)  {  	mobilesync_anchors_t anchors = (mobilesync_anchors_t) malloc(sizeof(mobilesync_anchors));  	if (device_anchor != NULL) { @@ -731,7 +731,7 @@ LIBIMOBILEDEVICE_API mobilesync_anchors_t mobilesync_anchors_new(const char *dev  	return anchors;  } -LIBIMOBILEDEVICE_API void mobilesync_anchors_free(mobilesync_anchors_t anchors) +void mobilesync_anchors_free(mobilesync_anchors_t anchors)  {  	if (anchors->device_anchor != NULL) {  		free(anchors->device_anchor); @@ -745,12 +745,12 @@ LIBIMOBILEDEVICE_API void mobilesync_anchors_free(mobilesync_anchors_t anchors)  	anchors = NULL;  } -LIBIMOBILEDEVICE_API plist_t mobilesync_actions_new(void) +plist_t mobilesync_actions_new(void)  {  	return plist_new_dict();  } -LIBIMOBILEDEVICE_API void mobilesync_actions_add(plist_t actions, ...) +void mobilesync_actions_add(plist_t actions, ...)  {  	if (!actions)  		return; @@ -782,7 +782,7 @@ LIBIMOBILEDEVICE_API void mobilesync_actions_add(plist_t actions, ...)  	va_end(args);  } -LIBIMOBILEDEVICE_API void mobilesync_actions_free(plist_t actions) +void mobilesync_actions_free(plist_t actions)  {  	if (actions) {  		plist_free(actions); diff --git a/src/mobilesync.h b/src/mobilesync.h index f672252..3b5ece9 100644 --- a/src/mobilesync.h +++ b/src/mobilesync.h @@ -23,6 +23,7 @@  #ifndef __MOBILESYNC_H  #define __MOBILESYNC_H +#include "idevice.h"  #include "libimobiledevice/mobilesync.h"  #include "device_link_service.h" diff --git a/src/notification_proxy.c b/src/notification_proxy.c index e17e2fe..c7e4660 100644 --- a/src/notification_proxy.c +++ b/src/notification_proxy.c @@ -24,14 +24,19 @@  #endif  #include <string.h>  #include <stdlib.h> + +#ifndef _MSC_VER  #include <unistd.h> +#endif +  #include <plist/plist.h>  #include "notification_proxy.h"  #include "property_list_service.h"  #include "common/debug.h" -#ifdef WIN32 +#ifdef _WIN32 +#include <windows.h>  #define sleep(x) Sleep(x*1000)  #endif @@ -89,7 +94,7 @@ static np_error_t np_error(property_list_service_error_t err)  	return NP_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client) +np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client)  {  	property_list_service_client_t plistclient = NULL;  	np_error_t err = np_error(property_list_service_client_new(device, service, &plistclient)); @@ -107,14 +112,14 @@ LIBIMOBILEDEVICE_API np_error_t np_client_new(idevice_t device, lockdownd_servic  	return NP_E_SUCCESS;  } -LIBIMOBILEDEVICE_API np_error_t np_client_start_service(idevice_t device, np_client_t* client, const char* label) +np_error_t np_client_start_service(idevice_t device, np_client_t* client, const char* label)  { -	np_error_t err = NP_E_UNKNOWN_ERROR; +	int32_t err = NP_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, NP_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(np_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client) +np_error_t np_client_free(np_client_t client)  {  	plist_t dict;  	property_list_service_client_t parent; @@ -168,7 +173,7 @@ LIBIMOBILEDEVICE_API np_error_t np_client_free(np_client_t client)  	return NP_E_SUCCESS;  } -LIBIMOBILEDEVICE_API np_error_t np_post_notification(np_client_t client, const char *notification) +np_error_t np_post_notification(np_client_t client, const char *notification)  {  	if (!client || !notification) {  		return NP_E_INVALID_ARG; @@ -204,7 +209,7 @@ static np_error_t internal_np_observe_notification(np_client_t client, const cha  	return res;  } -LIBIMOBILEDEVICE_API np_error_t np_observe_notification( np_client_t client, const char *notification ) +np_error_t np_observe_notification( np_client_t client, const char *notification )  {  	if (!client || !notification) {  		return NP_E_INVALID_ARG; @@ -215,7 +220,7 @@ LIBIMOBILEDEVICE_API np_error_t np_observe_notification( np_client_t client, con  	return res;  } -LIBIMOBILEDEVICE_API np_error_t np_observe_notifications(np_client_t client, const char **notification_spec) +np_error_t np_observe_notifications(np_client_t client, const char **notification_spec)  {  	int i = 0;  	np_error_t res = NP_E_UNKNOWN_ERROR; @@ -346,7 +351,7 @@ void* np_notifier( void* arg )  	return NULL;  } -LIBIMOBILEDEVICE_API np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb, void *user_data ) +np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb, void *user_data )  {  	if (!client)  		return NP_E_INVALID_ARG; diff --git a/src/notification_proxy.h b/src/notification_proxy.h index ea85149..595cb01 100644 --- a/src/notification_proxy.h +++ b/src/notification_proxy.h @@ -22,6 +22,7 @@  #ifndef __NOTIFICATION_PROXY_H  #define __NOTIFICATION_PROXY_H +#include "idevice.h"  #include "libimobiledevice/notification_proxy.h"  #include "property_list_service.h"  #include <libimobiledevice-glue/thread.h> diff --git a/src/ostrace.c b/src/ostrace.c new file mode 100644 index 0000000..68eb6bf --- /dev/null +++ b/src/ostrace.c @@ -0,0 +1,436 @@ +/* + * ostrace.c + * com.apple.os_trace_relay service implementation. + * + * Copyright (c) 2020-2025 Nikias Bassen, All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <string.h> +#include <stdlib.h> + +#include <plist/plist.h> + +#include "ostrace.h" +#include "lockdown.h" +#include "common/debug.h" +#include "endianness.h" + +struct ostrace_worker_thread { +	ostrace_client_t client; +	ostrace_activity_cb_t cbfunc; +	void *user_data; +}; + +/** + * Convert a service_error_t value to a ostrace_error_t value. + * Used internally to get correct error codes. + * + * @param err An service_error_t error code + * + * @return A matching ostrace_error_t error code, + *     OSTRACE_E_UNKNOWN_ERROR otherwise. + */ +static ostrace_error_t ostrace_error(service_error_t err) +{ +	switch (err) { +		case SERVICE_E_SUCCESS: +			return OSTRACE_E_SUCCESS; +		case SERVICE_E_INVALID_ARG: +			return OSTRACE_E_INVALID_ARG; +		case SERVICE_E_MUX_ERROR: +			return OSTRACE_E_MUX_ERROR; +		case SERVICE_E_SSL_ERROR: +			return OSTRACE_E_SSL_ERROR; +		case SERVICE_E_NOT_ENOUGH_DATA: +			return OSTRACE_E_NOT_ENOUGH_DATA; +		case SERVICE_E_TIMEOUT: +			return OSTRACE_E_TIMEOUT; +		default: +			break; +	} +	return OSTRACE_E_UNKNOWN_ERROR; +} + +ostrace_error_t ostrace_client_new(idevice_t device, lockdownd_service_descriptor_t service, ostrace_client_t * client) +{ +	*client = NULL; + +	if (!device || !service || service->port == 0 || !client || *client) { +		debug_info("Incorrect parameter passed to ostrace_client_new."); +		return OSTRACE_E_INVALID_ARG; +	} + +	debug_info("Creating ostrace_client, port = %d.", service->port); + +	service_client_t parent = NULL; +	ostrace_error_t ret = ostrace_error(service_client_new(device, service, &parent)); +	if (ret != OSTRACE_E_SUCCESS) { +		debug_info("Creating base service client failed. Error: %i", ret); +		return ret; +	} + +	ostrace_client_t client_loc = (ostrace_client_t) malloc(sizeof(struct ostrace_client_private)); +	client_loc->parent = parent; +	client_loc->worker = THREAD_T_NULL; + +	*client = client_loc; + +	debug_info("ostrace_client successfully created."); +	return 0; +} + +ostrace_error_t ostrace_client_start_service(idevice_t device, ostrace_client_t * client, const char* label) +{ +	ostrace_error_t err = OSTRACE_E_UNKNOWN_ERROR; +	service_client_factory_start_service(device, OSTRACE_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(ostrace_client_new), &err); +	return err; +} + +ostrace_error_t ostrace_client_free(ostrace_client_t client) +{ +	if (!client) +		return OSTRACE_E_INVALID_ARG; +	ostrace_stop_activity(client); +	ostrace_error_t err = ostrace_error(service_client_free(client->parent)); +	free(client); + +	return err; +} + +static ostrace_error_t ostrace_send_plist(ostrace_client_t client, plist_t plist) +{ +	ostrace_error_t res = OSTRACE_E_UNKNOWN_ERROR; +	uint32_t blen = 0; +	char* bin = NULL; +	uint32_t sent = 0; +	uint32_t swapped_len = 0; + +	if (!client || !plist) { +		return OSTRACE_E_INVALID_ARG; +	} + +	plist_to_bin(plist, &bin, &blen); +	swapped_len = htobe32(blen); + +	res = ostrace_error(service_send(client->parent, (char*)&swapped_len, 4, &sent)); +	if (res == OSTRACE_E_SUCCESS) { +		res = ostrace_error(service_send(client->parent, bin, blen, &sent)); +	} +	free(bin); +	return res; +} + +static ostrace_error_t ostrace_receive_plist(ostrace_client_t client, plist_t *plist) +{ +	ostrace_error_t res = OSTRACE_E_UNKNOWN_ERROR; +	uint8_t msgtype = 0; +	uint32_t received = 0; +	res = ostrace_error(service_receive(client->parent, (char*)&msgtype, 1, &received)); +	if (res != OSTRACE_E_SUCCESS) { +		debug_info("Failed to read message type from service"); +		return res; +	} +	uint32_t rlen = 0; +	res = ostrace_error(service_receive(client->parent, (char*)&rlen, 4, &received)); +	if (res != OSTRACE_E_SUCCESS) { +		debug_info("Failed to read message size from service"); +		return res; +	} + +	if (msgtype == 1) { +		rlen = be32toh(rlen); +	} else if (msgtype == 2) { +		rlen = le32toh(rlen); +	} else { +		debug_info("Unexpected message type %d", msgtype); +		return OSTRACE_E_UNKNOWN_ERROR; +	} +	debug_info("got length %d", rlen); + +	char* buf = (char*)malloc(rlen); +	res = ostrace_error(service_receive(client->parent, buf, rlen, &received)); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} + +	plist_t reply = NULL; +	plist_err_t perr = plist_from_memory(buf, received, &reply, NULL); +	free(buf); +	if (perr != PLIST_ERR_SUCCESS) { +		return OSTRACE_E_UNKNOWN_ERROR; +	} +	*plist = reply; +	return OSTRACE_E_SUCCESS;	 +} + +static ostrace_error_t _ostrace_check_result(plist_t reply) +{ +	ostrace_error_t res = OSTRACE_E_REQUEST_FAILED; +	if (!reply) { +		return res; +	} +	plist_t p_status = plist_dict_get_item(reply, "Status"); +	if (!p_status) { +		return res; +	} +	const char* status = plist_get_string_ptr(p_status, NULL); +	if (!status) { +		return res; +	} +	if (!strcmp(status, "RequestSuccessful")) { +		res = OSTRACE_E_SUCCESS; +	} +	return res; +} + +void *ostrace_worker(void *arg) +{ +	ostrace_error_t res = OSTRACE_E_UNKNOWN_ERROR; +	struct ostrace_worker_thread *oswt = (struct ostrace_worker_thread*)arg; + +	if (!oswt) +		return NULL; + +	uint8_t msgtype = 0; +	uint32_t received = 0; + +	debug_info("Running"); + +	while (oswt->client->parent) { +		res = ostrace_error(service_receive_with_timeout(oswt->client->parent, (char*)&msgtype, 1, &received, 100)); +		if (res == OSTRACE_E_TIMEOUT) { +			continue; +		} +		if (res != OSTRACE_E_SUCCESS) { +			debug_info("Failed to read message type from service"); +			break; +		} +		uint32_t rlen = 0; +		res = ostrace_error(service_receive(oswt->client->parent, (char*)&rlen, 4, &received)); +		if (res != OSTRACE_E_SUCCESS) { +			debug_info("Failed to read message size from service"); +			break; +		} + +		if (msgtype == 1) { +			rlen = be32toh(rlen); +		} else if (msgtype == 2) { +			rlen = le32toh(rlen); +		} else { +			debug_info("Unexpected message type %d", msgtype); +			break; +		} + +		debug_info("got length %d", rlen); + +		void* buf = malloc(rlen); +		res = ostrace_error(service_receive(oswt->client->parent, (char*)buf, rlen, &received)); +		if (res != OSTRACE_E_SUCCESS) { +			debug_info("Failed to receive %d bytes, error %d", rlen, res); +			break; +		} +		if (received < rlen) { +			debug_info("Failed to receive all data, got %d/%d", received, rlen); +			break; +		} +		oswt->cbfunc(buf, received, oswt->user_data); +	} + +	if (oswt) { +		free(oswt); +	} + +	debug_info("Exiting"); + +	return NULL; +} + +ostrace_error_t ostrace_start_activity(ostrace_client_t client, plist_t options, ostrace_activity_cb_t callback, void* user_data) +{ +	if (!client || !callback) +		return OSTRACE_E_INVALID_ARG; + +	ostrace_error_t res = OSTRACE_E_UNKNOWN_ERROR; + +	if (client->worker) { +		debug_info("Another ostrace activity thread appears to be running already."); +		return res; +	} + +	plist_t dict = plist_new_dict(); +	plist_dict_set_item(dict, "Pid", plist_new_uint(0x0FFFFFFFF)); +	plist_dict_set_item(dict, "MessageFilter", plist_new_uint(0xFFFF)); +	plist_dict_set_item(dict, "StreamFlags", plist_new_uint(0x3C)); +	if (options) { +		plist_dict_merge(&dict, options); +	} +	plist_dict_set_item(dict, "Request", plist_new_string("StartActivity")); + +	res = ostrace_send_plist(client, dict); +	plist_free(dict); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} +	 +	dict = NULL; +	res = ostrace_receive_plist(client, &dict); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} +	res = _ostrace_check_result(dict); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} + +	/* start worker thread */ +	struct ostrace_worker_thread *oswt = (struct ostrace_worker_thread*)malloc(sizeof(struct ostrace_worker_thread)); +	if (oswt) { +		oswt->client = client; +		oswt->cbfunc = callback; +		oswt->user_data = user_data; + +		if (thread_new(&client->worker, ostrace_worker, oswt) == 0) { +			res = OSTRACE_E_SUCCESS; +		} +	} + +	return res; +} + +ostrace_error_t ostrace_stop_activity(ostrace_client_t client) +{ +	if (client->worker) { +		/* notify thread to finish */ +		service_client_t parent = client->parent; +		client->parent = NULL; +		/* join thread to make it exit */ +		thread_join(client->worker); +		thread_free(client->worker); +		client->worker = THREAD_T_NULL; +		client->parent = parent; +	} + +	return OSTRACE_E_SUCCESS; +} + +ostrace_error_t ostrace_get_pid_list(ostrace_client_t client, plist_t* list) +{ +	ostrace_error_t res = OSTRACE_E_UNKNOWN_ERROR; +	plist_t dict = plist_new_dict(); +	plist_dict_set_item(dict, "Request", plist_new_string("PidList")); + +	if (!client || !list) { +		return OSTRACE_E_INVALID_ARG; +	} + +	res = ostrace_send_plist(client, dict); +	plist_free(dict); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} + +	plist_t reply = NULL; +	res = ostrace_receive_plist(client, &reply); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} +	res = _ostrace_check_result(reply); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} + +	plist_t payload = plist_dict_get_item(reply, "Payload"); +	if (!payload) { +		return OSTRACE_E_REQUEST_FAILED; +	} +	*list = plist_copy(payload); +	plist_free(reply); + +	return OSTRACE_E_SUCCESS; +} + +ostrace_error_t ostrace_create_archive(ostrace_client_t client, plist_t options, ostrace_archive_write_cb_t callback, void* user_data) +{ +	ostrace_error_t res = OSTRACE_E_UNKNOWN_ERROR; +	if (!client || !callback) { +		return OSTRACE_E_INVALID_ARG; +	} +	plist_t dict = plist_new_dict(); +	if (options) { +		plist_dict_merge(&dict, options); +	} +	plist_dict_set_item(dict, "Request", plist_new_string("CreateArchive")); + +	res = ostrace_send_plist(client, dict); +	plist_free(dict); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} + +	plist_t reply = NULL; +	res = ostrace_receive_plist(client, &reply); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} + +	res = _ostrace_check_result(reply); +	if (res != OSTRACE_E_SUCCESS) { +		return res; +	} + +	debug_info("Receiving archive...\n"); +	while (1) { +		uint8_t msgtype = 0; +		uint32_t received = 0; +		res = ostrace_error(service_receive(client->parent, (char*)&msgtype, 1, &received)); +		if (res != OSTRACE_E_SUCCESS) { +			debug_info("Could not read message type from service: %d", res); +			break; +		} +		if (msgtype != 3) { +			debug_info("Unexpected packet type %d", msgtype); +			return OSTRACE_E_REQUEST_FAILED; +		} +		uint32_t rlen = 0; +		res = ostrace_error(service_receive(client->parent, (char*)&rlen, 4, &received)); +		if (res != OSTRACE_E_SUCCESS) { +			debug_info("Failed to read message size from service"); +			break; +		} + +		rlen = le32toh(rlen); +		debug_info("got length %d", rlen); + +		unsigned char* buf = (unsigned char*)malloc(rlen); +		res = ostrace_error(service_receive(client->parent, (char*)buf, rlen, &received)); +		if (res != OSTRACE_E_SUCCESS) { +			debug_info("Could not read data from service: %d", res); +			break; +		} +		if (callback(buf, received, user_data) < 0) { +			debug_info("Aborted through callback"); +			return OSTRACE_E_REQUEST_FAILED; +		} +	} +	debug_info("Done.\n"); + +	return OSTRACE_E_SUCCESS; +} + diff --git a/src/ostrace.h b/src/ostrace.h new file mode 100644 index 0000000..dcc3e8d --- /dev/null +++ b/src/ostrace.h @@ -0,0 +1,37 @@ +/* + * ostrace.h + * com.apple.os_trace_relay service header file. + * + * Copyright (c) 2020-2025 Nikias Bassen, All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + */ + +#ifndef _OSTRACE_H +#define _OSTRACE_H + +#include "idevice.h" +#include "libimobiledevice/ostrace.h" +#include "service.h" +#include <libimobiledevice-glue/thread.h> + +struct ostrace_client_private { +	service_client_t parent; +	THREAD_T worker; +}; + +void *ostrace_worker(void *arg); + +#endif diff --git a/src/preboard.c b/src/preboard.c index 4b3b444..c3eff02 100644 --- a/src/preboard.c +++ b/src/preboard.c @@ -62,7 +62,7 @@ static preboard_error_t preboard_error(property_list_service_error_t err)  	return PREBOARD_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API preboard_error_t preboard_client_new(idevice_t device, lockdownd_service_descriptor_t service, preboard_client_t * client) +preboard_error_t preboard_client_new(idevice_t device, lockdownd_service_descriptor_t service, preboard_client_t * client)  {  	*client = NULL; @@ -90,14 +90,14 @@ LIBIMOBILEDEVICE_API preboard_error_t preboard_client_new(idevice_t device, lock  	return 0;  } -LIBIMOBILEDEVICE_API preboard_error_t preboard_client_start_service(idevice_t device, preboard_client_t * client, const char* label) +preboard_error_t preboard_client_start_service(idevice_t device, preboard_client_t * client, const char* label)  {  	preboard_error_t err = PREBOARD_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, PREBOARD_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(preboard_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API preboard_error_t preboard_client_free(preboard_client_t client) +preboard_error_t preboard_client_free(preboard_client_t client)  {  	if (!client)  		return PREBOARD_E_INVALID_ARG; @@ -116,7 +116,7 @@ LIBIMOBILEDEVICE_API preboard_error_t preboard_client_free(preboard_client_t cli  	return err;  } -LIBIMOBILEDEVICE_API preboard_error_t preboard_send(preboard_client_t client, plist_t plist) +preboard_error_t preboard_send(preboard_client_t client, plist_t plist)  {  	preboard_error_t res = PREBOARD_E_UNKNOWN_ERROR;  	res = preboard_error(property_list_service_send_binary_plist(client->parent, plist)); @@ -127,7 +127,7 @@ LIBIMOBILEDEVICE_API preboard_error_t preboard_send(preboard_client_t client, pl  	return res;  } -LIBIMOBILEDEVICE_API preboard_error_t preboard_receive_with_timeout(preboard_client_t client, plist_t * plist, uint32_t timeout_ms) +preboard_error_t preboard_receive_with_timeout(preboard_client_t client, plist_t * plist, uint32_t timeout_ms)  {  	preboard_error_t res = PREBOARD_E_UNKNOWN_ERROR;  	plist_t outplist = NULL; @@ -141,7 +141,7 @@ LIBIMOBILEDEVICE_API preboard_error_t preboard_receive_with_timeout(preboard_cli  	return res;  } -LIBIMOBILEDEVICE_API preboard_error_t preboard_receive(preboard_client_t client, plist_t * plist) +preboard_error_t preboard_receive(preboard_client_t client, plist_t * plist)  {  	return preboard_receive_with_timeout(client, plist, 5000);  } @@ -209,7 +209,7 @@ static preboard_error_t preboard_receive_status_loop_with_callback(preboard_clie  	return res;  } -LIBIMOBILEDEVICE_API preboard_error_t preboard_create_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data) +preboard_error_t preboard_create_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data)  {  	if (!client) {  		return PREBOARD_E_INVALID_ARG; @@ -232,7 +232,7 @@ LIBIMOBILEDEVICE_API preboard_error_t preboard_create_stashbag(preboard_client_t  	return preboard_receive_status_loop_with_callback(client, status_cb, user_data);  } -LIBIMOBILEDEVICE_API preboard_error_t preboard_commit_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data) +preboard_error_t preboard_commit_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data)  {  	if (!client) {  		return PREBOARD_E_INVALID_ARG; diff --git a/src/preboard.h b/src/preboard.h index 61263fc..f8164eb 100644 --- a/src/preboard.h +++ b/src/preboard.h @@ -22,6 +22,7 @@  #ifndef __PREBOARD_H  #define __PREBOARD_H +#include "idevice.h"  #include "libimobiledevice/preboard.h"  #include "property_list_service.h"  #include <libimobiledevice-glue/thread.h> diff --git a/src/property_list_service.c b/src/property_list_service.c index 4654b6e..2fca4e7 100644 --- a/src/property_list_service.c +++ b/src/property_list_service.c @@ -58,7 +58,7 @@ static property_list_service_error_t service_to_property_list_service_error(serv  	return PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API 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_new(idevice_t device, lockdownd_service_descriptor_t service, property_list_service_client_t *client)  {  	if (!device || !service || service->port == 0 || !client || *client)  		return PROPERTY_LIST_SERVICE_E_INVALID_ARG; @@ -78,7 +78,7 @@ LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_client_  	return PROPERTY_LIST_SERVICE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_client_free(property_list_service_client_t client) +property_list_service_error_t property_list_service_client_free(property_list_service_client_t client)  {  	if (!client)  		return PROPERTY_LIST_SERVICE_E_INVALID_ARG; @@ -152,12 +152,12 @@ static property_list_service_error_t internal_plist_send(property_list_service_c  	return res;  } -LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_send_xml_plist(property_list_service_client_t client, plist_t plist) +property_list_service_error_t property_list_service_send_xml_plist(property_list_service_client_t client, plist_t plist)  {  	return internal_plist_send(client, plist, 0);  } -LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_send_binary_plist(property_list_service_client_t client, plist_t plist) +property_list_service_error_t property_list_service_send_binary_plist(property_list_service_client_t client, plist_t plist)  {  	return internal_plist_send(client, plist, 1);  } @@ -262,31 +262,31 @@ static property_list_service_error_t internal_plist_receive_timeout(property_lis  	return res;  } -LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_receive_plist_with_timeout(property_list_service_client_t client, plist_t *plist, unsigned int timeout) +property_list_service_error_t property_list_service_receive_plist_with_timeout(property_list_service_client_t client, plist_t *plist, unsigned int timeout)  {  	return internal_plist_receive_timeout(client, plist, timeout);  } -LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_receive_plist(property_list_service_client_t client, plist_t *plist) +property_list_service_error_t property_list_service_receive_plist(property_list_service_client_t client, plist_t *plist)  {  	return internal_plist_receive_timeout(client, plist, 30000);  } -LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_enable_ssl(property_list_service_client_t client) +property_list_service_error_t property_list_service_enable_ssl(property_list_service_client_t client)  {  	if (!client || !client->parent)  		return PROPERTY_LIST_SERVICE_E_INVALID_ARG;  	return service_to_property_list_service_error(service_enable_ssl(client->parent));  } -LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_disable_ssl(property_list_service_client_t client) +property_list_service_error_t property_list_service_disable_ssl(property_list_service_client_t client)  {  	if (!client || !client->parent)  		return PROPERTY_LIST_SERVICE_E_INVALID_ARG;  	return service_to_property_list_service_error(service_disable_ssl(client->parent));  } -LIBIMOBILEDEVICE_API property_list_service_error_t property_list_service_get_service_client(property_list_service_client_t client, service_client_t *service_client) +property_list_service_error_t property_list_service_get_service_client(property_list_service_client_t client, service_client_t *service_client)  {  	if (!client || !client->parent || !service_client)  		return PROPERTY_LIST_SERVICE_E_INVALID_ARG; diff --git a/src/property_list_service.h b/src/property_list_service.h index 3c9e14d..0e9e948 100644 --- a/src/property_list_service.h +++ b/src/property_list_service.h @@ -22,6 +22,7 @@  #ifndef __PROPERTY_LIST_SERVICE_H  #define __PROPERTY_LIST_SERVICE_H +#include "idevice.h"  #include "libimobiledevice/property_list_service.h"  #include "service.h" diff --git a/src/restore.c b/src/restore.c index 41bfb9d..d13a28a 100644 --- a/src/restore.c +++ b/src/restore.c @@ -111,7 +111,7 @@ static restored_error_t restored_error(property_list_service_error_t err)          return RESTORE_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API restored_error_t restored_client_free(restored_client_t client) +restored_error_t restored_client_free(restored_client_t client)  {  	if (!client)  		return RESTORE_E_INVALID_ARG; @@ -139,7 +139,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_client_free(restored_client_t cli  	return ret;  } -LIBIMOBILEDEVICE_API void restored_client_set_label(restored_client_t client, const char *label) +void restored_client_set_label(restored_client_t client, const char *label)  {  	if (client) {  		if (client->label) @@ -149,7 +149,7 @@ LIBIMOBILEDEVICE_API void restored_client_set_label(restored_client_t client, co  	}  } -LIBIMOBILEDEVICE_API restored_error_t restored_receive(restored_client_t client, plist_t *plist) +restored_error_t restored_receive(restored_client_t client, plist_t *plist)  {  	if (!client || !plist || (plist && *plist))  		return RESTORE_E_INVALID_ARG; @@ -157,7 +157,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_receive(restored_client_t client,  	return restored_error(property_list_service_receive_plist(client->parent, plist));  } -LIBIMOBILEDEVICE_API restored_error_t restored_send(restored_client_t client, plist_t plist) +restored_error_t restored_send(restored_client_t client, plist_t plist)  {  	if (!client || !plist)  		return RESTORE_E_INVALID_ARG; @@ -165,7 +165,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_send(restored_client_t client, pl  	return restored_error(property_list_service_send_xml_plist(client->parent, plist));  } -LIBIMOBILEDEVICE_API restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version) +restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version)  {  	if (!client)  		return RESTORE_E_INVALID_ARG; @@ -224,7 +224,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_query_type(restored_client_t clie  	return ret;  } -LIBIMOBILEDEVICE_API restored_error_t restored_query_value(restored_client_t client, const char *key, plist_t *value) +restored_error_t restored_query_value(restored_client_t client, const char *key, plist_t *value)  {  	if (!client || !key)  		return RESTORE_E_INVALID_ARG; @@ -266,7 +266,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_query_value(restored_client_t cli  	return ret;  } -LIBIMOBILEDEVICE_API restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value) +restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value)  {  	plist_t item; @@ -291,7 +291,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_get_value(restored_client_t clien  	return RESTORE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API restored_error_t restored_client_new(idevice_t device, restored_client_t *client, const char *label) +restored_error_t restored_client_new(idevice_t device, restored_client_t *client, const char *label)  {  	if (!client)  		return RESTORE_E_INVALID_ARG; @@ -335,7 +335,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_client_new(idevice_t device, rest  	return ret;  } -LIBIMOBILEDEVICE_API restored_error_t restored_goodbye(restored_client_t client) +restored_error_t restored_goodbye(restored_client_t client)  {  	if (!client)  		return RESTORE_E_INVALID_ARG; @@ -367,7 +367,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_goodbye(restored_client_t client)  	return ret;  } -LIBIMOBILEDEVICE_API restored_error_t restored_start_restore(restored_client_t client, plist_t options, uint64_t version) +restored_error_t restored_start_restore(restored_client_t client, plist_t options, uint64_t version)  {  	if (!client)  		return RESTORE_E_INVALID_ARG; @@ -391,7 +391,7 @@ LIBIMOBILEDEVICE_API restored_error_t restored_start_restore(restored_client_t c  	return ret;  } -LIBIMOBILEDEVICE_API restored_error_t restored_reboot(restored_client_t client) +restored_error_t restored_reboot(restored_client_t client)  {  	if (!client)  		return RESTORE_E_INVALID_ARG; diff --git a/src/restore.h b/src/restore.h index 646d1d1..ec6fa04 100644 --- a/src/restore.h +++ b/src/restore.h @@ -24,6 +24,7 @@  #include <string.h> +#include "idevice.h"  #include "libimobiledevice/restore.h"  #include "property_list_service.h" diff --git a/src/reverse_proxy.c b/src/reverse_proxy.c index bca0a13..2fcfdd1 100644 --- a/src/reverse_proxy.c +++ b/src/reverse_proxy.c @@ -528,7 +528,7 @@ static void* _reverse_proxy_control_thread(void *cdata)  	return NULL;  } -LIBIMOBILEDEVICE_API reverse_proxy_error_t reverse_proxy_client_start_proxy(reverse_proxy_client_t client, int control_protocol_version) +reverse_proxy_error_t reverse_proxy_client_start_proxy(reverse_proxy_client_t client, int control_protocol_version)  {  	char buf[16] = {0, };  	uint32_t bytes = 0; @@ -607,7 +607,7 @@ LIBIMOBILEDEVICE_API reverse_proxy_error_t reverse_proxy_client_start_proxy(reve  	return err;  } -LIBIMOBILEDEVICE_API reverse_proxy_error_t reverse_proxy_client_create_with_service(idevice_t device, reverse_proxy_client_t* client, const char* label) +reverse_proxy_error_t reverse_proxy_client_create_with_service(idevice_t device, reverse_proxy_client_t* client, const char* label)  {  	reverse_proxy_error_t err = REVERSE_PROXY_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, "com.apple.PurpleReverseProxy.Ctrl", (void**)client, label, SERVICE_CONSTRUCTOR(reverse_proxy_client_new), &err); @@ -620,7 +620,7 @@ LIBIMOBILEDEVICE_API reverse_proxy_error_t reverse_proxy_client_create_with_serv  	return REVERSE_PROXY_E_SUCCESS;  } -LIBIMOBILEDEVICE_API reverse_proxy_error_t reverse_proxy_client_create_with_port(idevice_t device, reverse_proxy_client_t* client, uint16_t device_port) +reverse_proxy_error_t reverse_proxy_client_create_with_port(idevice_t device, reverse_proxy_client_t* client, uint16_t device_port)  {  	reverse_proxy_client_t client_loc = NULL;  	reverse_proxy_error_t err; @@ -641,7 +641,7 @@ LIBIMOBILEDEVICE_API reverse_proxy_error_t reverse_proxy_client_create_with_port  	return REVERSE_PROXY_E_SUCCESS;  } -LIBIMOBILEDEVICE_API reverse_proxy_error_t reverse_proxy_client_free(reverse_proxy_client_t client) +reverse_proxy_error_t reverse_proxy_client_free(reverse_proxy_client_t client)  {  	if (!client)  		return REVERSE_PROXY_E_INVALID_ARG; @@ -660,14 +660,14 @@ LIBIMOBILEDEVICE_API reverse_proxy_error_t reverse_proxy_client_free(reverse_pro  	return err;  } -LIBIMOBILEDEVICE_API reverse_proxy_client_type_t reverse_proxy_get_type(reverse_proxy_client_t client) +reverse_proxy_client_type_t reverse_proxy_get_type(reverse_proxy_client_t client)  {  	if (!client)  		return 0;  	return client->type;  } -LIBIMOBILEDEVICE_API void reverse_proxy_client_set_status_callback(reverse_proxy_client_t client, reverse_proxy_status_cb_t status_callback, void* user_data) +void reverse_proxy_client_set_status_callback(reverse_proxy_client_t client, reverse_proxy_status_cb_t status_callback, void* user_data)  {  	if (!client) {  		return; @@ -676,7 +676,7 @@ LIBIMOBILEDEVICE_API void reverse_proxy_client_set_status_callback(reverse_proxy  	client->status_cb_user_data = user_data;  } -LIBIMOBILEDEVICE_API void reverse_proxy_client_set_log_callback(reverse_proxy_client_t client, reverse_proxy_log_cb_t log_callback, void* user_data) +void reverse_proxy_client_set_log_callback(reverse_proxy_client_t client, reverse_proxy_log_cb_t log_callback, void* user_data)  {  	if (!client) {  		return; @@ -685,7 +685,7 @@ LIBIMOBILEDEVICE_API void reverse_proxy_client_set_log_callback(reverse_proxy_cl  	client->log_cb_user_data = user_data;  } -LIBIMOBILEDEVICE_API void reverse_proxy_client_set_data_callback(reverse_proxy_client_t client, reverse_proxy_data_cb_t data_callback, void* user_data) +void reverse_proxy_client_set_data_callback(reverse_proxy_client_t client, reverse_proxy_data_cb_t data_callback, void* user_data)  {  	if (!client) {  		return; diff --git a/src/reverse_proxy.h b/src/reverse_proxy.h index 17eabac..7f441bd 100644 --- a/src/reverse_proxy.h +++ b/src/reverse_proxy.h @@ -22,6 +22,7 @@  #ifndef __REVERSE_PROXY_H  #define __REVERSE_PROXY_H +#include "idevice.h"  #include "libimobiledevice/reverse_proxy.h"  #include "service.h" diff --git a/src/sbservices.c b/src/sbservices.c index ccb7c4b..5df5122 100644 --- a/src/sbservices.c +++ b/src/sbservices.c @@ -24,7 +24,11 @@  #endif  #include <string.h>  #include <stdlib.h> + +#ifndef _MSC_VER  #include <unistd.h> +#endif +  #include <plist/plist.h>  #include "sbservices.h" @@ -79,7 +83,7 @@ static sbservices_error_t sbservices_error(property_list_service_error_t err)  	return SBSERVICES_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t service, sbservices_client_t *client) +sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t service, sbservices_client_t *client)  {  	property_list_service_client_t plistclient = NULL;  	sbservices_error_t err = sbservices_error(property_list_service_client_new(device, service, &plistclient)); @@ -95,14 +99,14 @@ LIBIMOBILEDEVICE_API sbservices_error_t sbservices_client_new(idevice_t device,  	return SBSERVICES_E_SUCCESS;  } -LIBIMOBILEDEVICE_API sbservices_error_t sbservices_client_start_service(idevice_t device, sbservices_client_t * client, const char* label) +sbservices_error_t sbservices_client_start_service(idevice_t device, sbservices_client_t * client, const char* label)  {  	sbservices_error_t err = SBSERVICES_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, SBSERVICES_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(sbservices_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API sbservices_error_t sbservices_client_free(sbservices_client_t client) +sbservices_error_t sbservices_client_free(sbservices_client_t client)  {  	if (!client)  		return SBSERVICES_E_INVALID_ARG; @@ -115,7 +119,7 @@ LIBIMOBILEDEVICE_API sbservices_error_t sbservices_client_free(sbservices_client  	return err;  } -LIBIMOBILEDEVICE_API sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t *state, const char *format_version) +sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t *state, const char *format_version)  {  	if (!client || !client->parent || !state)  		return SBSERVICES_E_INVALID_ARG; @@ -155,7 +159,7 @@ leave_unlock:  	return res;  } -LIBIMOBILEDEVICE_API sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist_t newstate) +sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist_t newstate)  {  	if (!client || !client->parent || !newstate)  		return SBSERVICES_E_INVALID_ARG; @@ -172,7 +176,10 @@ LIBIMOBILEDEVICE_API sbservices_error_t sbservices_set_icon_state(sbservices_cli  	if (res != SBSERVICES_E_SUCCESS) {  		debug_info("could not send plist, error %d", res);  	} -	/* NO RESPONSE */ + +	uint32_t bytes = 0; +	service_receive_with_timeout(client->parent->parent, malloc(4), 4, &bytes, 2000); +	debug_info("setIconState response: %u", bytes);  	if (dict) {  		plist_free(dict); @@ -181,7 +188,7 @@ LIBIMOBILEDEVICE_API sbservices_error_t sbservices_set_icon_state(sbservices_cli  	return res;  } -LIBIMOBILEDEVICE_API sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, const char *bundleId, char **pngdata, uint64_t *pngsize) +sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, const char *bundleId, char **pngdata, uint64_t *pngsize)  {  	if (!client || !client->parent || !bundleId || !pngdata)  		return SBSERVICES_E_INVALID_ARG; @@ -218,7 +225,7 @@ leave_unlock:  	return res;  } -LIBIMOBILEDEVICE_API sbservices_error_t sbservices_get_interface_orientation(sbservices_client_t client, sbservices_interface_orientation_t* interface_orientation) +sbservices_error_t sbservices_get_interface_orientation(sbservices_client_t client, sbservices_interface_orientation_t* interface_orientation)  {  	if (!client || !client->parent || !interface_orientation)  		return SBSERVICES_E_INVALID_ARG; @@ -256,7 +263,7 @@ leave_unlock:  	return res;  } -LIBIMOBILEDEVICE_API sbservices_error_t sbservices_get_home_screen_wallpaper_pngdata(sbservices_client_t client, char **pngdata, uint64_t *pngsize) +sbservices_error_t sbservices_get_home_screen_wallpaper_pngdata(sbservices_client_t client, char **pngdata, uint64_t *pngsize)  {  	if (!client || !client->parent || !pngdata)  		return SBSERVICES_E_INVALID_ARG; diff --git a/src/sbservices.h b/src/sbservices.h index 39d822c..b67281e 100644 --- a/src/sbservices.h +++ b/src/sbservices.h @@ -22,6 +22,7 @@  #ifndef __SBSERVICES_H  #define __SBSERVICES_H +#include "idevice.h"  #include "libimobiledevice/sbservices.h"  #include "property_list_service.h"  #include <libimobiledevice-glue/thread.h> diff --git a/src/screenshotr.c b/src/screenshotr.c index 77835da..c3cc9ba 100644 --- a/src/screenshotr.c +++ b/src/screenshotr.c @@ -65,7 +65,7 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err)  	return SCREENSHOTR_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service, +screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service,  					   screenshotr_client_t * client)  {  	if (!device || !service || service->port == 0 || !client || *client) @@ -93,14 +93,14 @@ LIBIMOBILEDEVICE_API screenshotr_error_t screenshotr_client_new(idevice_t device  	return ret;  } -LIBIMOBILEDEVICE_API screenshotr_error_t screenshotr_client_start_service(idevice_t device, screenshotr_client_t * client, const char* label) +screenshotr_error_t screenshotr_client_start_service(idevice_t device, screenshotr_client_t * client, const char* label)  {  	screenshotr_error_t err = SCREENSHOTR_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, SCREENSHOTR_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(screenshotr_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API screenshotr_error_t screenshotr_client_free(screenshotr_client_t client) +screenshotr_error_t screenshotr_client_free(screenshotr_client_t client)  {  	if (!client)  		return SCREENSHOTR_E_INVALID_ARG; @@ -110,7 +110,7 @@ LIBIMOBILEDEVICE_API screenshotr_error_t screenshotr_client_free(screenshotr_cli  	return err;  } -LIBIMOBILEDEVICE_API screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize) +screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize)  {  	if (!client || !client->parent || !imgdata)  		return SCREENSHOTR_E_INVALID_ARG; diff --git a/src/screenshotr.h b/src/screenshotr.h index 47d4e42..1319ec0 100644 --- a/src/screenshotr.h +++ b/src/screenshotr.h @@ -22,6 +22,7 @@  #ifndef __SCREENSHOTR_H  #define __SCREENSHOTR_H +#include "idevice.h"  #include "libimobiledevice/screenshotr.h"  #include "device_link_service.h" diff --git a/src/service.c b/src/service.c index 6c9d109..9474021 100644 --- a/src/service.c +++ b/src/service.c @@ -56,7 +56,7 @@ static service_error_t idevice_to_service_error(idevice_error_t err)  	return SERVICE_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API service_error_t service_client_new(idevice_t device, lockdownd_service_descriptor_t service, service_client_t *client) +service_error_t service_client_new(idevice_t device, lockdownd_service_descriptor_t service, service_client_t *client)  {  	if (!device || !service || service->port == 0 || !client || *client)  		return SERVICE_E_INVALID_ARG; @@ -80,7 +80,7 @@ LIBIMOBILEDEVICE_API service_error_t service_client_new(idevice_t device, lockdo  	return SERVICE_E_SUCCESS;  } -LIBIMOBILEDEVICE_API service_error_t service_client_factory_start_service(idevice_t device, const char* service_name, void **client, const char* label, int32_t (*constructor_func)(idevice_t, lockdownd_service_descriptor_t, void**), int32_t *error_code) +service_error_t service_client_factory_start_service(idevice_t device, const char* service_name, void **client, const char* label, int32_t (*constructor_func)(idevice_t, lockdownd_service_descriptor_t, void**), int32_t *error_code)  {  	*client = NULL; @@ -119,7 +119,7 @@ LIBIMOBILEDEVICE_API service_error_t service_client_factory_start_service(idevic  	return (ec == SERVICE_E_SUCCESS) ? SERVICE_E_SUCCESS : SERVICE_E_START_SERVICE_ERROR;  } -LIBIMOBILEDEVICE_API service_error_t service_client_free(service_client_t client) +service_error_t service_client_free(service_client_t client)  {  	if (!client)  		return SERVICE_E_INVALID_ARG; @@ -132,7 +132,7 @@ LIBIMOBILEDEVICE_API service_error_t service_client_free(service_client_t client  	return err;  } -LIBIMOBILEDEVICE_API service_error_t service_send(service_client_t client, const char* data, uint32_t size, uint32_t *sent) +service_error_t service_send(service_client_t client, const char* data, uint32_t size, uint32_t *sent)  {  	service_error_t res = SERVICE_E_UNKNOWN_ERROR;  	uint32_t bytes = 0; @@ -153,7 +153,7 @@ LIBIMOBILEDEVICE_API service_error_t service_send(service_client_t client, const  	return res;  } -LIBIMOBILEDEVICE_API service_error_t service_receive_with_timeout(service_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout) +service_error_t service_receive_with_timeout(service_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout)  {  	service_error_t res = SERVICE_E_UNKNOWN_ERROR;  	uint32_t bytes = 0; @@ -174,31 +174,31 @@ LIBIMOBILEDEVICE_API service_error_t service_receive_with_timeout(service_client  	return res;  } -LIBIMOBILEDEVICE_API service_error_t service_receive(service_client_t client, char* data, uint32_t size, uint32_t *received) +service_error_t service_receive(service_client_t client, char* data, uint32_t size, uint32_t *received)  {  	return service_receive_with_timeout(client, data, size, received, 30000);  } -LIBIMOBILEDEVICE_API service_error_t service_enable_ssl(service_client_t client) +service_error_t service_enable_ssl(service_client_t client)  {  	if (!client || !client->connection)  		return SERVICE_E_INVALID_ARG;  	return idevice_to_service_error(idevice_connection_enable_ssl(client->connection));  } -LIBIMOBILEDEVICE_API service_error_t service_disable_ssl(service_client_t client) +service_error_t service_disable_ssl(service_client_t client)  {  	return service_disable_bypass_ssl(client, 0);  } -LIBIMOBILEDEVICE_API service_error_t service_disable_bypass_ssl(service_client_t client, uint8_t sslBypass) +service_error_t service_disable_bypass_ssl(service_client_t client, uint8_t sslBypass)  {  	if (!client || !client->connection)  		return SERVICE_E_INVALID_ARG;  	return idevice_to_service_error(idevice_connection_disable_bypass_ssl(client->connection, sslBypass));  } -LIBIMOBILEDEVICE_API service_error_t service_get_connection(service_client_t client, idevice_connection_t *connection) +service_error_t service_get_connection(service_client_t client, idevice_connection_t *connection)  {  	if (!client || !client->connection || !connection)  		return SERVICE_E_INVALID_ARG; diff --git a/src/service.h b/src/service.h index 3fc3077..071fe3f 100644 --- a/src/service.h +++ b/src/service.h @@ -21,9 +21,9 @@  #ifndef SERVICE_H  #define SERVICE_H +#include "idevice.h"  #include "libimobiledevice/service.h"  #include "libimobiledevice/lockdown.h" -#include "idevice.h"  struct service_client_private {  	idevice_connection_t connection; diff --git a/src/syslog_relay.c b/src/syslog_relay.c index ec9eca5..9f4296e 100644 --- a/src/syslog_relay.c +++ b/src/syslog_relay.c @@ -67,7 +67,7 @@ static syslog_relay_error_t syslog_relay_error(service_error_t err)  	return SYSLOG_RELAY_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, syslog_relay_client_t * client) +syslog_relay_error_t syslog_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, syslog_relay_client_t * client)  {  	*client = NULL; @@ -95,14 +95,14 @@ LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_client_new(idevice_t devi  	return 0;  } -LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_client_start_service(idevice_t device, syslog_relay_client_t * client, const char* label) +syslog_relay_error_t syslog_relay_client_start_service(idevice_t device, syslog_relay_client_t * client, const char* label)  {  	syslog_relay_error_t err = SYSLOG_RELAY_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, SYSLOG_RELAY_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(syslog_relay_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_client_free(syslog_relay_client_t client) +syslog_relay_error_t syslog_relay_client_free(syslog_relay_client_t client)  {  	if (!client)  		return SYSLOG_RELAY_E_INVALID_ARG; @@ -113,12 +113,12 @@ LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_client_free(syslog_relay_  	return err;  } -LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_receive(syslog_relay_client_t client, char* data, uint32_t size, uint32_t *received) +syslog_relay_error_t syslog_relay_receive(syslog_relay_client_t client, char* data, uint32_t size, uint32_t *received)  {  	return syslog_relay_receive_with_timeout(client, data, size, received, 1000);  } -LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_receive_with_timeout(syslog_relay_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout) +syslog_relay_error_t syslog_relay_receive_with_timeout(syslog_relay_client_t client, char* data, uint32_t size, uint32_t *received, unsigned int timeout)  {  	syslog_relay_error_t res = SYSLOG_RELAY_E_UNKNOWN_ERROR;  	int bytes = 0; @@ -175,7 +175,7 @@ void *syslog_relay_worker(void *arg)  	return NULL;  } -LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_start_capture(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data) +syslog_relay_error_t syslog_relay_start_capture(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data)  {  	if (!client || !callback)  		return SYSLOG_RELAY_E_INVALID_ARG; @@ -203,7 +203,7 @@ LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_start_capture(syslog_rela  	return res;  } -LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_start_capture_raw(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data) +syslog_relay_error_t syslog_relay_start_capture_raw(syslog_relay_client_t client, syslog_relay_receive_cb_t callback, void* user_data)  {  	if (!client || !callback)  		return SYSLOG_RELAY_E_INVALID_ARG; @@ -231,7 +231,7 @@ LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_start_capture_raw(syslog_  	return res;  } -LIBIMOBILEDEVICE_API syslog_relay_error_t syslog_relay_stop_capture(syslog_relay_client_t client) +syslog_relay_error_t syslog_relay_stop_capture(syslog_relay_client_t client)  {  	if (client->worker) {  		/* notify thread to finish */ diff --git a/src/syslog_relay.h b/src/syslog_relay.h index 86d798e..d5263e2 100644 --- a/src/syslog_relay.h +++ b/src/syslog_relay.h @@ -22,6 +22,7 @@  #ifndef _SYSLOG_RELAY_H  #define _SYSLOG_RELAY_H +#include "idevice.h"  #include "libimobiledevice/syslog_relay.h"  #include "service.h"  #include <libimobiledevice-glue/thread.h> diff --git a/src/webinspector.c b/src/webinspector.c index 3360597..f960fcc 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  	return WEBINSPECTOR_E_UNKNOWN_ERROR;  } -LIBIMOBILEDEVICE_API webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t service, webinspector_client_t * client) +webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t service, webinspector_client_t * client)  {  	*client = NULL; @@ -89,14 +89,14 @@ LIBIMOBILEDEVICE_API webinspector_error_t webinspector_client_new(idevice_t devi  	return 0;  } -LIBIMOBILEDEVICE_API webinspector_error_t webinspector_client_start_service(idevice_t device, webinspector_client_t * client, const char* label) +webinspector_error_t webinspector_client_start_service(idevice_t device, webinspector_client_t * client, const char* label)  {  	webinspector_error_t err = WEBINSPECTOR_E_UNKNOWN_ERROR;  	service_client_factory_start_service(device, WEBINSPECTOR_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(webinspector_client_new), &err);  	return err;  } -LIBIMOBILEDEVICE_API webinspector_error_t webinspector_client_free(webinspector_client_t client) +webinspector_error_t webinspector_client_free(webinspector_client_t client)  {  	if (!client)  		return WEBINSPECTOR_E_INVALID_ARG; @@ -107,7 +107,7 @@ LIBIMOBILEDEVICE_API webinspector_error_t webinspector_client_free(webinspector_  	return err;  } -LIBIMOBILEDEVICE_API webinspector_error_t webinspector_send(webinspector_client_t client, plist_t plist) +webinspector_error_t webinspector_send(webinspector_client_t client, plist_t plist)  {  	webinspector_error_t res = WEBINSPECTOR_E_UNKNOWN_ERROR; @@ -164,12 +164,12 @@ LIBIMOBILEDEVICE_API webinspector_error_t webinspector_send(webinspector_client_  	return res;  } -LIBIMOBILEDEVICE_API webinspector_error_t webinspector_receive(webinspector_client_t client, plist_t * plist) +webinspector_error_t webinspector_receive(webinspector_client_t client, plist_t * plist)  {  	return webinspector_receive_with_timeout(client, plist, 5000);  } -LIBIMOBILEDEVICE_API webinspector_error_t webinspector_receive_with_timeout(webinspector_client_t client, plist_t * plist, uint32_t timeout_ms) +webinspector_error_t webinspector_receive_with_timeout(webinspector_client_t client, plist_t * plist, uint32_t timeout_ms)  {  	webinspector_error_t res = WEBINSPECTOR_E_UNKNOWN_ERROR;  	plist_t message = NULL; diff --git a/src/webinspector.h b/src/webinspector.h index 67421bc..d249c58 100644 --- a/src/webinspector.h +++ b/src/webinspector.h @@ -22,6 +22,7 @@  #ifndef __WEBINSPECTOR_H  #define __WEBINSPECTOR_H +#include "idevice.h"  #include "libimobiledevice/webinspector.h"  #include "property_list_service.h" | 
