int main(int argc, char *argv[]) { int bytes = 0, port = 0, i = 0; iphone_lckd_client_t control = NULL; iphone_device_t phone = NULL; if (argc > 1 && !strcasecmp(argv[1], "--debug")) iphone_set_debug_mask(DBGMASK_MOBILESYNC); if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { printf("No iPhone found, is it plugged in?\n"); return -1; } if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { iphone_free_device(phone); return -1; } iphone_lckd_start_service(control, "com.apple.mobilesync", &port); if (port) { iphone_msync_client_t msync = NULL; iphone_msync_new_client(phone, port, &msync); if (msync) { iphone_msync_get_all_contacts(msync); iphone_msync_free_client(msync); } } else { printf("Start service failure.\n"); } printf("All done.\n"); iphone_lckd_free_client(control); iphone_free_device(phone); return 0; }
int main(int argc, char *argv[]) { iphone_lckd_client_t control = NULL; iphone_device_t phone = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; int i; int format = FORMAT_KEY_VALUE; char uuid[41]; char *domain = NULL; char *key = NULL; uuid[0] = 0; /* parse cmdline args */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { iphone_set_debug_mask(DBGMASK_ALL); iphone_set_debug(1); continue; } else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { i++; if (!argv[i] || (strlen(argv[i]) != 40)) { print_usage(argc, argv); return 0; } strcpy(uuid, argv[i]); continue; } else if (!strcmp(argv[i], "-q") || !strcmp(argv[i], "--domain")) { i++; if (!argv[i] || (strlen(argv[i]) < 4)) { print_usage(argc, argv); return 0; } if (!is_domain_known(argv[i])) { fprintf(stderr, "WARNING: Sending query with unknown domain \"%s\".\n", argv[i]); } domain = strdup(argv[i]); continue; } else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--key")) { i++; if (!argv[i] || (strlen(argv[i]) <= 1)) { print_usage(argc, argv); return 0; } key = strdup(argv[i]); continue; } else if (!strcmp(argv[i], "-x") || !strcmp(argv[i], "--xml")) { format = FORMAT_XML; continue; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { print_usage(argc, argv); return 0; } else { print_usage(argc, argv); return 0; } } if (uuid[0] != 0) { ret = iphone_get_device_by_uuid(&phone, uuid); if (ret != IPHONE_E_SUCCESS) { printf("No device found with uuid %s, is it plugged in?\n", uuid); return -1; } } else { ret = iphone_get_device(&phone); if (ret != IPHONE_E_SUCCESS) { printf("No device found, is it plugged in?\n"); return -1; } } if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { iphone_free_device(phone); return -1; } /* run query and output information */ print_lckd_request_result(control, domain, "GetValue", key, format); if (domain != NULL) free(domain); iphone_lckd_free_client(control); iphone_free_device(phone); return 0; }
int main(int argc, char *argv[]) { int bytes = 0, port = 0, i = 0; int npp; iphone_lckd_client_t control = NULL; iphone_device_t phone = NULL; uint64_t lockfile = 0; iphone_np_client_t gnp = NULL; if (argc > 1 && !strcasecmp(argv[1], "--debug")) { iphone_set_debug(1); iphone_set_debug_mask(DBGMASK_ALL); } else { iphone_set_debug(0); iphone_set_debug_mask(DBGMASK_NONE); } if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { printf("No iPhone found, is it plugged in?\n"); return -1; } if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { iphone_free_device(phone); printf("Exiting.\n"); return -1; } char *uid = NULL; if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) { printf("DeviceUniqueID : %s\n", uid); free(uid); } char *nnn = NULL; if (IPHONE_E_SUCCESS == lockdownd_get_device_name(control, &nnn)) { printf("DeviceName : %s\n", nnn); free(nnn); } iphone_lckd_start_service(control, "com.apple.afc", &port); if (port) { iphone_afc_client_t afc = NULL; iphone_afc_new_client(phone, port, &afc); if (afc) { iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); if (npp) { printf("Notification Proxy started.\n"); iphone_np_new_client(phone, npp, &gnp); } else { printf("ERROR: Notification proxy could not be started.\n"); } if (gnp) { const char *nspec[4] = { NP_SYNC_CANCEL_REQUEST, NP_SYNC_SUSPEND_REQUEST, NP_SYNC_RESUME_REQUEST, NULL }; iphone_np_observe_notifications(gnp, nspec); iphone_np_set_notify_callback(gnp, notifier); } perform_notification(phone, control, NP_SYNC_WILL_START); iphone_afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); if (lockfile) { printf("locking file\n"); iphone_afc_lock_file(afc, lockfile, 2 | 4); perform_notification(phone, control, NP_SYNC_DID_START); } char **dirs = NULL; iphone_afc_get_dir_list(afc, "/eafaedf", &dirs); if (!dirs) iphone_afc_get_dir_list(afc, "/", &dirs); printf("Directory time.\n"); for (i = 0; dirs[i]; i++) { printf("/%s\n", dirs[i]); } g_strfreev(dirs); dirs = NULL; iphone_afc_get_devinfo(afc, &dirs); if (dirs) { for (i = 0; dirs[i]; i += 2) { printf("%s: %s\n", dirs[i], dirs[i + 1]); } } g_strfreev(dirs); uint64_t my_file = 0; char **info = NULL; uint64_t fsize = 0; if (IPHONE_E_SUCCESS == iphone_afc_get_file_info(afc, "/readme.libiphone.fx", &info) && info) { for (i = 0; info[i]; i += 2) { printf("%s: %s\n", info[i], info[i+1]); if (!strcmp(info[i], "st_size")) { fsize = atoll(info[i+1]); } } } if (IPHONE_E_SUCCESS == iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { printf("A file size: %i\n", fsize); char *file_data = (char *) malloc(sizeof(char) * fsize); iphone_afc_read_file(afc, my_file, file_data, fsize, &bytes); if (bytes >= 0) { printf("The file's data:\n"); fwrite(file_data, 1, bytes, stdout); } printf("\nClosing my file.\n"); iphone_afc_close_file(afc, my_file); free(file_data); } else printf("couldn't open a file\n"); iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_WR, &my_file); if (my_file) { char *outdatafile = strdup("this is a bitchin text file\n"); iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); free(outdatafile); if (bytes > 0) printf("Wrote a surprise. ;)\n"); else printf("I wanted to write a surprise, but... :(\n"); iphone_afc_close_file(afc, my_file); } printf("Deleting a file...\n"); bytes = iphone_afc_delete_file(afc, "/delme"); if (bytes) printf("Success.\n"); else printf("Failure. (expected unless you have a /delme file on your phone)\n"); printf("Renaming a file...\n"); bytes = iphone_afc_rename_file(afc, "/renme", "/renme2"); if (bytes > 0) printf("Success.\n"); else printf("Failure. (expected unless you have a /renme file on your phone)\n"); printf("Seek & read\n"); iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file); if (IPHONE_E_SUCCESS != iphone_afc_seek_file(afc, my_file, 5, SEEK_CUR)) printf("WARN: SEEK DID NOT WORK\n"); char *threeletterword = (char *) malloc(sizeof(char) * 5); iphone_afc_read_file(afc, my_file, threeletterword, 3, &bytes); threeletterword[3] = '\0'; if (bytes > 0) printf("Result: %s\n", threeletterword); else printf("Couldn't read!\n"); free(threeletterword); iphone_afc_close_file(afc, my_file); } if (gnp && lockfile) { char *noti; /* noti = NULL; iphone_np_get_notification(gnp, ¬i); if (noti) { printf("------> received notification '%s'\n", noti); free(noti); }*/ printf("XXX sleeping\n"); /*for (i = 0; i < 5; i++) { noti = NULL; printf("--- getting notification\n"); iphone_np_get_notification(gnp, ¬i); if (noti) { printf("------> received notification '%s'\n", noti); free(noti); } else { printf("---- no notification\n"); } sleep(1); } */ sleep(5); //perform_notification(phone, control, NP_SYNC_DID_FINISH); printf("XXX unlocking file\n"); iphone_afc_lock_file(afc, lockfile, 8 | 4); printf("XXX closing file\n"); iphone_afc_close_file(afc, lockfile); } if (gnp) { iphone_np_free_client(gnp); gnp = NULL; } iphone_afc_free_client(afc); } else { printf("Start service failure.\n"); } printf("All done.\n"); iphone_lckd_free_client(control); iphone_free_device(phone); return 0; }
int main(int argc, char **argv) { iphone_device_t phone = NULL; lockdownd_client_t client = NULL; char **dev_list = NULL; char *devname = NULL; int ret = 0; int i; int mode = MODE_SHOW_ID; char uuid[41]; uuid[0] = 0; /* parse cmdline args */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { iphone_set_debug_mask(DBGMASK_ALL); iphone_set_debug_level(1); continue; } else if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--list")) { mode = MODE_LIST_DEVICES; continue; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { print_usage(argc, argv); return 0; } } /* check if uuid was passed */ if (mode == MODE_SHOW_ID) { i--; if (!argv[i] || (strlen(argv[i]) != 40)) { print_usage(argc, argv); return 0; } strcpy(uuid, argv[i]); } switch (mode) { case MODE_SHOW_ID: iphone_device_new(&phone, uuid); if (!phone) { fprintf(stderr, "ERROR: No device with UUID=%s attached.\n", uuid); return -2; } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { iphone_device_free(phone); fprintf(stderr, "ERROR: Connecting to device failed!\n"); return -2; } if ((LOCKDOWN_E_SUCCESS != lockdownd_get_device_name(client, &devname)) || !devname) { fprintf(stderr, "ERROR: Could not get device name!\n"); ret = -2; } lockdownd_client_free(client); iphone_device_free(phone); if (ret == 0) { printf("%s\n", devname); } if (devname) { free(devname); } return ret; case MODE_LIST_DEVICES: default: if (iphone_get_device_list(&dev_list, &i) < 0) { fprintf(stderr, "ERROR: Unable to retrieve device list!\n"); return -1; } for (i = 0; dev_list[i] != NULL; i++) { printf("%s\n", dev_list[i]); } iphone_device_list_free(dev_list); return 0; } }