diff options
| author | 2009-01-29 18:02:04 +0100 | |
|---|---|---|
| committer | 2009-01-29 18:02:04 +0100 | |
| commit | c1b2004461aaf2912af749620e7504345bf409ba (patch) | |
| tree | 2c238a2d8c1598265a07a2fd52beec0939d08a73 | |
| parent | 0934d1ac021dfb7907e4b580b38aa4a938cf2180 (diff) | |
| parent | f7fbac7803c5cb5934aab58925babc70af4ab848 (diff) | |
| download | libimobiledevice-c1b2004461aaf2912af749620e7504345bf409ba.tar.gz libimobiledevice-c1b2004461aaf2912af749620e7504345bf409ba.tar.bz2 | |
Merge branch 'master' into contact_sync
Conflicts:
src/Makefile.am
src/iphone.c
src/lockdown.c
src/lockdown.h
src/utils.c
| -rw-r--r-- | AUTHORS | 2 | ||||
| -rw-r--r-- | README | 65 | ||||
| -rw-r--r-- | include/libiphone/libiphone.h | 9 | ||||
| -rw-r--r-- | src/AFC.c | 2 | ||||
| -rw-r--r-- | src/Makefile.am | 2 | ||||
| -rw-r--r-- | src/iphone.c | 26 | ||||
| -rw-r--r-- | src/lockdown.c | 16 | ||||
| -rw-r--r-- | src/lockdown.h | 3 | ||||
| -rw-r--r-- | src/utils.c | 1 |
9 files changed, 36 insertions, 90 deletions
| @@ -6,3 +6,5 @@ Christophe Fergeau | |||
| 6 | Martin S. | 6 | Martin S. |
| 7 | Paul Sladen | 7 | Paul Sladen |
| 8 | Patrick Walton | 8 | Patrick Walton |
| 9 | Zoltan Balaton | ||
| 10 | Nikias Bassen | ||
| @@ -47,71 +47,6 @@ run _once_. It MUST be run otherwise communication will not work: | |||
| 47 | 47 | ||
| 48 | The generated keys are saved in '~/.config/libiphone/' in your home directory. | 48 | The generated keys are saved in '~/.config/libiphone/' in your home directory. |
| 49 | 49 | ||
| 50 | == Tools == | ||
| 51 | |||
| 52 | There are currently two more executables 'ifuse' and 'iphoneclient', | ||
| 53 | both located in src/. | ||
| 54 | |||
| 55 | |||
| 56 | === iFuse === | ||
| 57 | |||
| 58 | This is probably what you're after; this mounts a view of your | ||
| 59 | iPhone/iPod Touch's filesystem over the USB interface using the native | ||
| 60 | Apple protocol (AFC/"com.apple.afc"). | ||
| 61 | |||
| 62 | ifuse is a Fuse filesystem which allows you to mount your iPhone to a directory | ||
| 63 | like this: | ||
| 64 | |||
| 65 | ./src/ifuse <mountpoint> -s | ||
| 66 | |||
| 67 | To unmount: | ||
| 68 | umount <mountpoint> | ||
| 69 | |||
| 70 | (nb: '-s' is to force single-threaded mode, as ifuse maybe unstable without it). | ||
| 71 | |||
| 72 | Eg: | ||
| 73 | mkdir ~/iphone | ||
| 74 | |||
| 75 | ifuse ~/iphone -s | ||
| 76 | ls -l ~/iphone | ||
| 77 | ... | ||
| 78 | umount ~/iphone | ||
| 79 | |||
| 80 | Currently ifuse (via the AFC protocol) only gives access to the | ||
| 81 | '/var/root/Media/' chroot on the iPhone (containing music/pictures). | ||
| 82 | |||
| 83 | If you have a device that has been jailedbreaked then an additional | ||
| 84 | ("com.apple.afc2") service will have been installed, without the chroot. | ||
| 85 | On jailbroken devices only, you can do: | ||
| 86 | |||
| 87 | ifuse ~/iphone --root -s | ||
| 88 | |||
| 89 | And this will mount a full view of the iPhone's filesystem. | ||
| 90 | |||
| 91 | |||
| 92 | ==== Setting up FUSE ==== | ||
| 93 | |||
| 94 | Note that on some systems, you may have to load the 'fuse' kernel | ||
| 95 | module first and to ensure that you are a member of the 'fuse' group: | ||
| 96 | |||
| 97 | sudo modprobe fuse | ||
| 98 | sudo adduser $USER fuse | ||
| 99 | |||
| 100 | You can check your membership of the 'fuse' group with: | ||
| 101 | |||
| 102 | id | grep fuse && echo yes! || echo not yet... | ||
| 103 | |||
| 104 | If you have just added yourself, you will need to logout and log back | ||
| 105 | in for the group change to become visible. | ||
| 106 | |||
| 107 | |||
| 108 | === iphoneclient === | ||
| 109 | |||
| 110 | 'iphoneclient' is a basic commandline interface for testing, it just | ||
| 111 | runs a few various test operations such as attempting to view/create a | ||
| 112 | test file in the iPhone, but is mainly a developer tool. | ||
| 113 | |||
| 114 | |||
| 115 | == Who/what/where? == | 50 | == Who/what/where? == |
| 116 | 51 | ||
| 117 | wiki: | 52 | wiki: |
diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 6197923..9823bed 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h | |||
| @@ -53,10 +53,10 @@ extern "C" { | |||
| 53 | typedef int16_t iphone_error_t; | 53 | typedef int16_t iphone_error_t; |
| 54 | 54 | ||
| 55 | typedef enum { | 55 | typedef enum { |
| 56 | IPHONE_AFC_FILE_READ = 0x00000002, // seems to be able to read and write files | 56 | IPHONE_AFC_FILE_READ = 0x00000001, // seems to be able to read and write files |
| 57 | IPHONE_AFC_FILE_WRITE = 0x00000003, // writes and creates a file, blanks it out, etc. | 57 | IPHONE_AFC_FILE_WRITE = 0x00000002, // writes and creates a file, blanks it out, etc. |
| 58 | IPHONE_AFC_FILE_RW = 0x00000005, // seems to do the same as 2. Might even create the file. | 58 | IPHONE_AFC_FILE_RW = 0x00000003, // seems to do the same as 2. Might even create the file. |
| 59 | IPHONE_AFC_FILE_OP4 = 0x00000004, // no idea -- appears to be "write" -- clears file beforehand like 3 | 59 | IPHONE_AFC_FILE_CREAT = 0x00000004, // no idea -- appears to be "write" -- clears file beforehand like 3 |
| 60 | IPHONE_AFC_FILE_OP6 = 0x00000006, // no idea yet -- appears to be the same as 5. | 60 | IPHONE_AFC_FILE_OP6 = 0x00000006, // no idea yet -- appears to be the same as 5. |
| 61 | IPHONE_AFC_FILE_OP1 = 0x00000001, // no idea juuust yet... probably read. | 61 | IPHONE_AFC_FILE_OP1 = 0x00000001, // no idea juuust yet... probably read. |
| 62 | IPHONE_AFC_FILE_OP0 = 0x00000000, | 62 | IPHONE_AFC_FILE_OP0 = 0x00000000, |
| @@ -97,6 +97,7 @@ iphone_error_t iphone_free_device ( iphone_device_t device ); | |||
| 97 | 97 | ||
| 98 | 98 | ||
| 99 | //lockdownd related functions | 99 | //lockdownd related functions |
| 100 | iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); | ||
| 100 | iphone_error_t iphone_lckd_new_client ( iphone_device_t device, iphone_lckd_client_t *client ); | 101 | iphone_error_t iphone_lckd_new_client ( iphone_device_t device, iphone_lckd_client_t *client ); |
| 101 | iphone_error_t iphone_lckd_free_client( iphone_lckd_client_t client ); | 102 | iphone_error_t iphone_lckd_free_client( iphone_lckd_client_t client ); |
| 102 | 103 | ||
| @@ -227,7 +227,7 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) | |||
| 227 | iphone_mux_recv(client->connection, buffer, sizeof(AFCPacket) * 4, &bytes); | 227 | iphone_mux_recv(client->connection, buffer, sizeof(AFCPacket) * 4, &bytes); |
| 228 | if (bytes <= 0) { | 228 | if (bytes <= 0) { |
| 229 | free(buffer); | 229 | free(buffer); |
| 230 | fprintf(stderr, "Just didn't get enough.\n"); | 230 | log_debug_msg("Just didn't get enough.\n"); |
| 231 | *dump_here = NULL; | 231 | *dump_here = NULL; |
| 232 | return -1; | 232 | return -1; |
| 233 | } | 233 | } |
diff --git a/src/Makefile.am b/src/Makefile.am index 2e92fd1..1b97f45 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | INCLUDES = -I$(top_srcdir)/include | 1 | INCLUDES = -I$(top_srcdir)/include |
| 2 | 2 | ||
| 3 | AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(libplist_CFLAGS) -g | 3 | AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(libplist_CFLAGS) -g -Wall |
| 4 | AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) $(libplist_LIBS) | 4 | AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) $(libplist_LIBS) |
| 5 | 5 | ||
| 6 | bin_PROGRAMS = libiphone-initconf | 6 | bin_PROGRAMS = libiphone-initconf |
diff --git a/src/iphone.c b/src/iphone.c index 1f68180..6eb56f7 100644 --- a/src/iphone.c +++ b/src/iphone.c | |||
| @@ -38,6 +38,8 @@ | |||
| 38 | static void iphone_config_usb_device(iphone_device_t phone) | 38 | static void iphone_config_usb_device(iphone_device_t phone) |
| 39 | { | 39 | { |
| 40 | int ret; | 40 | int ret; |
| 41 | int bytes; | ||
| 42 | unsigned char buf[512]; | ||
| 41 | 43 | ||
| 42 | log_debug_msg("setting configuration... "); | 44 | log_debug_msg("setting configuration... "); |
| 43 | ret = usb_set_configuration(phone->device, 3); | 45 | ret = usb_set_configuration(phone->device, 3); |
| @@ -70,6 +72,14 @@ static void iphone_config_usb_device(iphone_device_t phone) | |||
| 70 | } else { | 72 | } else { |
| 71 | log_debug_msg("done.\n"); | 73 | log_debug_msg("done.\n"); |
| 72 | } | 74 | } |
| 75 | |||
| 76 | do { | ||
| 77 | bytes = usb_bulk_read(phone->device, BULKIN, (void *) &buf, 512, 800); | ||
| 78 | if (bytes > 0) { | ||
| 79 | log_debug_msg("iphone_config_usb_device: initial read returned %d bytes of data.\n", bytes); | ||
| 80 | log_debug_buffer(buf, bytes); | ||
| 81 | } | ||
| 82 | } while (bytes > 0); | ||
| 73 | } | 83 | } |
| 74 | 84 | ||
| 75 | /** | 85 | /** |
| @@ -151,7 +161,7 @@ static iphone_error_t iphone_get_specific_device(unsigned int bus_n, int dev_n, | |||
| 151 | // Check for correct version | 161 | // Check for correct version |
| 152 | if (ntohl(version->major) == 1 && ntohl(version->minor) == 0) { | 162 | if (ntohl(version->major) == 1 && ntohl(version->minor) == 0) { |
| 153 | // We're all ready to roll. | 163 | // We're all ready to roll. |
| 154 | fprintf(stderr, "get_iPhone() success\n"); | 164 | log_debug_msg("get_iPhone() success\n"); |
| 155 | free(version); | 165 | free(version); |
| 156 | *device = phone; | 166 | *device = phone; |
| 157 | return IPHONE_E_SUCCESS; | 167 | return IPHONE_E_SUCCESS; |
| @@ -219,12 +229,14 @@ iphone_error_t iphone_free_device(iphone_device_t device) | |||
| 219 | int bytes; | 229 | int bytes; |
| 220 | unsigned char buf[512]; | 230 | unsigned char buf[512]; |
| 221 | 231 | ||
| 222 | // read final package | 232 | // read final package(s) |
| 223 | bytes = usb_bulk_read(device->device, BULKIN, (void *) &buf, 512, 1000); | 233 | do { |
| 224 | if (bytes > 0) { | 234 | bytes = usb_bulk_read(device->device, BULKIN, (void *) &buf, 512, 800); |
| 225 | log_debug_msg("iphone_free_device: final read returned\n"); | 235 | if (bytes > 0) { |
| 226 | log_debug_buffer(buf, bytes); | 236 | log_debug_msg("iphone_free_device: final read returned\n"); |
| 227 | } | 237 | log_debug_buffer(buf, bytes); |
| 238 | } | ||
| 239 | } while (bytes > 0); | ||
| 228 | 240 | ||
| 229 | if (device->buffer) { | 241 | if (device->buffer) { |
| 230 | free(device->buffer); | 242 | free(device->buffer); |
diff --git a/src/lockdown.c b/src/lockdown.c index b83b8cf..a02e6a8 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -77,7 +77,6 @@ static void iphone_lckd_stop_session(iphone_lckd_client_t control) | |||
| 77 | if (!control) | 77 | if (!control) |
| 78 | return; //IPHONE_E_INVALID_ARG; | 78 | return; //IPHONE_E_INVALID_ARG; |
| 79 | 79 | ||
| 80 | int bytes = 0, i = 0; | ||
| 81 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 80 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 82 | 81 | ||
| 83 | plist_t dict = plist_new_dict(); | 82 | plist_t dict = plist_new_dict(); |
| @@ -128,7 +127,6 @@ static void iphone_lckd_stop_session(iphone_lckd_client_t control) | |||
| 128 | return; // ret; | 127 | return; // ret; |
| 129 | } | 128 | } |
| 130 | 129 | ||
| 131 | |||
| 132 | /** | 130 | /** |
| 133 | * Shuts down the SSL session by first calling iphone_lckd_stop_session | 131 | * Shuts down the SSL session by first calling iphone_lckd_stop_session |
| 134 | * to cleanly close the lockdownd communication session, and then | 132 | * to cleanly close the lockdownd communication session, and then |
| @@ -159,7 +157,6 @@ static void iphone_lckd_stop_SSL_session(iphone_lckd_client_t client) | |||
| 159 | return; | 157 | return; |
| 160 | } | 158 | } |
| 161 | 159 | ||
| 162 | |||
| 163 | /** Closes the lockdownd client and does the necessary housekeeping. | 160 | /** Closes the lockdownd client and does the necessary housekeeping. |
| 164 | * | 161 | * |
| 165 | * @param control The lockdown client | 162 | * @param control The lockdown client |
| @@ -471,7 +468,7 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client | |||
| 471 | 468 | ||
| 472 | iphone_lckd_client_t client_loc = new_lockdownd_client(device); | 469 | iphone_lckd_client_t client_loc = new_lockdownd_client(device); |
| 473 | if (IPHONE_E_SUCCESS != lockdownd_hello(client_loc)) { | 470 | if (IPHONE_E_SUCCESS != lockdownd_hello(client_loc)) { |
| 474 | fprintf(stderr, "Hello failed in the lockdownd client.\n"); | 471 | log_debug_msg("Hello failed in the lockdownd client.\n"); |
| 475 | ret = IPHONE_E_NOT_ENOUGH_DATA; | 472 | ret = IPHONE_E_NOT_ENOUGH_DATA; |
| 476 | } | 473 | } |
| 477 | 474 | ||
| @@ -479,12 +476,12 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client | |||
| 479 | char *uid = NULL; | 476 | char *uid = NULL; |
| 480 | ret = lockdownd_get_device_uid(client_loc, &uid); | 477 | ret = lockdownd_get_device_uid(client_loc, &uid); |
| 481 | if (IPHONE_E_SUCCESS != ret) { | 478 | if (IPHONE_E_SUCCESS != ret) { |
| 482 | fprintf(stderr, "Device refused to send uid.\n"); | 479 | log_debug_msg("Device refused to send uid.\n"); |
| 483 | } | 480 | } |
| 484 | 481 | ||
| 485 | host_id = get_host_id(); | 482 | host_id = get_host_id(); |
| 486 | if (IPHONE_E_SUCCESS == ret && !host_id) { | 483 | if (IPHONE_E_SUCCESS == ret && !host_id) { |
| 487 | fprintf(stderr, "No HostID found, run libiphone-initconf.\n"); | 484 | log_debug_msg("No HostID found, run libiphone-initconf.\n"); |
| 488 | ret = IPHONE_E_INVALID_CONF; | 485 | ret = IPHONE_E_INVALID_CONF; |
| 489 | } | 486 | } |
| 490 | 487 | ||
| @@ -499,7 +496,7 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client | |||
| 499 | ret = lockdownd_start_SSL_session(client_loc, host_id); | 496 | ret = lockdownd_start_SSL_session(client_loc, host_id); |
| 500 | if (IPHONE_E_SUCCESS != ret) { | 497 | if (IPHONE_E_SUCCESS != ret) { |
| 501 | ret = IPHONE_E_SSL_ERROR; | 498 | ret = IPHONE_E_SSL_ERROR; |
| 502 | fprintf(stderr, "SSL Session opening failed.\n"); | 499 | log_debug_msg("SSL Session opening failed.\n"); |
| 503 | } | 500 | } |
| 504 | 501 | ||
| 505 | if (host_id) { | 502 | if (host_id) { |
| @@ -532,7 +529,7 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch | |||
| 532 | 529 | ||
| 533 | ret = lockdownd_get_device_public_key(control, &public_key); | 530 | ret = lockdownd_get_device_public_key(control, &public_key); |
| 534 | if (ret != IPHONE_E_SUCCESS) { | 531 | if (ret != IPHONE_E_SUCCESS) { |
| 535 | fprintf(stderr, "Device refused to send public key.\n"); | 532 | log_debug_msg("Device refused to send public key.\n"); |
| 536 | return ret; | 533 | return ret; |
| 537 | } | 534 | } |
| 538 | 535 | ||
| @@ -804,8 +801,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t | |||
| 804 | iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID) | 801 | iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID) |
| 805 | { | 802 | { |
| 806 | plist_t dict = NULL; | 803 | plist_t dict = NULL; |
| 807 | char *XML_content = NULL; | 804 | uint32_t return_me = 0; |
| 808 | uint32_t length = 0, bytes = 0, return_me = 0; | ||
| 809 | 805 | ||
| 810 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 806 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 811 | control->session_id[0] = '\0'; | 807 | control->session_id[0] = '\0'; |
diff --git a/src/lockdown.h b/src/lockdown.h index cdc46b8..2f2a4b9 100644 --- a/src/lockdown.h +++ b/src/lockdown.h | |||
| @@ -42,9 +42,10 @@ struct iphone_lckd_client_int { | |||
| 42 | 42 | ||
| 43 | iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); | 43 | iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); |
| 44 | iphone_error_t lockdownd_hello(iphone_lckd_client_t control); | 44 | iphone_error_t lockdownd_hello(iphone_lckd_client_t control); |
| 45 | |||
| 45 | iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const char *req_key, char *req_string, | 46 | iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const char *req_key, char *req_string, |
| 46 | gnutls_datum_t * value); | 47 | gnutls_datum_t * value); |
| 47 | iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); | 48 | |
| 48 | iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, gnutls_datum_t * public_key); | 49 | iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, gnutls_datum_t * public_key); |
| 49 | 50 | ||
| 50 | iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert, | 51 | iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert, |
diff --git a/src/utils.c b/src/utils.c index 988cb03..5b0872d 100644 --- a/src/utils.c +++ b/src/utils.c | |||
| @@ -66,7 +66,6 @@ void log_debug_msg(const char *format, ...) | |||
| 66 | void log_dbg_msg(uint16_t id, const char *format, ...) | 66 | void log_dbg_msg(uint16_t id, const char *format, ...) |
| 67 | { | 67 | { |
| 68 | #ifndef STRIP_DEBUG_CODE | 68 | #ifndef STRIP_DEBUG_CODE |
| 69 | |||
| 70 | if (id & dbg_mask) { | 69 | if (id & dbg_mask) { |
| 71 | va_list args; | 70 | va_list args; |
| 72 | /* run the real fprintf */ | 71 | /* run the real fprintf */ |
