summaryrefslogtreecommitdiffstats
path: root/dev
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2010-01-25 00:50:14 +0100
committerGravatar Martin Szulecki2010-01-25 04:19:14 +0100
commit762bf3d1589e2285945eb4eff1d79afbe0fc46c6 (patch)
tree65f9ead704170ebbc7970dc05abf246a110cdb62 /dev
parentbbfd5355b9bb25ece2da83af93ac3cdd01bc41c7 (diff)
downloadlibimobiledevice-762bf3d1589e2285945eb4eff1d79afbe0fc46c6.tar.gz
libimobiledevice-762bf3d1589e2285945eb4eff1d79afbe0fc46c6.tar.bz2
Quick and dirty file_relay test tool.
Diffstat (limited to 'dev')
-rw-r--r--dev/Makefile.am7
-rw-r--r--dev/filerelaytest.c108
2 files changed, 114 insertions, 1 deletions
diff --git a/dev/Makefile.am b/dev/Makefile.am
index b71c212..1ca15e5 100644
--- a/dev/Makefile.am
+++ b/dev/Makefile.am
@@ -4,7 +4,7 @@ AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_C
AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS)
if ENABLE_DEVTOOLS
-noinst_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneenterrecovery
+noinst_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneenterrecovery filerelaytest
iphoneclient_SOURCES = iphoneclient.c
iphoneclient_LDADD = ../src/libiphone.la
@@ -29,6 +29,11 @@ iphoneenterrecovery_CFLAGS = $(AM_CFLAGS)
iphoneenterrecovery_LDFLAGS = $(AM_LDFLAGS)
iphoneenterrecovery_LDADD = ../src/libiphone.la
+filerelaytest_SOURCES = filerelaytest.c
+filerelaytest_CFLAGS = $(AM_CFLAGS)
+filerelaytest_LDFLAGS = $(AM_LDFLAGS)
+filerelaytest_LDADD = ../src/libiphone.la
+
endif # ENABLE_DEVTOOLS
EXTRA_DIST = iphoneclient.c lckdclient.c afccheck.c msyncclient.c iphoneenterrecovery.c
diff --git a/dev/filerelaytest.c b/dev/filerelaytest.c
new file mode 100644
index 0000000..f7e0d07
--- /dev/null
+++ b/dev/filerelaytest.c
@@ -0,0 +1,108 @@
+/*
+ * 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 <libiphone/libiphone.h>
+#include <libiphone/lockdown.h>
+#include <libiphone/file_relay.h>
+
+int main(int argc, char **argv)
+{
+ iphone_device_t dev = NULL;
+ lockdownd_client_t client = NULL;
+ file_relay_client_t frc = NULL;
+
+ if (iphone_device_new(&dev, NULL) != IPHONE_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;
+ }
+
+ iphone_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 (iphone_connection_receive(dump, buf, 4096, &len) == IPHONE_E_SUCCESS) {
+ fwrite(buf, 1, len, f);
+ cnt += len;
+ printf(".", len);
+ 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) {
+ iphone_device_free(dev);
+ }
+
+ return 0;
+}