summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2010-02-17 16:33:18 +0100
committerGravatar Matt Colyer2010-02-19 09:34:43 -0800
commita5d7f3815adc052a8fb5ec71bf66386c2384d7d1 (patch)
tree6e3b67b338e76805775ff1797c2d0aec4d9d0f82 /tools
parentf364f1984e3d3ea2baa18ec7e939f912ddc06dbf (diff)
downloadlibimobiledevice-a5d7f3815adc052a8fb5ec71bf66386c2384d7d1.tar.gz
libimobiledevice-a5d7f3815adc052a8fb5ec71bf66386c2384d7d1.tar.bz2
New screenshotr service plus idevicescreenshot tool
[#113 state:resolved]
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am7
-rw-r--r--tools/idevicescreenshot.c111
2 files changed, 117 insertions, 1 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index b4fa69e..472ebab 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/include
3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) 3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS)
4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) 4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS)
5 5
6bin_PROGRAMS = idevice_id ideviceinfo idevicesyslog idevicebackup ideviceimagemounter 6bin_PROGRAMS = idevice_id ideviceinfo idevicesyslog idevicebackup ideviceimagemounter idevicescreenshot
7 7
8ideviceinfo_SOURCES = ideviceinfo.c 8ideviceinfo_SOURCES = ideviceinfo.c
9ideviceinfo_CFLAGS = $(AM_CFLAGS) 9ideviceinfo_CFLAGS = $(AM_CFLAGS)
@@ -29,3 +29,8 @@ ideviceimagemounter_SOURCES = ideviceimagemounter.c
29ideviceimagemounter_CFLAGS = $(AM_CFLAGS) 29ideviceimagemounter_CFLAGS = $(AM_CFLAGS)
30ideviceimagemounter_LDFLAGS = $(AM_LDFLAGS) 30ideviceimagemounter_LDFLAGS = $(AM_LDFLAGS)
31ideviceimagemounter_LDADD = ../src/libimobiledevice.la 31ideviceimagemounter_LDADD = ../src/libimobiledevice.la
32
33idevicescreenshot_SOURCES = idevicescreenshot.c
34idevicescreenshot_CFLAGS = $(AM_CFLAGS)
35idevicescreenshot_LDFLAGS = $(AM_LDFLAGS)
36idevicescreenshot_LDADD = ../src/libimobiledevice.la
diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c
new file mode 100644
index 0000000..ca4454c
--- /dev/null
+++ b/tools/idevicescreenshot.c
@@ -0,0 +1,111 @@
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <errno.h>
5
6#include <libimobiledevice/libimobiledevice.h>
7#include <libimobiledevice/lockdown.h>
8#include <libimobiledevice/screenshotr.h>
9
10void print_usage(int argc, char **argv);
11
12int main(int argc, char **argv)
13{
14 idevice_t device = NULL;
15 lockdownd_client_t lckd = NULL;
16 screenshotr_client_t shotr = NULL;
17 uint16_t port = 0;
18 int result = -1;
19 int i;
20 char *uuid = NULL;
21
22 /* parse cmdline args */
23 for (i = 1; i < argc; i++) {
24 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
25 idevice_set_debug_level(1);
26 continue;
27 }
28 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) {
29 i++;
30 if (!argv[i] || (strlen(argv[i]) != 40)) {
31 print_usage(argc, argv);
32 return 0;
33 }
34 uuid = strdup(argv[i]);
35 continue;
36 }
37 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
38 print_usage(argc, argv);
39 return 0;
40 }
41 else {
42 print_usage(argc, argv);
43 return 0;
44 }
45 }
46
47 if (IDEVICE_E_SUCCESS != idevice_new(&device, uuid)) {
48 printf("No device found, is it plugged in?\n");
49 if (uuid) {
50 free(uuid);
51 }
52 return -1;
53 }
54 if (uuid) {
55 free(uuid);
56 }
57
58 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lckd, NULL)) {
59 idevice_free(device);
60 printf("Exiting.\n");
61 return -1;
62 }
63
64 lockdownd_start_service(lckd, "com.apple.mobile.screenshotr", &port);
65 lockdownd_client_free(lckd);
66 if (port > 0) {
67 if (screenshotr_client_new(device, port, &shotr) != SCREENSHOTR_E_SUCCESS) {
68 printf("Could not connect to screenshotr!\n");
69 } else {
70 char *imgdata = NULL;
71 uint64_t imgsize = 0;
72 if (screenshotr_take_screenshot(shotr, &imgdata, &imgsize) == SCREENSHOTR_E_SUCCESS) {
73 FILE *f = fopen("screenshot.tiff", "w");
74 if (f) {
75 if (fwrite(imgdata, 1, (size_t)imgsize, f) == (size_t)imgsize) {
76 printf("Screenshot saved to screenshot.tiff\n");
77 result = 0;
78 } else {
79 printf("Could not save screenshot to file!\n");
80 }
81 fclose(f);
82 } else {
83 printf("Could not open screenshot.tiff for writing: %s\n", strerror(errno));
84 }
85 } else {
86 printf("Could not get screenshot!\n");
87 }
88 screenshotr_client_free(shotr);
89 }
90 } else {
91 printf("Could not start screenshotr service! Remember that you have to mount the Developer disk image on your device if you want to use the screenshotr service.\n");
92 }
93 idevice_free(device);
94
95 return result;
96}
97
98void print_usage(int argc, char **argv)
99{
100 char *name = NULL;
101
102 name = strrchr(argv[0], '/');
103 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
104 printf("Gets a screenshot from the connected iPhone/iPod Touch.\n");
105 printf("NOTE: A mounted developer disk image is required on the device, otherwise\n");
106 printf(" the screenshotr service is not available.\n\n");
107 printf(" -d, --debug\t\tenable communication debugging\n");
108 printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n");
109 printf(" -h, --help\t\tprints usage information\n");
110 printf("\n");
111}