diff options
Diffstat (limited to 'dev')
-rw-r--r-- | dev/Makefile.am | 36 | ||||
-rw-r--r-- | dev/afccheck.c | 146 | ||||
-rw-r--r-- | dev/filerelaytest.c | 108 | ||||
-rw-r--r-- | dev/housearresttest.c | 214 | ||||
-rw-r--r-- | dev/ideviceclient.c | 252 | ||||
-rw-r--r-- | dev/lckdclient.c | 115 |
6 files changed, 0 insertions, 871 deletions
diff --git a/dev/Makefile.am b/dev/Makefile.am deleted file mode 100644 index 72c00a3..0000000 --- a/dev/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -AM_CPPFLAGS = -I$(top_srcdir)/include - -AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) -AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) - -if ENABLE_DEVTOOLS -noinst_PROGRAMS = ideviceclient lckd-client afccheck filerelaytest housearresttest - -ideviceclient_SOURCES = ideviceclient.c -ideviceclient_CFLAGS = $(AM_CFLAGS) -ideviceclient_LDFLAGS = $(AM_LDFLAGS) -ideviceclient_LDADD = ../src/libimobiledevice.la - -lckd_client_SOURCES = lckdclient.c -lckd_client_CFLAGS = $(AM_CFLAGS) -lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS) -lckd_client_LDADD = ../src/libimobiledevice.la - -afccheck_SOURCES = afccheck.c -afccheck_CFLAGS = $(AM_CFLAGS) -afccheck_LDFLAGS = $(AM_LDFLAGS) -afccheck_LDADD = ../src/libimobiledevice.la - -filerelaytest_SOURCES = filerelaytest.c -filerelaytest_CFLAGS = $(AM_CFLAGS) -filerelaytest_LDFLAGS = $(AM_LDFLAGS) -filerelaytest_LDADD = ../src/libimobiledevice.la - -housearresttest_SOURCES = housearresttest.c -housearresttest_CFLAGS = $(AM_CFLAGS) -housearresttest_LDFLAGS = $(AM_LDFLAGS) -housearresttest_LDADD = ../src/libimobiledevice.la - -endif # ENABLE_DEVTOOLS - -EXTRA_DIST = ideviceclient.c lckdclient.c afccheck.c filerelaytest.c housearresttest.c diff --git a/dev/afccheck.c b/dev/afccheck.c deleted file mode 100644 index b4d8910..0000000 --- a/dev/afccheck.c +++ /dev/null @@ -1,146 +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 <glib.h> - -#include <libimobiledevice/libimobiledevice.h> -#include <libimobiledevice/lockdown.h> -#include <libimobiledevice/afc.h> - -#define BUFFER_SIZE 20000 -#define NB_THREADS 10 - - -typedef struct { - afc_client_t afc; - int id; -} param; - - -static void check_afc(gpointer 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); - g_thread_exit(0); -} - -int main(int argc, char *argv[]) -{ - lockdownd_client_t client = NULL; - idevice_t phone = NULL; - GError *err; - uint16_t port = 0; - 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", &port) && !port) { - lockdownd_client_free(client); - idevice_free(phone); - fprintf(stderr, "Something went wrong when starting AFC."); - return 1; - } - - afc_client_new(phone, port, &afc); - - //makes sure thread environment is available - if (!g_thread_supported()) - g_thread_init(NULL); - - GThread *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; - threads[i] = g_thread_create((GThreadFunc) check_afc, data + i, TRUE, &err); - } - - for (i = 0; i < NB_THREADS; i++) { - g_thread_join(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 6e611c0..0000000 --- a/dev/filerelaytest.c +++ /dev/null @@ -1,108 +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 <stdio.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; - file_relay_client_t frc = NULL; - - 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; - } - - uint16_t port = 0; - if (lockdownd_start_service(client, "com.apple.mobile.file_relay", &port) != 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, port, &frc) != FILE_RELAY_E_SUCCESS) { - printf("could not connect to file_relay service!\n"); - goto leave_cleanup; - } - - idevice_connection_t dump = NULL; - const char *sources[] = {"AppleSupport", "Network", "VPN", "WiFi", "UserDatabases", "CrashReporter", "tmp", "SystemConfiguration", NULL}; - - printf("Requesting"); - int i = 0; - while (sources[i]) { - printf(" %s", sources[i]); - i++; - } - printf("\n"); - - if (file_relay_request_sources(frc, sources, &dump) != FILE_RELAY_E_SUCCESS) { - printf("could not get sources\n"); - 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", "w"); - 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 7282a8c..0000000 --- a/dev/housearresttest.c +++ /dev/null @@ -1,214 +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, --uuid UUID\ttarget specific device by its 40-digit device UUID\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 *uuid = 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], "--uuid")) { - i++; - if (!argv[i] || (strlen(argv[i]) != 40)) { - print_usage(argc, argv); - return 0; - } - uuid = 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, uuid) != 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; - } - - uint16_t port = 0; - if (lockdownd_start_service(client, "com.apple.mobile.house_arrest", &port) != 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, port, &hac) != HOUSE_ARREST_E_SUCCESS) { - printf("could not connect to house_arrest service!\n"); - goto leave_cleanup; - } - - 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 d952594..0000000 --- a/dev/ideviceclient.c +++ /dev/null @@ -1,252 +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> -#include <glib.h> - -#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) -{ - uint16_t nport = 0; - np_client_t np; - - lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); - if (nport) { - printf("::::::::::::::: np was started ::::::::::::\n"); - np_client_new(phone, nport, &np); - if (np) { - printf("::::::::: PostNotification %s\n", notification); - np_post_notification(np, notification); - np_client_free(np); - } - } else { - printf("::::::::::::::: np was NOT started ::::::::::::\n"); - } -} - -int main(int argc, char *argv[]) -{ - unsigned int bytes = 0; - uint16_t port = 0, i = 0; - uint16_t npp; - 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 *uuid = NULL; - if (IDEVICE_E_SUCCESS == idevice_get_uuid(phone, &uuid)) { - printf("DeviceUniqueID : %s\n", uuid); - } - if (uuid) - free(uuid); - - 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", &port); - - if (port) { - afc_client_t afc = NULL; - afc_client_new(phone, port, &afc); - if (afc) { - lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); - if (npp) { - printf("Notification Proxy started.\n"); - np_client_new(phone, npp, &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]); - } - - g_strfreev(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]); - } - } - g_strfreev(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); - } else { - printf("Start service failure.\n"); - } - - printf("All done.\n"); - - lockdownd_client_free(client); - idevice_free(phone); - - return 0; -} diff --git a/dev/lckdclient.c b/dev/lckdclient.c deleted file mode 100644 index 773de9f..0000000 --- a/dev/lckdclient.c +++ /dev/null @@ -1,115 +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 <glib.h> -#include <readline/readline.h> -#include <readline/history.h> - -#include <libimobiledevice/libimobiledevice.h> -#include <libimobiledevice/lockdown.h> - -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 *uuid = NULL; - if (IDEVICE_E_SUCCESS == idevice_get_uuid(phone, &uuid)) { - printf("DeviceUniqueID : %s\n", uuid); - } - if (uuid) - free(uuid); - - if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "lckdclient")) { - idevice_free(phone); - return -1; - } - - using_history(); - int loop = TRUE; - while (loop) { - char *cmd = readline("> "); - if (cmd) { - - gchar **args = g_strsplit(cmd, " ", 0); - - int len = 0; - if (args) { - while (*(args + len)) { - g_strstrip(*(args + len)); - len++; - } - } - - if (len > 0) { - add_history(cmd); - if (!strcmp(*args, "quit")) - loop = FALSE; - - 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) { - uint16_t port = 0; - if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &port)) { - printf("started service %s on port %i\n", *(args + 1), port); - } - else - { - printf("failed to start service %s on device.\n", *(args + 1)); - } - } - } - g_strfreev(args); - } - free(cmd); - cmd = NULL; - } - clear_history(); - lockdownd_client_free(client); - idevice_free(phone); - - return 0; -} |