summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2008-09-02 22:54:32 +0200
committerGravatar Matt Colyer2008-09-11 22:05:45 -0700
commit3287ba4cb6f6e1a268dba039853c633938c6e200 (patch)
tree13fd1f95d6a8cc1b3bfc60c6f0f7ce07d1339546
parentb61d63f43f28d2ec94f750753b1d6d4748fd944b (diff)
downloadlibimobiledevice-3287ba4cb6f6e1a268dba039853c633938c6e200.tar.gz
libimobiledevice-3287ba4cb6f6e1a268dba039853c633938c6e200.tar.bz2
Setup a very basic lockdownd command line client
Signed-off-by: Matt Colyer <matt@colyer.name>
-rw-r--r--src/Makefile.am7
-rw-r--r--src/lckdclient.c105
-rw-r--r--src/lockdown.c8
-rw-r--r--src/lockdown.h1
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
AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libfuse_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) -g
AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libfuse_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS)
-bin_PROGRAMS = iphoneclient ifuse libiphone-initconf
+bin_PROGRAMS = iphoneclient ifuse libiphone-initconf lckd-client
iphoneclient_SOURCES = main.c
iphoneclient_LDADD = libiphone.la
@@ -14,6 +14,11 @@ libiphone_initconf_LDFLAGS = $(libgthread2_LIBS) $(AM_LDFLAGS)
ifuse_SOURCES = ifuse.c
ifuse_LDADD = libiphone.la
+lckd_client_SOURCES = lckdclient.c
+lckd_client_CFLAGS = $(AM_CFLAGS)
+lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS)
+lckd_client_LDADD = libiphone.la
+
lib_LTLIBRARIES = libiphone.la
libiphone_la_SOURCES = usbmux.c iphone.c plist.c lockdown.c AFC.c userpref.c
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 @@
+/*
+ * 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 <string.h>
+#include <glib.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+
+
+#include "usbmux.h"
+#include "iphone.h"
+#include <libiphone/libiphone.h>
+
+int debug = 1;
+
+int main(int argc, char *argv[])
+{
+ int bytes = 0, port = 0, i = 0;
+ iphone_lckd_client_t control = NULL;
+ iphone_device_t phone = NULL;
+
+
+ if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
+ printf("No iPhone found, is it plugged in?\n");
+ return -1;
+ }
+
+ if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
+ iphone_free_device(phone);
+ return -1;
+ }
+
+ char *uid = NULL;
+ if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) {
+ printf("DeviceUniqueID : %s\n", uid);
+ free(uid);
+ }
+
+ 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 == 3) {
+ char *value = NULL;
+ if (IPHONE_E_SUCCESS == lockdownd_generic_get_value(control, *(args+1), *(args+2), &value))
+ printf("Success : value = %s\n", value);
+ else
+ printf("Error\n");
+ }
+
+ if (!strcmp(*args, "start") && len == 2) {
+ int port = 0;
+ iphone_lckd_start_service(control, *(args+1), &port);
+ printf("%i\n", port);
+ }
+ }
+ g_strfreev(args);
+ }
+ free(cmd);
+ cmd = NULL;
+ }
+ clear_history();
+ iphone_lckd_free_client(control);
+ iphone_free_device(phone);
+
+ return 0;
+}
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)
*
* @return IPHONE_E_SUCCESS on success.
*/
-iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char **value)
+iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char *req_string, char **value)
{
if (!control || !req_key || !value || (value && *value))
return IPHONE_E_INVALID_ARG;
@@ -280,7 +280,7 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r
/* Setup DevicePublicKey request plist */
dict = add_child_to_plist(plist, "dict", "\n", NULL, 0);
- key = add_key_str_dict_element(plist, dict, "Key", req_key, 1);
+ key = add_key_str_dict_element(plist, dict, req_key, req_string, 1);
key = add_key_str_dict_element(plist, dict, "Request", "GetValue", 1);
xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length);
@@ -343,7 +343,7 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r
*/
iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid)
{
- return lockdownd_generic_get_value(control, "UniqueDeviceID", uid);
+ return lockdownd_generic_get_value(control, "Key", "UniqueDeviceID", uid);
}
/** 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
*/
iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key)
{
- return lockdownd_generic_get_value(control, "DevicePublicKey", public_key);
+ return lockdownd_generic_get_value(control, "Key", "DevicePublicKey", public_key);
}
/** 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();
iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone);
iphone_error_t lockdownd_hello(iphone_lckd_client_t control);
+iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *req_key, char *req_string, char **value);
iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid);
iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key);