diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/ideviceimagemounter.c | 117 |
1 files changed, 64 insertions, 53 deletions
diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c index cd41e6a..29d25d7 100644 --- a/tools/ideviceimagemounter.c +++ b/tools/ideviceimagemounter.c | |||
| @@ -47,6 +47,11 @@ static char *imagetype = NULL; | |||
| 47 | static const char PKG_PATH[] = "PublicStaging"; | 47 | static const char PKG_PATH[] = "PublicStaging"; |
| 48 | static const char PATH_PREFIX[] = "/private/var/mobile/Media"; | 48 | static const char PATH_PREFIX[] = "/private/var/mobile/Media"; |
| 49 | 49 | ||
| 50 | typedef enum { | ||
| 51 | DISK_IMAGE_UPLOAD_TYPE_AFC, | ||
| 52 | DISK_IMAGE_UPLOAD_TYPE_UPLOAD_IMAGE | ||
| 53 | } disk_image_upload_type_t; | ||
| 54 | |||
| 50 | static void print_usage(int argc, char **argv) | 55 | static void print_usage(int argc, char **argv) |
| 51 | { | 56 | { |
| 52 | char *name = NULL; | 57 | char *name = NULL; |
| @@ -178,12 +183,13 @@ int main(int argc, char **argv) | |||
| 178 | if (pver && plist_get_node_type(pver) == PLIST_STRING) { | 183 | if (pver && plist_get_node_type(pver) == PLIST_STRING) { |
| 179 | plist_get_string_val(pver, &product_version); | 184 | plist_get_string_val(pver, &product_version); |
| 180 | } | 185 | } |
| 181 | int ge70 = 0; | 186 | disk_image_upload_type_t disk_image_upload_type = DISK_IMAGE_UPLOAD_TYPE_AFC; |
| 187 | int product_version_major = 0; | ||
| 188 | int product_version_minor = 0; | ||
| 182 | if (product_version) { | 189 | if (product_version) { |
| 183 | int maj = 0; | 190 | if (sscanf(product_version, "%d.%d.%*d", &product_version_major, &product_version_minor) == 2) { |
| 184 | int min = 0; | 191 | if (product_version_major >= 7) |
| 185 | if (sscanf(product_version, "%d.%d.%*d", &maj, &min) == 2) { | 192 | disk_image_upload_type = DISK_IMAGE_UPLOAD_TYPE_UPLOAD_IMAGE; |
| 186 | ge70 = (maj >= 7); | ||
| 187 | } | 193 | } |
| 188 | } | 194 | } |
| 189 | 195 | ||
| @@ -206,7 +212,7 @@ int main(int argc, char **argv) | |||
| 206 | 212 | ||
| 207 | if (!list_mode) { | 213 | if (!list_mode) { |
| 208 | struct stat fst; | 214 | struct stat fst; |
| 209 | if (!ge70) { | 215 | if (disk_image_upload_type == DISK_IMAGE_UPLOAD_TYPE_AFC) { |
| 210 | if ((lockdownd_start_service(lckd, "com.apple.afc", &service) != | 216 | if ((lockdownd_start_service(lckd, "com.apple.afc", &service) != |
| 211 | LOCKDOWN_E_SUCCESS) || !service || !service->port) { | 217 | LOCKDOWN_E_SUCCESS) || !service || !service->port) { |
| 212 | fprintf(stderr, "Could not start com.apple.afc!\n"); | 218 | fprintf(stderr, "Could not start com.apple.afc!\n"); |
| @@ -292,62 +298,67 @@ int main(int argc, char **argv) | |||
| 292 | imagetype = strdup("Developer"); | 298 | imagetype = strdup("Developer"); |
| 293 | } | 299 | } |
| 294 | 300 | ||
| 295 | if (ge70) { | 301 | switch(disk_image_upload_type) { |
| 296 | printf("Uploading %s\n", image_path); | 302 | case DISK_IMAGE_UPLOAD_TYPE_UPLOAD_IMAGE: |
| 297 | err = mobile_image_mounter_upload_image(mim, imagetype, image_size, mim_upload_cb, f); | 303 | printf("Uploading %s\n", image_path); |
| 298 | } else { | 304 | err = mobile_image_mounter_upload_image(mim, imagetype, image_size, sig, sig_length, mim_upload_cb, f); |
| 299 | printf("Uploading %s --> afc:///%s\n", image_path, targetname); | 305 | break; |
| 300 | char **strs = NULL; | 306 | case DISK_IMAGE_UPLOAD_TYPE_AFC: |
| 301 | if (afc_get_file_info(afc, PKG_PATH, &strs) != AFC_E_SUCCESS) { | 307 | default: |
| 302 | if (afc_make_directory(afc, PKG_PATH) != AFC_E_SUCCESS) { | 308 | printf("Uploading %s --> afc:///%s\n", image_path, targetname); |
| 303 | fprintf(stderr, "WARNING: Could not create directory '%s' on device!\n", PKG_PATH); | 309 | char **strs = NULL; |
| 310 | if (afc_get_file_info(afc, PKG_PATH, &strs) != AFC_E_SUCCESS) { | ||
| 311 | if (afc_make_directory(afc, PKG_PATH) != AFC_E_SUCCESS) { | ||
| 312 | fprintf(stderr, "WARNING: Could not create directory '%s' on device!\n", PKG_PATH); | ||
| 313 | } | ||
| 304 | } | 314 | } |
| 305 | } | 315 | if (strs) { |
| 306 | if (strs) { | 316 | int i = 0; |
| 307 | int i = 0; | 317 | while (strs[i]) { |
| 308 | while (strs[i]) { | 318 | free(strs[i]); |
| 309 | free(strs[i]); | 319 | i++; |
| 310 | i++; | 320 | } |
| 321 | free(strs); | ||
| 311 | } | 322 | } |
| 312 | free(strs); | ||
| 313 | } | ||
| 314 | 323 | ||
| 315 | uint64_t af = 0; | 324 | uint64_t af = 0; |
| 316 | if ((afc_file_open(afc, targetname, AFC_FOPEN_WRONLY, &af) != | 325 | if ((afc_file_open(afc, targetname, AFC_FOPEN_WRONLY, &af) != |
| 317 | AFC_E_SUCCESS) || !af) { | 326 | AFC_E_SUCCESS) || !af) { |
| 318 | fclose(f); | 327 | fclose(f); |
| 319 | fprintf(stderr, "afc_file_open on '%s' failed!\n", targetname); | 328 | fprintf(stderr, "afc_file_open on '%s' failed!\n", targetname); |
| 320 | goto leave; | 329 | goto leave; |
| 321 | } | 330 | } |
| 322 | 331 | ||
| 323 | char buf[8192]; | 332 | char buf[8192]; |
| 324 | size_t amount = 0; | 333 | size_t amount = 0; |
| 325 | do { | 334 | do { |
| 326 | amount = fread(buf, 1, sizeof(buf), f); | 335 | amount = fread(buf, 1, sizeof(buf), f); |
| 327 | if (amount > 0) { | 336 | if (amount > 0) { |
| 328 | uint32_t written, total = 0; | 337 | uint32_t written, total = 0; |
| 329 | while (total < amount) { | 338 | while (total < amount) { |
| 330 | written = 0; | 339 | written = 0; |
| 331 | if (afc_file_write(afc, af, buf, amount, &written) != | 340 | if (afc_file_write(afc, af, buf, amount, &written) != |
| 332 | AFC_E_SUCCESS) { | 341 | AFC_E_SUCCESS) { |
| 333 | fprintf(stderr, "AFC Write error!\n"); | 342 | fprintf(stderr, "AFC Write error!\n"); |
| 334 | break; | 343 | break; |
| 344 | } | ||
| 345 | total += written; | ||
| 346 | } | ||
| 347 | if (total != amount) { | ||
| 348 | fprintf(stderr, "Error: wrote only %d of %d\n", total, | ||
| 349 | (unsigned int)amount); | ||
| 350 | afc_file_close(afc, af); | ||
| 351 | fclose(f); | ||
| 352 | goto leave; | ||
| 335 | } | 353 | } |
| 336 | total += written; | ||
| 337 | } | ||
| 338 | if (total != amount) { | ||
| 339 | fprintf(stderr, "Error: wrote only %d of %d\n", total, | ||
| 340 | (unsigned int)amount); | ||
| 341 | afc_file_close(afc, af); | ||
| 342 | fclose(f); | ||
| 343 | goto leave; | ||
| 344 | } | 354 | } |
| 345 | } | 355 | } |
| 346 | } | 356 | while (amount > 0); |
| 347 | while (amount > 0); | ||
| 348 | 357 | ||
| 349 | afc_file_close(afc, af); | 358 | afc_file_close(afc, af); |
| 359 | break; | ||
| 350 | } | 360 | } |
| 361 | |||
| 351 | fclose(f); | 362 | fclose(f); |
| 352 | 363 | ||
| 353 | printf("done.\n"); | 364 | printf("done.\n"); |
