Debian Codegraph @

src/mobile_image_mounter.c

raw
1 /*
2 * mobile_image_mounter.c
3 * com.apple.mobile.mobile_image_mounter service implementation.
4 *
5 * Copyright (c) 2010-2019 Nikias Bassen, All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #include <string.h>
26 #include <stdlib.h>
27
28 #ifndef _MSC_VER
29 #include <unistd.h>
30 #endif
31
32 #include <plist/plist.h>
33
34 #include "mobile_image_mounter.h"
35 #include "property_list_service.h"
36 #include "common/debug.h"
37
38 /**
39 * Locks a mobile_image_mounter client, used for thread safety.
40 *
41 * @param client mobile_image_mounter client to lock
42 */
43 static void mobile_image_mounter_lock(mobile_image_mounter_client_t client)
44 {
45 mutex_lock(&client->mutex);
46 }
47
48 /**
49 * Unlocks a mobile_image_mounter client, used for thread safety.
50 *
51 * @param client mobile_image_mounter client to unlock
52 */
53 static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client)
54 {
55 mutex_unlock(&client->mutex);
56 }
57
58 /**
59 * Convert a property_list_service_error_t value to a
60 * mobile_image_mounter_error_t value.
61 * Used internally to get correct error codes.
62 *
63 * @param err A property_list_service_error_t error code
64 *
65 * @return A matching mobile_image_mounter_error_t error code,
66 * MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR otherwise.
67 */
68 static mobile_image_mounter_error_t mobile_image_mounter_error(property_list_service_error_t err)
69 {
70 switch (err) {
71 case PROPERTY_LIST_SERVICE_E_SUCCESS:
72 return MOBILE_IMAGE_MOUNTER_E_SUCCESS;
73 case PROPERTY_LIST_SERVICE_E_INVALID_ARG:
74 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
75 case PROPERTY_LIST_SERVICE_E_PLIST_ERROR:
76 return MOBILE_IMAGE_MOUNTER_E_PLIST_ERROR;
77 case PROPERTY_LIST_SERVICE_E_MUX_ERROR:
78 return MOBILE_IMAGE_MOUNTER_E_CONN_FAILED;
79 default:
80 break;
81 }
82 return MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR;
83 }
84
85 mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t service, mobile_image_mounter_client_t *client)
86 {
87 property_list_service_client_t plistclient = NULL;
88 mobile_image_mounter_error_t err = mobile_image_mounter_error(property_list_service_client_new(device, service, &plistclient));
89 if (err != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
90 return err;
91 }
92
93 mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private));
94 client_loc->parent = plistclient;
95
96 mutex_init(&client_loc->mutex);
97
98 *client = client_loc;
99 return MOBILE_IMAGE_MOUNTER_E_SUCCESS;
100 }
101
102 mobile_image_mounter_error_t mobile_image_mounter_start_service(idevice_t device, mobile_image_mounter_client_t * client, const char* label)
103 {
104 mobile_image_mounter_error_t err = MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR;
105 service_client_factory_start_service(device, MOBILE_IMAGE_MOUNTER_SERVICE_NAME, (void**)client, label, SERVICE_CONSTRUCTOR(mobile_image_mounter_new), &err);
106 return err;
107 }
108
109 mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client)
110 {
111 if (!client)
112 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
113
114 property_list_service_client_free(client->parent);
115 client->parent = NULL;
116 mutex_destroy(&client->mutex);
117 free(client);
118
119 return MOBILE_IMAGE_MOUNTER_E_SUCCESS;
120 }
121
122 mobile_image_mounter_error_t mobile_image_mounter_lookup_image(mobile_image_mounter_client_t client, const char *image_type, plist_t *result)
123 {
124 if (!client || !image_type || !result) {
125 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
126 }
127 mobile_image_mounter_lock(client);
128
129 plist_t dict = plist_new_dict();
130 plist_dict_set_item(dict,"Command", plist_new_string("LookupImage"));
131 plist_dict_set_item(dict,"ImageType", plist_new_string(image_type));
132
133 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
134 plist_free(dict);
135
136 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
137 debug_info("%s: Error sending XML plist to device!", __func__);
138 goto leave_unlock;
139 }
140
141 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, result));
142 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
143 debug_info("%s: Error receiving response from device!", __func__);
144 }
145
146 leave_unlock:
147 mobile_image_mounter_unlock(client);
148 return res;
149 }
150
151 static mobile_image_mounter_error_t process_result(plist_t result, const char *expected_status)
152 {
153 mobile_image_mounter_error_t res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED;
154 char* strval = NULL;
155 plist_t node;
156
157 node = plist_dict_get_item(result, "Error");
158 if (node && plist_get_node_type(node) == PLIST_STRING) {
159 plist_get_string_val(node, &strval);
160 }
161 if (strval) {
162 if (!strcmp(strval, "DeviceLocked")) {
163 debug_info("Device is locked, can't mount");
164 res = MOBILE_IMAGE_MOUNTER_E_DEVICE_LOCKED;
165 } else {
166 debug_info("Unhandled error '%s' received", strval);
167 }
168 free(strval);
169 return res;
170 }
171
172 node = plist_dict_get_item(result, "Status");
173 if (node && plist_get_node_type(node) == PLIST_STRING) {
174 plist_get_string_val(node, &strval);
175 }
176 if (!strval) {
177 debug_info("Error: Unexpected response received!");
178 } else if (strcmp(strval, expected_status) == 0) {
179 res = MOBILE_IMAGE_MOUNTER_E_SUCCESS;
180 } else {
181 debug_info("Error: didn't get %s but %s", expected_status, strval);
182 }
183 free(strval);
184
185 return res;
186 }
187
188 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 unsigned char *signature, unsigned int signature_size, mobile_image_mounter_upload_cb_t upload_cb, void* userdata)
189 {
190 if (!client || !image_type || (image_size == 0) || !upload_cb) {
191 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
192 }
193 mobile_image_mounter_lock(client);
194 plist_t result = NULL;
195
196 plist_t dict = plist_new_dict();
197 plist_dict_set_item(dict, "Command", plist_new_string("ReceiveBytes"));
198 if (signature && signature_size != 0)
199 plist_dict_set_item(dict, "ImageSignature", plist_new_data((char*)signature, signature_size));
200 plist_dict_set_item(dict, "ImageSize", plist_new_uint(image_size));
201 plist_dict_set_item(dict, "ImageType", plist_new_string(image_type));
202
203 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
204 plist_free(dict);
205
206 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
207 debug_info("Error sending XML plist to device!");
208 goto leave_unlock;
209 }
210
211 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result));
212 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
213 debug_info("Error receiving response from device!");
214 goto leave_unlock;
215 }
216 res = process_result(result, "ReceiveBytesAck");
217 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
218 goto leave_unlock;
219 }
220
221 size_t tx = 0;
222 size_t bufsize = 65536;
223 unsigned char *buf = (unsigned char*)malloc(bufsize);
224 if (!buf) {
225 debug_info("Out of memory");
226 res = MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR;
227 goto leave_unlock;
228 }
229 debug_info("uploading image (%d bytes)", (int)image_size);
230 while (tx < image_size) {
231 size_t remaining = image_size - tx;
232 size_t amount = (remaining < bufsize) ? remaining : bufsize;
233 ssize_t r = upload_cb(buf, amount, userdata);
234 if (r < 0) {
235 debug_info("upload_cb returned %d", (int)r);
236 break;
237 }
238 uint32_t sent = 0;
239 if (service_send(client->parent->parent, (const char*)buf, (uint32_t)r, &sent) != SERVICE_E_SUCCESS) {
240 debug_info("service_send failed");
241 break;
242 }
243 tx += r;
244 }
245 free(buf);
246 if (tx < image_size) {
247 debug_info("Error: failed to upload image");
248 res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED;
249 goto leave_unlock;
250 }
251 debug_info("image uploaded");
252
253 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result));
254 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
255 debug_info("Error receiving response from device!");
256 goto leave_unlock;
257 }
258 res = process_result(result, "Complete");
259
260 leave_unlock:
261 mobile_image_mounter_unlock(client);
262 if (result)
263 plist_free(result);
264 return res;
265
266 }
267
268 mobile_image_mounter_error_t mobile_image_mounter_mount_image_with_options(mobile_image_mounter_client_t client, const char *image_path, const unsigned char *signature, unsigned int signature_size, const char *image_type, plist_t options, plist_t *result)
269 {
270 if (!client || !image_path || !image_type || !result) {
271 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
272 }
273 mobile_image_mounter_lock(client);
274
275 plist_t dict = plist_new_dict();
276 plist_dict_set_item(dict, "Command", plist_new_string("MountImage"));
277 plist_dict_set_item(dict, "ImagePath", plist_new_string(image_path));
278 if (signature && signature_size != 0)
279 plist_dict_set_item(dict, "ImageSignature", plist_new_data((char*)signature, signature_size));
280 plist_dict_set_item(dict, "ImageType", plist_new_string(image_type));
281 if (PLIST_IS_DICT(options)) {
282 plist_dict_merge(&dict, options);
283 }
284
285 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
286 plist_free(dict);
287
288 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
289 debug_info("%s: Error sending XML plist to device!", __func__);
290 goto leave_unlock;
291 }
292
293 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, result));
294 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
295 debug_info("%s: Error receiving response from device!", __func__);
296 }
297
298 leave_unlock:
299 mobile_image_mounter_unlock(client);
300 return res;
301 }
302
303 mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, const char *image_path, const unsigned char *signature, unsigned int signature_size, const char *image_type, plist_t *result)
304 {
305 return mobile_image_mounter_mount_image_with_options(client, image_path, signature, signature_size, image_type, NULL, result);
306 }
307
308 mobile_image_mounter_error_t mobile_image_mounter_unmount_image(mobile_image_mounter_client_t client, const char *mount_path)
309 {
310 if (!client || !mount_path) {
311 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
312 }
313 mobile_image_mounter_lock(client);
314
315 plist_t dict = plist_new_dict();
316 plist_dict_set_item(dict, "Command", plist_new_string("UnmountImage"));
317 plist_dict_set_item(dict, "MountPath", plist_new_string(mount_path));
318 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
319 plist_free(dict);
320
321 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
322 debug_info("%s: Error sending XML plist to device!", __func__);
323 goto leave_unlock;
324 }
325
326 plist_t result = NULL;
327 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result));
328 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
329 debug_info("%s: Error receiving response from device!", __func__);
330 } else {
331 plist_t p_error = plist_dict_get_item(result, "Error");
332 if (p_error) {
333 plist_t p_detailed = plist_dict_get_item(result, "DetailedError");
334 const char* detailederr = (p_detailed) ? plist_get_string_ptr(p_detailed, NULL) : "";
335 const char* errstr = plist_get_string_ptr(p_error, NULL);
336 if (errstr && !strcmp(errstr, "UnknownCommand")) {
337 res = MOBILE_IMAGE_MOUNTER_E_NOT_SUPPORTED;
338 } else if (errstr && !strcmp(errstr, "DeviceLocked")) {
339 res = MOBILE_IMAGE_MOUNTER_E_DEVICE_LOCKED;
340 } else if (strstr(detailederr, "no matching entry")) {
341 res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED;
342 } else {
343 res = MOBILE_IMAGE_MOUNTER_E_UNKNOWN_ERROR;
344 }
345 }
346 }
347
348 leave_unlock:
349 mobile_image_mounter_unlock(client);
350 return res;
351 }
352
353 mobile_image_mounter_error_t mobile_image_mounter_hangup(mobile_image_mounter_client_t client)
354 {
355 if (!client) {
356 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
357 }
358 mobile_image_mounter_lock(client);
359
360 plist_t dict = plist_new_dict();
361 plist_dict_set_item(dict, "Command", plist_new_string("Hangup"));
362
363 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
364 plist_free(dict);
365
366 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
367 debug_info("%s: Error sending XML plist to device!", __func__);
368 goto leave_unlock;
369 }
370
371 dict = NULL;
372 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &dict));
373 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
374 debug_info("%s: Error receiving response from device!", __func__);
375 }
376 if (dict) {
377 debug_plist(dict);
378 plist_free(dict);
379 }
380
381 leave_unlock:
382 mobile_image_mounter_unlock(client);
383 return res;
384 }
385
386 mobile_image_mounter_error_t mobile_image_mounter_query_developer_mode_status(mobile_image_mounter_client_t client, plist_t *result)
387 {
388 if (!client || !result) {
389 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
390 }
391 mobile_image_mounter_lock(client);
392
393 plist_t dict = plist_new_dict();
394 plist_dict_set_item(dict, "Command", plist_new_string("QueryDeveloperModeStatus"));
395 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
396 plist_free(dict);
397
398 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
399 debug_info("%s: Error sending XML plist to device!", __func__);
400 goto leave_unlock;
401 }
402
403 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, result));
404 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
405 debug_info("%s: Error receiving response from device!", __func__);
406 }
407
408 leave_unlock:
409 mobile_image_mounter_unlock(client);
410 return res;
411 }
412
413 mobile_image_mounter_error_t mobile_image_mounter_query_nonce(mobile_image_mounter_client_t client, const char* image_type, unsigned char** nonce, unsigned int* nonce_size)
414 {
415 if (!client || !nonce || !nonce_size) {
416 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
417 }
418 mobile_image_mounter_lock(client);
419
420 plist_t dict = plist_new_dict();
421 plist_dict_set_item(dict, "Command", plist_new_string("QueryNonce"));
422 if (image_type) {
423 plist_dict_set_item(dict, "PersonalizedImageType", plist_new_string(image_type));
424 }
425 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
426 plist_free(dict);
427
428 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
429 debug_info("%s: Error sending XML plist to device!", __func__);
430 goto leave_unlock;
431 }
432
433 plist_t result = NULL;
434 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result));
435 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
436 debug_info("%s: Error receiving response from device!", __func__);
437 } else {
438 plist_t p_nonce = plist_dict_get_item(result, "PersonalizationNonce");
439 if (!p_nonce) {
440 res = MOBILE_IMAGE_MOUNTER_E_NOT_SUPPORTED;
441 } else {
442 uint64_t nonce_size_ = 0;
443 plist_get_data_val(p_nonce, (char**)nonce, &nonce_size_);
444 if (*nonce) {
445 *nonce_size = (unsigned int)nonce_size_;
446 } else {
447 res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED;
448 }
449 }
450 }
451 plist_free(result);
452
453 leave_unlock:
454 mobile_image_mounter_unlock(client);
455 return res;
456 }
457
458 mobile_image_mounter_error_t mobile_image_mounter_query_personalization_identifiers(mobile_image_mounter_client_t client, const char* image_type, plist_t *result)
459 {
460 if (!client || !result) {
461 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
462 }
463 mobile_image_mounter_lock(client);
464
465 plist_t dict = plist_new_dict();
466 plist_dict_set_item(dict, "Command", plist_new_string("QueryPersonalizationIdentifiers"));
467 if (image_type) {
468 plist_dict_set_item(dict, "PersonalizedImageType", plist_new_string(image_type));
469 }
470 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
471 plist_free(dict);
472
473 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
474 debug_info("%s: Error sending XML plist to device!", __func__);
475 goto leave_unlock;
476 }
477
478 plist_t _result = NULL;
479 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &_result));
480 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
481 debug_info("%s: Error receiving response from device!", __func__);
482 }
483 *result = plist_copy(plist_dict_get_item(_result, "PersonalizationIdentifiers"));
484 if (!*result) {
485 debug_info("%s: Response did not contain PersonalizationIdentifiers!", __func__);
486 res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED;
487 }
488
489 leave_unlock:
490 mobile_image_mounter_unlock(client);
491 return res;
492 }
493
494 mobile_image_mounter_error_t mobile_image_mounter_query_personalization_manifest(mobile_image_mounter_client_t client, const char* image_type, const unsigned char* signature, unsigned int signature_size, unsigned char** manifest, unsigned int* manifest_size)
495 {
496 if (!client || !image_type || !signature || !signature_size || !manifest || !manifest_size) {
497 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
498 }
499 mobile_image_mounter_lock(client);
500
501 plist_t dict = plist_new_dict();
502 plist_dict_set_item(dict, "Command", plist_new_string("QueryPersonalizationManifest"));
503 plist_dict_set_item(dict, "PersonalizedImageType", plist_new_string(image_type));
504 plist_dict_set_item(dict, "ImageType", plist_new_string(image_type));
505 plist_dict_set_item(dict, "ImageSignature", plist_new_data((char*)signature, signature_size));
506
507 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
508 plist_free(dict);
509
510 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
511 debug_info("%s: Error sending XML plist to device!", __func__);
512 goto leave_unlock;
513 }
514
515 plist_t result = NULL;
516 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result));
517 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
518 debug_info("%s: Error receiving response from device!", __func__);
519 } else {
520 plist_t p_manifest = plist_dict_get_item(result, "ImageSignature");
521 if (!p_manifest) {
522 res = MOBILE_IMAGE_MOUNTER_E_NOT_SUPPORTED;
523 } else {
524 uint64_t manifest_size_ = 0;
525 plist_get_data_val(p_manifest, (char**)manifest, &manifest_size_);
526 if (*manifest) {
527 *manifest_size = (unsigned int)manifest_size_;
528 } else {
529 res = MOBILE_IMAGE_MOUNTER_E_COMMAND_FAILED;
530 }
531 }
532 }
533 plist_free(result);
534
535 leave_unlock:
536 mobile_image_mounter_unlock(client);
537 return res;
538 }
539
540 mobile_image_mounter_error_t mobile_image_mounter_roll_personalization_nonce(mobile_image_mounter_client_t client)
541 {
542 if (!client) {
543 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
544 }
545 mobile_image_mounter_lock(client);
546
547 plist_t dict = plist_new_dict();
548 plist_dict_set_item(dict, "Command", plist_new_string("RollPersonalizationNonce"));
549 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
550 plist_free(dict);
551
552 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
553 debug_info("%s: Error sending XML plist to device!", __func__);
554 goto leave_unlock;
555 }
556
557 plist_t result = NULL;
558 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result));
559 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
560 debug_info("%s: Error receiving response from device!", __func__);
561 }
562 plist_free(result);
563
564 leave_unlock:
565 mobile_image_mounter_unlock(client);
566 return res;
567 }
568
569 mobile_image_mounter_error_t mobile_image_mounter_roll_cryptex_nonce(mobile_image_mounter_client_t client)
570 {
571 if (!client) {
572 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
573 }
574 mobile_image_mounter_lock(client);
575
576 plist_t dict = plist_new_dict();
577 plist_dict_set_item(dict, "Command", plist_new_string("RollCryptexNonce"));
578 mobile_image_mounter_error_t res = mobile_image_mounter_error(property_list_service_send_xml_plist(client->parent, dict));
579 plist_free(dict);
580
581 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
582 debug_info("%s: Error sending XML plist to device!", __func__);
583 goto leave_unlock;
584 }
585
586 plist_t result = NULL;
587 res = mobile_image_mounter_error(property_list_service_receive_plist(client->parent, &result));
588 if (res != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
589 debug_info("%s: Error receiving response from device!", __func__);
590 }
591 plist_free(result);
592
593 leave_unlock:
594 mobile_image_mounter_unlock(client);
595 return res;
596 }