summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libimobiledevice/mobile_image_mounter.h1
-rw-r--r--src/mobile_image_mounter.c77
-rw-r--r--tools/ideviceimagemounter.c13
3 files changed, 53 insertions, 38 deletions
diff --git a/include/libimobiledevice/mobile_image_mounter.h b/include/libimobiledevice/mobile_image_mounter.h
index 8d783c4..e185ad5 100644
--- a/include/libimobiledevice/mobile_image_mounter.h
+++ b/include/libimobiledevice/mobile_image_mounter.h
@@ -40,6 +40,7 @@ typedef enum {
40 MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR = -2, 40 MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR = -2,
41 MOBILE_IMAGE_MOUNTER_E_CONN_FAILED = -3, 41 MOBILE_IMAGE_MOUNTER_E_CONN_FAILED = -3,
42 MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED = -4, 42 MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED = -4,
43 MOBILE_IMAGE_MOUNTER_E_DEVICE_LOCKED = -5,
43 MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR = -256 44 MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR = -256
44} mobile_image_mounter_error_t; 45} mobile_image_mounter_error_t;
45 46
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c
index c8c4c6f..bbebbb4 100644
--- a/src/mobile_image_mounter.c
+++ b/src/mobile_image_mounter.c
@@ -2,7 +2,7 @@
2 * mobile_image_mounter.c 2 * mobile_image_mounter.c
3 * com.apple.mobile.mobile_image_mounter service implementation. 3 * com.apple.mobile.mobile_image_mounter service implementation.
4 * 4 *
5 * Copyright (c) 2010 Nikias Bassen, All Rights Reserved. 5 * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public 8 * modify it under the terms of the GNU Lesser General Public
@@ -141,6 +141,43 @@ leave_unlock:
141 return res; 141 return res;
142} 142}
143 143
144static mobile_image_mounter_error_t process_result(plist_t result, const char *expected_status)
145{
146 mobile_image_mounter_error_t res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED;
147 char* strval = NULL;
148 plist_t node;
149
150 node = plist_dict_get_item(result, "Error");
151 if (node && plist_get_node_type(node) == PLIST_STRING) {
152 plist_get_string_val(node, &strval);
153 }
154 if (strval) {
155 if (!strcmp(strval, "DeviceLocked")) {
156 debug_info("Device is locked, can't mount");
157 res = MOBILE_IMAGE_MOUNTER_E_DEVICE_LOCKED;
158 } else {
159 debug_info("Unhandled error '%s' received", strval);
160 }
161 free(strval);
162 return res;
163 }
164
165 node = plist_dict_get_item(result, "Status");
166 if (node && plist_get_node_type(node) == PLIST_STRING) {
167 plist_get_string_val(node, &strval);
168 }
169 if (!strval) {
170 debug_info("Error: Unexpected response received!");
171 } else if (strcmp(strval, expected_status) == 0) {
172 res = MOBILE_IMAGE_MOUNTER_E_SUCCESS;
173 } else {
174 debug_info("Error: didn't get %s but %s", expected_status, strval);
175 }
176 free(strval);
177
178 return res;
179}
180
144LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_image(mobile_image_mounter_client_t client, const char *image_type, size_t image_size, const char *signature, uint16_t signature_size, mobile_image_mounter_upload_cb_t upload_cb, void* userdata) 181LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_image(mobile_image_mounter_client_t client, const char *image_type, size_t image_size, const char *signature, uint16_t signature_size, mobile_image_mounter_upload_cb_t upload_cb, void* userdata)
145{ 182{
146 if (!client || !image_type || (image_size == 0) || !upload_cb) { 183 if (!client || !image_type || (image_size == 0) || !upload_cb) {
@@ -169,23 +206,10 @@ LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_im
169 debug_info("Error receiving response from device!"); 206 debug_info("Error receiving response from device!");
170 goto leave_unlock; 207 goto leave_unlock;
171 } 208 }
172 res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED; 209 res = process_result(result, "ReceiveBytesAck");
173 210 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
174 char* strval = NULL;
175 plist_t node = plist_dict_get_item(result, "Status");
176 if (node && plist_get_node_type(node) == PLIST_STRING) {
177 plist_get_string_val(node, &strval);
178 }
179 if (!strval) {
180 debug_info("Error: Unexpected response received!");
181 goto leave_unlock;
182 }
183 if (strcmp(strval, "ReceiveBytesAck") != 0) {
184 debug_info("Error: didn't get ReceiveBytesAck but %s", strval);
185 free(strval);
186 goto leave_unlock; 211 goto leave_unlock;
187 } 212 }
188 free(strval);
189 213
190 size_t tx = 0; 214 size_t tx = 0;
191 size_t bufsize = 65536; 215 size_t bufsize = 65536;
@@ -223,26 +247,7 @@ LIBIMOBILEDEVICE_API mobile_image_mounter_error_t mobile_image_mounter_upload_im
223 debug_info("Error receiving response from device!"); 247 debug_info("Error receiving response from device!");
224 goto leave_unlock; 248 goto leave_unlock;
225 } 249 }
226 res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED; 250 res = process_result(result, "Complete");
227
228 strval = NULL;
229 node = plist_dict_get_item(result, "Status");
230 if (node && plist_get_node_type(node) == PLIST_STRING) {
231 plist_get_string_val(node, &strval);
232 }
233 if (!strval) {
234 debug_info("Error: Unexpected response received!");
235 goto leave_unlock;
236 }
237 if (strcmp(strval, "Complete") != 0) {
238 debug_info("Error: didn't get Complete but %s", strval);
239 free(strval);
240 goto leave_unlock;
241 } else {
242 res = MOBILE_IMAGE_MOUNTER_E_SUCCESS;
243 }
244 free(strval);
245
246 251
247leave_unlock: 252leave_unlock:
248 mobile_image_mounter_unlock(client); 253 mobile_image_mounter_unlock(client);
diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c
index 7101c7e..93cab09 100644
--- a/tools/ideviceimagemounter.c
+++ b/tools/ideviceimagemounter.c
@@ -248,7 +248,7 @@ int main(int argc, char **argv)
248 lockdownd_client_free(lckd); 248 lockdownd_client_free(lckd);
249 lckd = NULL; 249 lckd = NULL;
250 250
251 mobile_image_mounter_error_t err; 251 mobile_image_mounter_error_t err = MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR;
252 plist_t result = NULL; 252 plist_t result = NULL;
253 253
254 if (list_mode) { 254 if (list_mode) {
@@ -344,7 +344,7 @@ int main(int argc, char **argv)
344 uint32_t written, total = 0; 344 uint32_t written, total = 0;
345 while (total < amount) { 345 while (total < amount) {
346 written = 0; 346 written = 0;
347 if (afc_file_write(afc, af, buf, amount, &written) != 347 if (afc_file_write(afc, af, buf + total, amount - total, &written) !=
348 AFC_E_SUCCESS) { 348 AFC_E_SUCCESS) {
349 fprintf(stderr, "AFC Write error!\n"); 349 fprintf(stderr, "AFC Write error!\n");
350 break; 350 break;
@@ -368,6 +368,14 @@ int main(int argc, char **argv)
368 368
369 fclose(f); 369 fclose(f);
370 370
371 if (err != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
372 if (err == MOBILE_IMAGE_MOUNTER_E_DEVICE_LOCKED) {
373 printf("ERROR: Device is locked, can't mount. Unlock device and try again.\n");
374 } else {
375 printf("ERROR: Unknown error occurred, can't mount.\n");
376 }
377 goto error_out;
378 }
371 printf("done.\n"); 379 printf("done.\n");
372 380
373 printf("Mounting...\n"); 381 printf("Mounting...\n");
@@ -435,6 +443,7 @@ int main(int argc, char **argv)
435 plist_free(result); 443 plist_free(result);
436 } 444 }
437 445
446error_out:
438 /* perform hangup command */ 447 /* perform hangup command */
439 mobile_image_mounter_hangup(mim); 448 mobile_image_mounter_hangup(mim);
440 /* free client */ 449 /* free client */