diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/Makefile.am | 41 | ||||
| -rw-r--r-- | dev/afccheck.c | 147 | ||||
| -rw-r--r-- | dev/filerelaytest.c | 151 | ||||
| -rw-r--r-- | dev/housearresttest.c | 219 | ||||
| -rw-r--r-- | dev/ideviceclient.c | 272 | ||||
| -rw-r--r-- | dev/ideviceheartbeat.c | 157 | ||||
| -rw-r--r-- | dev/lckdclient.c | 163 | 
7 files changed, 0 insertions, 1150 deletions
| diff --git a/dev/Makefile.am b/dev/Makefile.am deleted file mode 100644 index 89ef75b..0000000 --- a/dev/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/include - -AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(openssl_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) -AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(openssl_LIBS) $(libplist_LIBS) - -if ENABLE_DEVTOOLS -noinst_PROGRAMS = ideviceclient afccheck filerelaytest housearresttest lckd-client ideviceheartbeat - -ideviceclient_SOURCES = ideviceclient.c -ideviceclient_CFLAGS = $(AM_CFLAGS) -ideviceclient_LDFLAGS = $(AM_LDFLAGS) -ideviceclient_LDADD = $(top_builddir)/src/libimobiledevice.la - -lckd_client_SOURCES = lckdclient.c -lckd_client_CFLAGS = $(AM_CFLAGS) $(libglib2_CFLAGS) -lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS) $(libglib2_LIBS) -lckd_client_LDADD = $(top_builddir)/src/libimobiledevice.la - -afccheck_SOURCES = afccheck.c -afccheck_CFLAGS = -I$(top_srcdir) $(AM_CFLAGS) -afccheck_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS) -afccheck_LDADD = $(top_builddir)/src/libimobiledevice.la - -filerelaytest_SOURCES = filerelaytest.c -filerelaytest_CFLAGS = $(AM_CFLAGS) -filerelaytest_LDFLAGS = $(AM_LDFLAGS) -filerelaytest_LDADD = $(top_builddir)/src/libimobiledevice.la - -housearresttest_SOURCES = housearresttest.c -housearresttest_CFLAGS = $(AM_CFLAGS) -housearresttest_LDFLAGS = $(AM_LDFLAGS) -housearresttest_LDADD = $(top_builddir)/src/libimobiledevice.la - -ideviceheartbeat_SOURCES = ideviceheartbeat.c -ideviceheartbeat_CFLAGS = $(AM_CFLAGS) -ideviceheartbeat_LDFLAGS = $(AM_LDFLAGS) -ideviceheartbeat_LDADD = $(top_builddir)/src/libimobiledevice.la - -endif # ENABLE_DEVTOOLS - -EXTRA_DIST = ideviceclient.c lckdclient.c afccheck.c filerelaytest.c housearresttest.c ideviceheartbeat.c diff --git a/dev/afccheck.c b/dev/afccheck.c deleted file mode 100644 index fed8538..0000000 --- a/dev/afccheck.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * afccheck.c - * creates threads and check communication through AFC is done rigth - * - * Copyright (c) 2008 Jonathan Beck 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 - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <libimobiledevice/libimobiledevice.h> -#include <libimobiledevice/lockdown.h> -#include <libimobiledevice/afc.h> -#include "common/thread.h" - -#define BUFFER_SIZE 20000 -#define NB_THREADS 10 - - -typedef struct { -	afc_client_t afc; -	int id; -} param; - - -static void* check_afc(void *data) -{ -	//prepare a buffer -	unsigned int buffersize = BUFFER_SIZE * sizeof(unsigned int); -	int *buf = (int *) malloc(buffersize); -	int *buf2 = (int *) malloc(buffersize); -	unsigned int bytes = 0; -	uint64_t position = 0; - -	//fill buffer -	int i = 0; -	for (i = 0; i < BUFFER_SIZE; i++) { -		buf[i] = ((param *) data)->id * i; -	} - -	//now  writes buffer on device -	uint64_t file = 0; -	char path[50]; -	sprintf(path, "/Buf%i", ((param *) data)->id); -	afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RW, &file); -	afc_file_write(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); -	afc_file_close(((param *) data)->afc, file); -	file = 0; -	if (bytes != buffersize) -		printf("Write operation failed\n"); - -	//now read it -	bytes = 0; -	afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); -	afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize/2, &bytes); -	afc_file_read(((param *) data)->afc, file, (char *) buf2 + (buffersize/2), buffersize/2, &bytes); -	if(AFC_E_SUCCESS != afc_file_tell(((param *) data)->afc, file, &position)) -		printf("Tell operation failed\n"); -	afc_file_close(((param *) data)->afc, file); -	if (position != buffersize) -		printf("Read operation failed\n"); - -	//compare buffers -	for (i = 0; i < BUFFER_SIZE; i++) { -		if (buf[i] != buf2[i]) { -			printf("Buffers are differents, stream corrupted\n"); -			break; -		} -	} - -	//cleanup -	afc_remove_path(((param *) data)->afc, path); -	return NULL; -} - -int main(int argc, char *argv[]) -{ -	lockdownd_client_t client = NULL; -	idevice_t phone = NULL; -	lockdownd_service_descriptor_t service = NULL; -	afc_client_t afc = NULL; - -	if (argc > 1 && !strcasecmp(argv[1], "--debug")) { -		idevice_set_debug_level(1); -	} else { -		idevice_set_debug_level(0); -	} - -	if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) { -		printf("No device found, is it plugged in?\n"); -		return 1; -	} - -	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "afccheck")) { -		idevice_free(phone); -		return 1; -	} - -	if (LOCKDOWN_E_SUCCESS != lockdownd_start_service(client, "com.apple.afc", &service) || !service || !service->port) { -		lockdownd_client_free(client); -		idevice_free(phone); -		fprintf(stderr, "Something went wrong when starting AFC."); -		return 1; -	} - -	afc_client_new(phone, service, &afc); - -	if (service) { -		lockdownd_service_descriptor_free(service); -		service = NULL; -	} - -	thread_t threads[NB_THREADS]; -	param data[NB_THREADS]; - -	int i = 0; -	for (i = 0; i < NB_THREADS; i++) { -		data[i].afc = afc; -		data[i].id = i + 1; -		thread_new(&threads[i], check_afc, data + i); -	} - -	for (i = 0; i < NB_THREADS; i++) { -		thread_join(threads[i]); -		thread_free(threads[i]); -	} - -	lockdownd_client_free(client); -	idevice_free(phone); - -	return 0; -} diff --git a/dev/filerelaytest.c b/dev/filerelaytest.c deleted file mode 100644 index 6983f1d..0000000 --- a/dev/filerelaytest.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * filerelaytest.c - * Simple Test program showing the usage of the file_relay interface. - * - * Copyright (c) 2010 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 - */ -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <libimobiledevice/libimobiledevice.h> -#include <libimobiledevice/lockdown.h> -#include <libimobiledevice/file_relay.h> - -int main(int argc, char **argv) -{ -	idevice_t dev = NULL; -	lockdownd_client_t client = NULL; -	lockdownd_service_descriptor_t service = NULL; -	file_relay_client_t frc = NULL; -	file_relay_error_t frc_error = FILE_RELAY_E_SUCCESS; -	idevice_connection_t dump = NULL; -	const char **sources; -	const char *default_sources[] = {"AppleSupport", "Network", "VPN", "WiFi", "UserDatabases", "CrashReporter", "tmp", "SystemConfiguration", NULL}; -	int i = 0; - -	if (idevice_new(&dev, NULL) != IDEVICE_E_SUCCESS) { -		printf("No device connected?!\n"); -		goto leave_cleanup; -	} - -	printf("Connecting...\n"); -	if (lockdownd_client_new_with_handshake(dev, &client, NULL) != LOCKDOWN_E_SUCCESS) { -		printf("Could not connect to lockdownd!\n"); -		goto leave_cleanup; -	} - -	if (lockdownd_start_service(client, FILE_RELAY_SERVICE_NAME, &service) != LOCKDOWN_E_SUCCESS) { -		printf("Could not start file_relay service!\n"); -		goto leave_cleanup; -	} - -	if (client) { -		lockdownd_client_free(client); -		client = NULL; -	} - -	if (file_relay_client_new(dev, service, &frc) != FILE_RELAY_E_SUCCESS) { -		printf("Could not connect to file_relay service!\n"); -		goto leave_cleanup; -	} - -	if (service) { -		lockdownd_service_descriptor_free(service); -		service = NULL; -	} - -	if (argc > 1) { -		sources = calloc(1, argc * sizeof(char *)); -		argc--; -		argv++; -		for (i = 0; i < argc; i++) { -			sources[i] = argv[i]; -		} -	} -	else { -		sources = default_sources; -	} - -	printf("Requesting "); -	i = 0; -	while (sources[i]) { -		printf(" %s", sources[i]); -		i++; -		if (sources[i]) -			printf(","); -	} -	printf("\n"); - -	frc_error = file_relay_request_sources(frc, sources, &dump); -	if (frc_error != FILE_RELAY_E_SUCCESS) { -		printf("Could not request sources.\n"); -		switch (frc_error) { -			case FILE_RELAY_E_INVALID_SOURCE: -				printf("At least one of the given sources is invalid and was rejected.\n"); -				break; -			case FILE_RELAY_E_STAGING_EMPTY: -				printf("Staging is empty. Perhaps there is no data for the requested sources available.\n"); -				break; -			case FILE_RELAY_E_PERMISSION_DENIED: -				printf("Permission denied by device. Possibly missing a signed preferences profile.\n"); -				break; -			default: -				printf("An unknown error occoured.\n"); -				break; -		} -		goto leave_cleanup; -	} - -	if (!dump) { -		printf("Did not get connection!\n"); -		goto leave_cleanup; -	} - -	uint32_t cnt = 0; -	uint32_t len = 0; -	char buf[4096]; -	FILE *f = fopen("dump.cpio.gz", "wb"); -	if (!f) { -		fprintf(stderr, "dump.cpio.gz: %s\n", strerror(errno)); -		return EXIT_FAILURE; -	} -	setbuf(stdout, NULL); -	printf("Receiving "); -	while (idevice_connection_receive(dump, buf, 4096, &len) == IDEVICE_E_SUCCESS) { -		fwrite(buf, 1, len, f); -		cnt += len; -		printf("."); -		len = 0; -	} -	printf("\n"); -	fclose(f); -	printf("Total size received: %d\n", cnt); - -leave_cleanup: -	if (frc) { -		file_relay_client_free(frc); -	} -	if (client) { -		lockdownd_client_free(client); -	} -	if (dev) { -		idevice_free(dev); -	} - -	return 0; -} diff --git a/dev/housearresttest.c b/dev/housearresttest.c deleted file mode 100644 index 6586787..0000000 --- a/dev/housearresttest.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * housearresttest.c - * Simple Test program showing the usage of the house_arrest interface. - * - * Copyright (c) 2010 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 - */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <libimobiledevice/libimobiledevice.h> -#include <libimobiledevice/lockdown.h> -#include <libimobiledevice/house_arrest.h> -#include <libimobiledevice/afc.h> - -static void print_usage(int argc, char **argv) -{ -	char *name = NULL; - -	name = strrchr(argv[0], '/'); -	printf("Usage: %s [OPTIONS] APPID\n", (name ? name + 1: argv[0])); -	printf("Test the house_arrest service.\n\n"); -	printf("  -d, --debug\t\tenable communication debugging\n"); -	printf("  -u, --udid UDID\ttarget specific device by its 40-digit device UDID\n"); -	printf("  -t, --test\t\ttest creating, writing, and deleting a file\n"); -	printf("  -h, --help\t\tprints usage information\n"); -	printf("\n"); -} - -int main(int argc, char **argv) -{ -	idevice_t dev = NULL; -	lockdownd_client_t client = NULL; -	house_arrest_client_t hac = NULL; -	house_arrest_error_t res; -	int i; -	char *udid = NULL; -	const char *appid = NULL; -	int test_file_io = 0; - -	/* parse cmdline args */ -	for (i = 1; i < argc; i++) { -		if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { -			idevice_set_debug_level(1); -			continue; -		} -		else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) { -			i++; -			if (!argv[i] || (strlen(argv[i]) != 40)) { -				print_usage(argc, argv); -				return 0; -			} -			udid = strdup(argv[i]); -			continue; -		} -		else if (!strcmp(argv[i], "-t") || !strcmp(argv[i], "--test")) { -			test_file_io = 1; -			continue; -		} -		else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { -			print_usage(argc, argv); -			return 0; -		} -		else { -			appid = argv[i]; -			break; -		} -	} - -	if (!appid) { -		print_usage(argc, argv); -		return 0; -	} - -	if (idevice_new(&dev, udid) != IDEVICE_E_SUCCESS) { -		printf("no device connected?!\n"); -		goto leave_cleanup; -	} - -	if (lockdownd_client_new_with_handshake(dev, &client, NULL) != LOCKDOWN_E_SUCCESS) { -		printf("could not connect to lockdownd!\n"); -		goto leave_cleanup; -	} - -	lockdownd_service_descriptor_t service = NULL; -	if (lockdownd_start_service(client, "com.apple.mobile.house_arrest", &service) != LOCKDOWN_E_SUCCESS) { -		printf("could not start house_arrest service!\n"); -		goto leave_cleanup; -	} - -	if (client) { -		lockdownd_client_free(client); -		client = NULL; -	} - -	if (house_arrest_client_new(dev, service, &hac) != HOUSE_ARREST_E_SUCCESS) { -		printf("could not connect to house_arrest service!\n"); -		goto leave_cleanup; -	} - -	if (service) { -		lockdownd_service_descriptor_free(service); -		service = NULL; -	} - -	res = house_arrest_send_command(hac, "VendDocuments", appid); -	if (res != HOUSE_ARREST_E_SUCCESS) { -		printf("error %d when trying to get VendDocuments\n", res); -		goto leave_cleanup; -	} - -	plist_t dict = NULL; -	if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) { -		if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) { -			printf("hmmm....\n"); -			goto leave_cleanup; -		} -	} - -	plist_t node = plist_dict_get_item(dict, "Error"); -	if (node) { -		char *str = NULL; -		plist_get_string_val(node, &str); -		printf("Error: %s\n", str); -		if (str) free(str); -		plist_free(dict); -		dict = NULL; -		goto leave_cleanup; -	} -	node = plist_dict_get_item(dict, "Status"); -	if (node) { -		char *str = NULL; -		plist_get_string_val(node, &str); -		if (str && (strcmp(str, "Complete") != 0)) { -			printf("Warning: Status is not 'Complete' but '%s'\n", str); -		} -		if (str) free(str); -		plist_free(dict); -		dict = NULL; -	} -	if (dict) { -		plist_free(dict); -	} - -	afc_client_t afc = NULL; -	afc_error_t ae = afc_client_new_from_house_arrest_client(hac, &afc); -	if (ae != AFC_E_SUCCESS) { -		printf("afc error %d\n", ae); -	} -	if (ae == AFC_E_SUCCESS) { -		char **list = NULL; -		afc_read_directory(afc, "/", &list); -		printf("Directory contents:\n"); -		if (list) { -			while (list[0]) { -				if (strcmp(list[0], ".") && strcmp(list[0], "..")) { -					puts(list[0]); -				} -				list++; -			} -		} - -		if (test_file_io) { -			uint64_t tf = 0; -			printf("\n==== Performing file tests ====\n"); -			printf("Opening file 'foobar' for writing: "); -			if (afc_file_open(afc, "/foobar", AFC_FOPEN_RW, &tf) == AFC_E_SUCCESS) { -				uint32_t wb = 0; -				printf("OK\n"); - -				printf("Writing to file: "); -				if (afc_file_write(afc, tf, "test\r\n", 6, &wb) != AFC_E_SUCCESS) { -					printf("ERROR\n"); -				} else { -					printf("OK\n"); -				} -				afc_file_close(afc, tf); -				printf("Deleting file 'foobar': "); -				if (afc_remove_path(afc, "/foobar") == AFC_E_SUCCESS) { -					printf("OK\n"); -				} else { -					printf("ERROR\n"); -				} -			} else { -				printf("ERROR\n"); -			} -		} -		afc_client_free(afc); -	} else { -		printf("failed to connect to afc service, error %d\n", ae); -	} - -leave_cleanup: -	if (hac) { -		house_arrest_client_free(hac); -	} -	if (client) { -		lockdownd_client_free(client); -	} -	if (dev) { -		idevice_free(dev); -	} - -	return 0; -} diff --git a/dev/ideviceclient.c b/dev/ideviceclient.c deleted file mode 100644 index b92ae94..0000000 --- a/dev/ideviceclient.c +++ /dev/null @@ -1,272 +0,0 @@ -/* - * main.c - * Test program for testing several services. - * - * Copyright (c) 2008 Zach C. 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 - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -#ifdef WIN32 -#include <windows.h> -#define sleep(x) Sleep(x*1000) -#else -#include <unistd.h> -#endif - -#include <libimobiledevice/libimobiledevice.h> -#include <libimobiledevice/lockdown.h> -#include <libimobiledevice/afc.h> -#include <libimobiledevice/notification_proxy.h> - -static void notifier(const char *notification, void *userdata) -{ -	printf("---------------------------------------------------------\n"); -	printf("------> Notification received: %s\n", notification); -	printf("---------------------------------------------------------\n"); -} - -static void perform_notification(idevice_t phone, lockdownd_client_t client, const char *notification) -{ -	lockdownd_service_descriptor_t service = NULL; -	np_client_t np; - -	lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service); -	if (service && service->port) { -		printf("::::::::::::::: np was started ::::::::::::\n"); -		np_client_new(phone, service, &np); -		if (np) { -			printf("::::::::: PostNotification %s\n", notification); -			np_post_notification(np, notification); -			np_client_free(np); -		} -	} else { -		printf("::::::::::::::: np was NOT started ::::::::::::\n"); -	} - -	if (service) { -		lockdownd_service_descriptor_free(service); -		service = NULL; -	} -} - -int main(int argc, char *argv[]) -{ -	unsigned int bytes = 0; -	uint16_t i = 0; -	lockdownd_service_descriptor_t service = NULL; -	lockdownd_client_t client = NULL; -	idevice_t phone = NULL; -	uint64_t lockfile = 0; -	np_client_t gnp = NULL; - -	if (argc > 1 && !strcasecmp(argv[1], "--debug")) { -		idevice_set_debug_level(1); -	} else { -		idevice_set_debug_level(0); -	} - -	if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) { -		printf("No device found, is it plugged in?\n"); -		return -1; -	} - -	char *udid = NULL; -	if (IDEVICE_E_SUCCESS == idevice_get_udid(phone, &udid)) { -		printf("DeviceUniqueID : %s\n", udid); -	} -	if (udid) -		free(udid); - -	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "ideviceclient")) { -		idevice_free(phone); -		printf("Exiting.\n"); -		return -1; -	} - -	char *nnn = NULL; -	if (LOCKDOWN_E_SUCCESS == lockdownd_get_device_name(client, &nnn)) { -		printf("DeviceName : %s\n", nnn); -		free(nnn); -	} - -	lockdownd_start_service(client, "com.apple.afc", &service); - -	if (service && service->port) { -		afc_client_t afc = NULL; -		afc_client_new(phone, service, &afc); - -		if (afc) { -			service->port = 0; -			service->ssl_enabled = 0; -			lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service); -			if (service->port) { -				printf("Notification Proxy started.\n"); -				np_client_new(phone, service, &gnp); -			} else { -				printf("ERROR: Notification proxy could not be started.\n"); -			} - -			if (gnp) { -				const char *nspec[5] = { -					NP_SYNC_CANCEL_REQUEST, -					NP_SYNC_SUSPEND_REQUEST, -					NP_SYNC_RESUME_REQUEST, -					NP_ITDBPREP_DID_END, -					NULL -				}; -				np_observe_notifications(gnp, nspec); -				np_set_notify_callback(gnp, notifier, NULL); -			} - -			perform_notification(phone, client, NP_SYNC_WILL_START); - -			afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); -			if (lockfile) { -				printf("locking file\n"); -				afc_file_lock(afc, lockfile, AFC_LOCK_EX); - -				perform_notification(phone, client, NP_SYNC_DID_START); -			} - -			char **dirs = NULL; -			afc_read_directory(afc, "/eafaedf", &dirs); -			if (!dirs) -				afc_read_directory(afc, "/", &dirs); -			printf("Directory time.\n"); -			for (i = 0; dirs[i]; i++) { -				printf("/%s\n", dirs[i]); -				free(dirs[i]); -			} -			if (dirs) -				free(dirs); - -			dirs = NULL; -			afc_get_device_info(afc, &dirs); -			if (dirs) { -				for (i = 0; dirs[i]; i += 2) { -					printf("%s: %s\n", dirs[i], dirs[i + 1]); -					free(dirs[i]); -				} -				free(dirs); -			} - -			uint64_t my_file = 0; -			char **info = NULL; -			uint64_t fsize = 0; -			if (AFC_E_SUCCESS == afc_get_file_info(afc, "/readme.libimobiledevice.fx", &info) && info) { -				for (i = 0; info[i]; i += 2) { -					printf("%s: %s\n", info[i], info[i+1]); -					if (!strcmp(info[i], "st_size")) { -						fsize = atoll(info[i+1]); -					} -				} -			} - -			if (AFC_E_SUCCESS == -				afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { -				printf("A file size: %llu\n", (long long)fsize); -				char *file_data = (char *) malloc(sizeof(char) * fsize); -				afc_file_read(afc, my_file, file_data, fsize, &bytes); -				if (bytes > 0) { -					printf("The file's data:\n"); -					fwrite(file_data, 1, bytes, stdout); -				} -				printf("\nClosing my file.\n"); -				afc_file_close(afc, my_file); -				free(file_data); -			} else -				printf("couldn't open a file\n"); - -			afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_WR, &my_file); -			if (my_file) { -				char *outdatafile = strdup("this is a bitchin text file\n"); -				afc_file_write(afc, my_file, outdatafile, strlen(outdatafile), &bytes); -				free(outdatafile); -				if (bytes > 0) -					printf("Wrote a surprise. ;)\n"); -				else -					printf("I wanted to write a surprise, but... :(\n"); -				afc_file_close(afc, my_file); -			} -			printf("Deleting a file...\n"); -			bytes = afc_remove_path(afc, "/delme"); -			if (bytes) -				printf("Success.\n"); -			else -				printf("Failure. (expected unless you have a /delme file on your phone)\n"); - -			printf("Renaming a file...\n"); -			bytes = afc_rename_path(afc, "/renme", "/renme2"); -			if (bytes > 0) -				printf("Success.\n"); -			else -				printf("Failure. (expected unless you have a /renme file on your phone)\n"); - -			printf("Seek & read\n"); -			afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_RDONLY, &my_file); -			if (AFC_E_SUCCESS != afc_file_seek(afc, my_file, 5, SEEK_CUR)) -				printf("WARN: SEEK DID NOT WORK\n"); -			char *threeletterword = (char *) malloc(sizeof(char) * 5); -			afc_file_read(afc, my_file, threeletterword, 3, &bytes); -			threeletterword[3] = '\0'; -			if (bytes > 0) -				printf("Result: %s\n", threeletterword); -			else -				printf("Couldn't read!\n"); -			free(threeletterword); -			afc_file_close(afc, my_file); -		} - -		if (gnp && lockfile) { -			printf("XXX sleeping\n"); -			sleep(5); - -			printf("XXX unlocking file\n"); -			afc_file_lock(afc, lockfile, AFC_LOCK_UN); - -			printf("XXX closing file\n"); -			afc_file_close(afc, lockfile); - -			printf("XXX sleeping\n"); -			sleep(5); -			//perform_notification(phone, client, NP_SYNC_DID_FINISH); -		} - -		if (gnp) { -			np_client_free(gnp); -			gnp = NULL; -		} - -		afc_client_free(afc); - -		lockdownd_service_descriptor_free(service); -		service = NULL; -	} else { -		printf("Start service failure.\n"); -	} - -	printf("All done.\n"); - -	lockdownd_client_free(client); -	idevice_free(phone); - -	return 0; -} diff --git a/dev/ideviceheartbeat.c b/dev/ideviceheartbeat.c deleted file mode 100644 index a140589..0000000 --- a/dev/ideviceheartbeat.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * ideviceheartbeat.c - * Simple utility which keeps a "heartbeat service" connection alive - * - * Copyright (c) 2013 Martin Szulecki 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 - */ - -#include <stdio.h> -#include <string.h> -#include <inttypes.h> -#include <signal.h> -#include <stdlib.h> - -#include <libimobiledevice/libimobiledevice.h> -#include <libimobiledevice/heartbeat.h> - -static int quit_flag = 0; - -/** - * signal handler function for cleaning up properly - */ -static void clean_exit(int sig) -{ -	fprintf(stderr, "Exiting...\n"); -	quit_flag++; -} - -static void print_usage(int argc, char **argv) -{ -	char *name = NULL; - -	name = strrchr(argv[0], '/'); -	printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0])); -	printf("Runs in the foreground and keeps a \"heartbeat\" connection alive.\n\n"); -	printf("  -d, --debug\t\tenable communication debugging\n"); -	printf("  -u, --udid UDID\ttarget specific device by its 40-digit device UDID\n"); -	printf("  -h, --help\t\tprints usage information\n"); -	printf("\n"); -} - -int main(int argc, char *argv[]) -{ -	heartbeat_client_t heartbeat = NULL; -	idevice_t device = NULL; -	idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; -	int i; -	const char* udid = NULL; - -	signal(SIGINT, clean_exit); -	signal(SIGTERM, clean_exit); -#ifndef WIN32 -	signal(SIGQUIT, clean_exit); -	signal(SIGPIPE, SIG_IGN); -#endif -	/* parse cmdline args */ -	for (i = 1; i < argc; i++) { -		if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { -			idevice_set_debug_level(1); -			continue; -		} -		else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--udid")) { -			i++; -			if (!argv[i] || (strlen(argv[i]) != 40)) { -				print_usage(argc, argv); -				return 0; -			} -			udid = argv[i]; -			continue; -		} -		else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { -			print_usage(argc, argv); -			return 0; -		} -		else { -			print_usage(argc, argv); -			return 0; -		} -	} - -	ret = idevice_new(&device, udid); -	if (ret != IDEVICE_E_SUCCESS) { -		if (udid) { -			printf("No device found with udid %s, is it plugged in?\n", udid); -		} else { -			printf("No device found, is it plugged in?\n"); -		} -		return -1; -	} - -	/* start heartbeat service on device */ -	heartbeat_client_start_service(device, &heartbeat, "ideviceheartbeat"); -	if (heartbeat) { -		printf("< heartbeat started, listening...\n"); -	} else { -		printf("Failed to start heartbeat service\n"); -		idevice_free(device); -		return -1; -	} - -	/* main loop */ -	uint8_t b = 0; -	uint64_t interval = 10000; -	plist_t message = NULL; -	plist_t node = NULL; -	do { -		/* await a "ping" message from the device every interval seconds */ -		heartbeat_receive_with_timeout(heartbeat, &message, (uint32_t)interval); -		if (message) { -			/* report device beat settings */ -			node = plist_dict_get_item(message, "SupportsSleepyTime"); -			if (node && plist_get_node_type(node) == PLIST_BOOLEAN) { -				plist_get_bool_val(node, &b); -			} -			node = plist_dict_get_item(message, "Interval"); -			if (node && plist_get_node_type(node) == PLIST_UINT) { -				plist_get_uint_val(node, &interval); -			} - -			printf("> marco: supports_sleepy_time %d, interval %"PRIu64"\n", b, interval); - -			plist_free(message); -			message = NULL; - -			/* answer with a "pong" message */ -			message = plist_new_dict(); -			plist_dict_set_item(message, "Command", plist_new_string("Polo")); -			heartbeat_send(heartbeat, message); - -			printf("< polo\n"); - -			if (message) { -				plist_free(message); -				message = NULL; -			} -		} -	} while(!quit_flag); - -	heartbeat_client_free(heartbeat); - -	idevice_free(device); - -	return 0; -} diff --git a/dev/lckdclient.c b/dev/lckdclient.c deleted file mode 100644 index 08d798f..0000000 --- a/dev/lckdclient.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * lckdclient.c - * Rudimentary command line interface to the Lockdown protocol - * - * Copyright (c) 2008 Jonathan Beck 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 - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <readline/readline.h> -#include <readline/history.h> - -#include <libimobiledevice/libimobiledevice.h> -#include <libimobiledevice/lockdown.h> - -static char** get_tokens(const char *str) -{ -	char *strcp = strdup(str); -	char *p; -	char res_max = 8; -	char **result = NULL; -	int cnt = 0; - -	p = strtok(strcp, " "); -	if (!p) { -		result = (char**)malloc(2 * sizeof(char*)); -		result[0] = strdup(str); -		result[1] = NULL; -		return result; -	} - -	result = (char**)malloc(res_max * sizeof(char*)); -	memset(result, 0, res_max * sizeof(char*)); - -	while (p) { -		if (cnt >= res_max) { -			res_max += 8; -			result = (char**)realloc(result, res_max * sizeof(char*)); -		} -		result[cnt] = strdup(p); -		cnt++; -		p = strtok(NULL, " "); -	} - -	if (cnt >= res_max) { -		res_max += 1; -		result = (char**)realloc(result, res_max * sizeof(char*)); -		result[cnt] = NULL; -	} - -	return result; -} - -static void strfreev(char **strs) -{ -	int i = 0; -	while (strs && strs[i]) { -		free(strs[i]); -		i++; -	} -	free(strs); -} - -int main(int argc, char *argv[]) -{ -	lockdownd_client_t client = NULL; -	idevice_t phone = NULL; - -	idevice_set_debug_level(1); - -	if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) { -		printf("No device found, is it plugged in?\n"); -		return -1; -	} - -	char *udid = NULL; -	if (IDEVICE_E_SUCCESS == idevice_get_udid(phone, &udid)) { -		printf("DeviceUniqueID : %s\n", udid); -	} -	if (udid) -		free(udid); - -	if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "lckdclient")) { -		idevice_free(phone); -		return -1; -	} - -	using_history(); -	int loop = 1; -	while (loop) { -		char *cmd = readline("> "); -		if (cmd) { - -			char **args = get_tokens(cmd); - -			int len = 0; -			while (args && args[len]) { -				len++; -			} - -			if (len > 0) { -				add_history(cmd); -				if (!strcmp(*args, "quit")) -					loop = 0; - -				if (!strcmp(*args, "get") && len >= 2) { -					plist_t value = NULL; -					if (LOCKDOWN_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL,  len == 3 ? *(args + 2):*(args + 1), &value)) -					{ -						char *xml = NULL; -						uint32_t length; -						plist_to_xml(value, &xml, &length); -						printf("Success : value = %s\n", xml); -						free(xml); -					} -					else -						printf("Error\n"); - -					if (value) -						plist_free(value); -				} - -				if (!strcmp(*args, "start") && len == 2) { -					lockdownd_service_descriptor_t service = NULL; -					if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &service)) { -						printf("started service %s on port %i\n", *(args + 1), service->port); -						if (service) { -							lockdownd_service_descriptor_free(service); -							service = NULL; -						} -					} -					else -					{ -						printf("failed to start service %s on device.\n", *(args + 1)); -					} -				} -			} -			strfreev(args); -		} -		free(cmd); -		cmd = NULL; -	} -	clear_history(); -	lockdownd_client_free(client); -	idevice_free(phone); - -	return 0; -} | 
