diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 7 | ||||
| -rw-r--r-- | src/lckdclient.c | 105 | ||||
| -rw-r--r-- | src/lockdown.c | 8 | ||||
| -rw-r--r-- | src/lockdown.h | 1 |
4 files changed, 116 insertions, 5 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index f26deb1..9a5df62 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
| @@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/include | |||
| 3 | AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libfuse_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) -g | 3 | AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libfuse_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) -g |
| 4 | AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) | 4 | AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) |
| 5 | 5 | ||
| 6 | bin_PROGRAMS = iphoneclient ifuse libiphone-initconf | 6 | bin_PROGRAMS = iphoneclient ifuse libiphone-initconf lckd-client |
| 7 | iphoneclient_SOURCES = main.c | 7 | iphoneclient_SOURCES = main.c |
| 8 | iphoneclient_LDADD = libiphone.la | 8 | iphoneclient_LDADD = libiphone.la |
| 9 | 9 | ||
| @@ -14,6 +14,11 @@ libiphone_initconf_LDFLAGS = $(libgthread2_LIBS) $(AM_LDFLAGS) | |||
| 14 | ifuse_SOURCES = ifuse.c | 14 | ifuse_SOURCES = ifuse.c |
| 15 | ifuse_LDADD = libiphone.la | 15 | ifuse_LDADD = libiphone.la |
| 16 | 16 | ||
| 17 | lckd_client_SOURCES = lckdclient.c | ||
| 18 | lckd_client_CFLAGS = $(AM_CFLAGS) | ||
| 19 | lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS) | ||
| 20 | lckd_client_LDADD = libiphone.la | ||
| 21 | |||
| 17 | lib_LTLIBRARIES = libiphone.la | 22 | lib_LTLIBRARIES = libiphone.la |
| 18 | libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c | 23 | libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c |
| 19 | 24 | ||
diff --git a/src/lckdclient.c b/src/lckdclient.c new file mode 100644 index 0000000..179ecae --- /dev/null +++ b/src/lckdclient.c | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | /* | ||
| 2 | * lckdclient.c | ||
| 3 | * Rudimentary command line interface to the Lockdown protocol | ||
| 4 | * | ||
| 5 | * Copyright (c) 2008 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <glib.h> | ||
| 25 | #include <readline/readline.h> | ||
| 26 | #include <readline/history.h> | ||
| 27 | |||
| 28 | |||
| 29 | #include "usbmux.h" | ||
| 30 | #include "iphone.h" | ||
| 31 | #include <libiphone/libiphone.h> | ||
| 32 | |||
| 33 | int debug = 1; | ||
| 34 | |||
| 35 | int main(int argc, char *argv[]) | ||
| 36 | { | ||
| 37 | int bytes = 0, port = 0, i = 0; | ||
| 38 | iphone_lckd_client_t control = NULL; | ||
| 39 | iphone_device_t phone = NULL; | ||
| 40 | |||
| 41 | |||
| 42 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { | ||
| 43 | printf("No iPhone found, is it plugged in?\n"); | ||
| 44 | return -1; | ||
| 45 | } | ||
| 46 | |||
| 47 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | ||
| 48 | iphone_free_device(phone); | ||
| 49 | return -1; | ||
| 50 | } | ||
| 51 | |||
| 52 | char *uid = NULL; | ||
| 53 | if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) { | ||
| 54 | printf("DeviceUniqueID : %s\n", uid); | ||
| 55 | free(uid); | ||
| 56 | } | ||
| 57 | |||
| 58 | using_history(); | ||
| 59 | int loop = TRUE; | ||
| 60 | while(loop) | ||
| 61 | { | ||
| 62 | char *cmd = readline("> "); | ||
| 63 | if (cmd) | ||
| 64 | { | ||
| 65 | |||
| 66 | gchar** args = g_strsplit(cmd, " ", 0); | ||
| 67 | |||
| 68 | int len = 0; | ||
| 69 | if (args) { | ||
| 70 | while ( *(args+len) ) { | ||
| 71 | g_strstrip(*(args+len)); | ||
| 72 | len++; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | if (len > 0) { | ||
| 77 | add_history(cmd); | ||
| 78 | if (!strcmp(*args, "quit")) | ||
| 79 | loop = FALSE; | ||
| 80 | |||
| 81 | if (!strcmp(*args, "get") && len == 3) { | ||
| 82 | char *value = NULL; | ||
| 83 | if (IPHONE_E_SUCCESS == lockdownd_generic_get_value(control, *(args+1), *(args+2), &value)) | ||
| 84 | printf("Success : value = %s\n", value); | ||
| 85 | else | ||
| 86 | printf("Error\n"); | ||
| 87 | } | ||
| 88 | |||
| 89 | if (!strcmp(*args, "start") && len == 2) { | ||
| 90 | int port = 0; | ||
| 91 | iphone_lckd_start_service(control, *(args+1), &port); | ||
| 92 | printf("%i\n", port); | ||
| 93 | } | ||
| 94 | } | ||
| 95 | g_strfreev(args); | ||
| 96 | } | ||
| 97 | free(cmd); | ||
| 98 | cmd = NULL; | ||
| 99 | } | ||
| 100 | clear_history(); | ||
| 101 | iphone_lckd_free_client(control); | ||
| 102 | iphone_free_device(phone); | ||
| 103 | |||
| 104 | return 0; | ||
| 105 | } | ||
diff --git a/src/lockdown.c b/src/lockdown.c index 80974d2..ffabd88 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -265,7 +265,7 @@ iphone_error_t lockdownd_hello(iphone_lckd_client_t control) | |||
| 265 | * | 265 | * |
| 266 | * @return IPHONE_E_SUCCESS on success. | 266 | * @return IPHONE_E_SUCCESS on success. |
| 267 | */ | 267 | */ |
| 268 | iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char **value) | 268 | iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char *req_string, char **value) |
| 269 | { | 269 | { |
| 270 | if (!control || !req_key || !value || (value && *value)) | 270 | if (!control || !req_key || !value || (value && *value)) |
| 271 | return IPHONE_E_INVALID_ARG; | 271 | return IPHONE_E_INVALID_ARG; |
| @@ -280,7 +280,7 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r | |||
| 280 | 280 | ||
| 281 | /* Setup DevicePublicKey request plist */ | 281 | /* Setup DevicePublicKey request plist */ |
| 282 | dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); | 282 | dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); |
| 283 | key = add_key_str_dict_element(plist, dict, "Key", req_key, 1); | 283 | key = add_key_str_dict_element(plist, dict, req_key, req_string, 1); |
| 284 | key = add_key_str_dict_element(plist, dict, "Request", "GetValue", 1); | 284 | key = add_key_str_dict_element(plist, dict, "Request", "GetValue", 1); |
| 285 | xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); | 285 | xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); |
| 286 | 286 | ||
| @@ -343,7 +343,7 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r | |||
| 343 | */ | 343 | */ |
| 344 | iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid) | 344 | iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid) |
| 345 | { | 345 | { |
| 346 | return lockdownd_generic_get_value(control, "UniqueDeviceID", uid); | 346 | return lockdownd_generic_get_value(control, "Key", "UniqueDeviceID", uid); |
| 347 | } | 347 | } |
| 348 | 348 | ||
| 349 | /** Askes for the device's public key. Part of the lockdownd handshake. | 349 | /** Askes for the device's public key. Part of the lockdownd handshake. |
| @@ -354,7 +354,7 @@ iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid | |||
| 354 | */ | 354 | */ |
| 355 | iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key) | 355 | iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key) |
| 356 | { | 356 | { |
| 357 | return lockdownd_generic_get_value(control, "DevicePublicKey", public_key); | 357 | return lockdownd_generic_get_value(control, "Key", "DevicePublicKey", public_key); |
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | /** Completes the entire lockdownd handshake. | 360 | /** Completes the entire lockdownd handshake. |
diff --git a/src/lockdown.h b/src/lockdown.h index 41402c4..9176524 100644 --- a/src/lockdown.h +++ b/src/lockdown.h | |||
| @@ -44,6 +44,7 @@ char *lockdownd_generate_hostid(); | |||
| 44 | 44 | ||
| 45 | iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); | 45 | iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); |
| 46 | iphone_error_t lockdownd_hello(iphone_lckd_client_t control); | 46 | iphone_error_t lockdownd_hello(iphone_lckd_client_t control); |
| 47 | iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char *req_string, char **value); | ||
| 47 | iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); | 48 | iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); |
| 48 | iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key); | 49 | iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key); |
| 49 | 50 | ||
