diff options
| -rw-r--r-- | docs/Makefile.am | 2 | ||||
| -rw-r--r-- | docs/idevicesetlocation.1 | 33 | ||||
| -rw-r--r-- | tools/Makefile.am | 7 | ||||
| -rw-r--r-- | tools/idevicesetlocation.c | 182 |
4 files changed, 222 insertions, 2 deletions
diff --git a/docs/Makefile.am b/docs/Makefile.am index d788297..d355ac0 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | man_MANS = idevice_id.1 ideviceinfo.1 idevicesyslog.1 idevicebackup.1 idevicebackup2.1 ideviceimagemounter.1 idevicescreenshot.1 idevicepair.1 ideviceenterrecovery.1 idevicedate.1 ideviceprovision.1 idevicedebugserverproxy.1 idevicediagnostics.1 idevicecrashreport.1 idevicename.1 idevicedebug.1 idevicenotificationproxy.1 | 1 | man_MANS = idevice_id.1 ideviceinfo.1 idevicesyslog.1 idevicebackup.1 idevicebackup2.1 ideviceimagemounter.1 idevicescreenshot.1 idevicepair.1 ideviceenterrecovery.1 idevicedate.1 ideviceprovision.1 idevicedebugserverproxy.1 idevicediagnostics.1 idevicecrashreport.1 idevicename.1 idevicedebug.1 idevicenotificationproxy.1 idevicesetlocation.1 |
| 2 | 2 | ||
| 3 | EXTRA_DIST = $(man_MANS) | 3 | EXTRA_DIST = $(man_MANS) |
| 4 | 4 | ||
diff --git a/docs/idevicesetlocation.1 b/docs/idevicesetlocation.1 new file mode 100644 index 0000000..2434dc8 --- /dev/null +++ b/docs/idevicesetlocation.1 | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | .TH "idevicesetlocation" 1 | ||
| 2 | .SH NAME | ||
| 3 | idevicesetlocation \- Simulate location on iOS device. | ||
| 4 | .SH SYNOPSIS | ||
| 5 | .B idevicesetlocation | ||
| 6 | [OPTIONS] -- <LAT> <LONG> | ||
| 7 | |||
| 8 | .B idevicesetlocation | ||
| 9 | [OPTIONS] reset | ||
| 10 | |||
| 11 | .SH DESCRIPTION | ||
| 12 | |||
| 13 | Simulate location on iOS device with mounted developer disk image. | ||
| 14 | |||
| 15 | .SH OPTIONS | ||
| 16 | .TP | ||
| 17 | .B \-d, \-\-debug | ||
| 18 | enable communication debugging | ||
| 19 | .TP | ||
| 20 | .B \-u, \-\-udid UDID | ||
| 21 | target specific device by UDID | ||
| 22 | .TP | ||
| 23 | .B \-n, \-\-network | ||
| 24 | connect to network device even if available via USB | ||
| 25 | .TP | ||
| 26 | .B \-h, \-\-help | ||
| 27 | prints usage information | ||
| 28 | |||
| 29 | .SH AUTHOR | ||
| 30 | Nikias Bassen | ||
| 31 | |||
| 32 | .SH ON THE WEB | ||
| 33 | http://libimobiledevice.org | ||
diff --git a/tools/Makefile.am b/tools/Makefile.am index db929bb..726dc18 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am | |||
| @@ -3,7 +3,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir) | |||
| 3 | AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgcrypt_CFLAGS) $(openssl_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) | 3 | AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgcrypt_CFLAGS) $(openssl_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) |
| 4 | AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgcrypt_LIBS) $(openssl_LIBS) $(libplist_LIBS) | 4 | AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgcrypt_LIBS) $(openssl_LIBS) $(libplist_LIBS) |
| 5 | 5 | ||
| 6 | bin_PROGRAMS = idevice_id ideviceinfo idevicename idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate idevicebackup idevicebackup2 ideviceprovision idevicedebugserverproxy idevicediagnostics idevicedebug idevicenotificationproxy idevicecrashreport | 6 | bin_PROGRAMS = idevice_id ideviceinfo idevicename idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate idevicebackup idevicebackup2 ideviceprovision idevicedebugserverproxy idevicediagnostics idevicedebug idevicenotificationproxy idevicecrashreport idevicesetlocation |
| 7 | 7 | ||
| 8 | ideviceinfo_SOURCES = ideviceinfo.c | 8 | ideviceinfo_SOURCES = ideviceinfo.c |
| 9 | ideviceinfo_CFLAGS = $(AM_CFLAGS) | 9 | ideviceinfo_CFLAGS = $(AM_CFLAGS) |
| @@ -89,3 +89,8 @@ idevicecrashreport_SOURCES = idevicecrashreport.c | |||
| 89 | idevicecrashreport_CFLAGS = -I$(top_srcdir) $(AM_CFLAGS) | 89 | idevicecrashreport_CFLAGS = -I$(top_srcdir) $(AM_CFLAGS) |
| 90 | idevicecrashreport_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS) | 90 | idevicecrashreport_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS) |
| 91 | idevicecrashreport_LDADD = $(top_builddir)/src/libimobiledevice.la | 91 | idevicecrashreport_LDADD = $(top_builddir)/src/libimobiledevice.la |
| 92 | |||
| 93 | idevicesetlocation_SOURCES = idevicesetlocation.c | ||
| 94 | idevicesetlocation_CFLAGS = $(AM_CFLAGS) | ||
| 95 | idevicesetlocation_LDFLAGS = $(top_builddir)/common/libinternalcommon.la $(AM_LDFLAGS) | ||
| 96 | idevicesetlocation_LDADD = $(top_builddir)/src/libimobiledevice.la | ||
diff --git a/tools/idevicesetlocation.c b/tools/idevicesetlocation.c new file mode 100644 index 0000000..d2b8864 --- /dev/null +++ b/tools/idevicesetlocation.c | |||
| @@ -0,0 +1,182 @@ | |||
| 1 | /* | ||
| 2 | * idevicesetlocation.c | ||
| 3 | * Simulate location on iOS device with mounted developer disk image | ||
| 4 | * | ||
| 5 | * Copyright (c) 2016-2020 Nikias Bassen, All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License as published by | ||
| 9 | * the Free Software Foundation; either version 2 of the License, or | ||
| 10 | * (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This program 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 | ||
| 15 | * GNU General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License | ||
| 18 | * along with this program; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | #ifdef HAVE_CONFIG_H | ||
| 22 | #include <config.h> | ||
| 23 | #endif | ||
| 24 | #include <stdio.h> | ||
| 25 | #include <stdlib.h> | ||
| 26 | #include <stdint.h> | ||
| 27 | #include <string.h> | ||
| 28 | #include <errno.h> | ||
| 29 | #include <getopt.h> | ||
| 30 | |||
| 31 | #include <libimobiledevice/libimobiledevice.h> | ||
| 32 | #include <libimobiledevice/lockdown.h> | ||
| 33 | #include <libimobiledevice/service.h> | ||
| 34 | |||
| 35 | #include <endianness.h> | ||
| 36 | |||
| 37 | #define DT_SIMULATELOCATION_SERVICE "com.apple.dt.simulatelocation" | ||
| 38 | |||
| 39 | enum { | ||
| 40 | SET_LOCATION = 0, | ||
| 41 | RESET_LOCATION = 1 | ||
| 42 | }; | ||
| 43 | |||
| 44 | static void print_usage(int argc, char **argv, int is_error) | ||
| 45 | { | ||
| 46 | char *bname = strrchr(argv[0], '/'); | ||
| 47 | bname = (bname) ? bname + 1 : argv[0]; | ||
| 48 | |||
| 49 | fprintf(is_error ? stderr : stdout, "Usage: %s [OPTIONS] -- <LAT> <LONG>\n", bname); | ||
| 50 | fprintf(is_error ? stderr : stdout, " %s [OPTIONS] reset\n", bname); | ||
| 51 | fprintf(is_error ? stderr : stdout, "\n" \ | ||
| 52 | "OPTIONS:\n" \ | ||
| 53 | " -u, --udid UDID target specific device by UDID\n" \ | ||
| 54 | " -n, --network connect to network device even if available via USB\n" \ | ||
| 55 | " -h, --help prints usage information\n" \ | ||
| 56 | " -d, --debug enable communication debugging\n" \ | ||
| 57 | "\n" | ||
| 58 | "Homepage: <" PACKAGE_URL ">\n" | ||
| 59 | ); | ||
| 60 | } | ||
| 61 | |||
| 62 | int main(int argc, char **argv) | ||
| 63 | { | ||
| 64 | const struct option longopts[] = { | ||
| 65 | { "help", no_argument, NULL, 'h' }, | ||
| 66 | { "udid", required_argument, NULL, 'u' }, | ||
| 67 | { "debug", no_argument, NULL, 'd' }, | ||
| 68 | { "network", no_argument, NULL, 'n' }, | ||
| 69 | { NULL, 0, NULL, 0} | ||
| 70 | }; | ||
| 71 | uint32_t mode = 0; | ||
| 72 | char *udid = NULL; | ||
| 73 | enum idevice_options lookup_opts = IDEVICE_LOOKUP_USBMUX | IDEVICE_LOOKUP_NETWORK; | ||
| 74 | |||
| 75 | int c = 0; | ||
| 76 | while ((c = getopt_long(argc, argv, "dhu:n", longopts, NULL)) != -1) { | ||
| 77 | switch (c) { | ||
| 78 | case 'd': | ||
| 79 | idevice_set_debug_level(1); | ||
| 80 | break; | ||
| 81 | case 'u': | ||
| 82 | if (!*optarg) { | ||
| 83 | fprintf(stderr, "ERROR: UDID must not be empty!\n"); | ||
| 84 | print_usage(argc, argv, 1); | ||
| 85 | return 2; | ||
| 86 | } | ||
| 87 | free(udid); | ||
| 88 | udid = strdup(optarg); | ||
| 89 | break; | ||
| 90 | case 'n': | ||
| 91 | lookup_opts |= IDEVICE_LOOKUP_PREFER_NETWORK; | ||
| 92 | break; | ||
| 93 | case 'h': | ||
| 94 | print_usage(argc, argv, 0); | ||
| 95 | return 0; | ||
| 96 | default: | ||
| 97 | print_usage(argc, argv, 1); | ||
| 98 | return 2; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 102 | argc -= optind; | ||
| 103 | argv += optind; | ||
| 104 | |||
| 105 | if ((argc > 2) || (argc < 1)) { | ||
| 106 | print_usage(argc+optind, argv-optind, 1); | ||
| 107 | return -1; | ||
| 108 | } | ||
| 109 | |||
| 110 | if (argc == 2) { | ||
| 111 | mode = SET_LOCATION; | ||
| 112 | } else if (argc == 1) { | ||
| 113 | if (strcmp(argv[0], "reset") == 0) { | ||
| 114 | mode = RESET_LOCATION; | ||
| 115 | } else { | ||
| 116 | print_usage(argc+optind, argv-optind, 1); | ||
| 117 | return -1; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | idevice_t device = NULL; | ||
| 122 | |||
| 123 | if (idevice_new_with_options(&device, udid, lookup_opts) != IDEVICE_E_SUCCESS) { | ||
| 124 | if (udid) { | ||
| 125 | printf("ERROR: Device %s not found!\n", udid); | ||
| 126 | } else { | ||
| 127 | printf("ERROR: No device found!\n"); | ||
| 128 | } | ||
| 129 | return -1; | ||
| 130 | } | ||
| 131 | |||
| 132 | lockdownd_client_t lockdown; | ||
| 133 | lockdownd_client_new_with_handshake(device, &lockdown, NULL); | ||
| 134 | |||
| 135 | lockdownd_service_descriptor_t svc = NULL; | ||
| 136 | if (lockdownd_start_service(lockdown, DT_SIMULATELOCATION_SERVICE, &svc) != LOCKDOWN_E_SUCCESS) { | ||
| 137 | lockdownd_client_free(lockdown); | ||
| 138 | idevice_free(device); | ||
| 139 | printf("ERROR: Could not start the simulatelocation service. Make sure a developer disk image is mounted!\n"); | ||
| 140 | return -1; | ||
| 141 | } | ||
| 142 | lockdownd_client_free(lockdown); | ||
| 143 | |||
| 144 | service_client_t service = NULL; | ||
| 145 | |||
| 146 | service_error_t serr = service_client_new(device, svc, &service); | ||
| 147 | |||
| 148 | lockdownd_service_descriptor_free(svc); | ||
| 149 | |||
| 150 | if (serr != SERVICE_E_SUCCESS) { | ||
| 151 | lockdownd_client_free(lockdown); | ||
| 152 | idevice_free(device); | ||
| 153 | printf("ERROR: Could not connect to simulatelocation service (%d)\n", serr); | ||
| 154 | return -1; | ||
| 155 | } | ||
| 156 | |||
| 157 | uint32_t l; | ||
| 158 | uint32_t s = 0; | ||
| 159 | |||
| 160 | l = htobe32(mode); | ||
| 161 | service_send(service, (const char*)&l, 4, &s); | ||
| 162 | if (mode == SET_LOCATION) { | ||
| 163 | int len = 4 + strlen(argv[0]) + 4 + strlen(argv[1]); | ||
| 164 | char *buf = malloc(len); | ||
| 165 | uint32_t latlen; | ||
| 166 | latlen = strlen(argv[0]); | ||
| 167 | l = htobe32(latlen); | ||
| 168 | memcpy(buf, &l, 4); | ||
| 169 | memcpy(buf+4, argv[0], latlen); | ||
| 170 | uint32_t longlen = strlen(argv[1]); | ||
| 171 | l = htobe32(longlen); | ||
| 172 | memcpy(buf+4+latlen, &l, 4); | ||
| 173 | memcpy(buf+4+latlen+4, argv[1], longlen); | ||
| 174 | |||
| 175 | s = 0; | ||
| 176 | service_send(service, buf, len, &s); | ||
| 177 | } | ||
| 178 | |||
| 179 | idevice_free(device); | ||
| 180 | |||
| 181 | return 0; | ||
| 182 | } | ||
