DeviceStatus Device::getName() { char *name = NULL; lockdownd_get_device_name(this->mLockDown, &name); this->mName = name; free(name); return StatusOK; }
SWIGEXPORT jshort JNICALL Java_org_robovm_libimobiledevice_binding_libimobiledeviceJNI_lockdownd_1get_1device_1name(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2) { jshort jresult = 0 ; lockdownd_client_t arg1 = (lockdownd_client_t) 0 ; char **arg2 = (char **) 0 ; lockdownd_error_t result; (void)jenv; (void)jcls; arg1 = *(lockdownd_client_t *)&jarg1; arg2 = *(char ***)&jarg2; result = (lockdownd_error_t)lockdownd_get_device_name(arg1,arg2); jresult = (jshort)result; return jresult; }
int fill_in_info() { plist_t *node=NULL; char* type=NULL; char* version=NULL; char* name=NULL; char* img=NULL; lockdownd_get_device_name(client, &name); lockdownd_get_value(client, NULL, "ProductType", &node); plist_get_string_val(node, &type); plist_free(node); node=NULL; lockdownd_get_value(client, NULL, "ProductVersion", &node); plist_get_string_val(node, &version); plist_free(node); node=NULL; plist_from_xml(img_plist, strlen(img_plist), &node); plist_t devNode=plist_dict_get_item(node, type); if (!devNode) { printf("ERROR: Unknown device!\n"); } plist_get_string_val(devNode, &img); plist_free(node); node=NULL; strcpy(data, ""); gtk_image_set_from_file(devImg, img); //gtk_label_set_use_underline(dName, TRUE); char devL[512]=""; snprintf(devL, 512, "<b>%s</b>", name); gtk_label_set_text(dName, name); gtk_label_set_markup(dName, devL); gtk_label_set_text(fV, version); return 0; }
int main(int argc, char **argv) { idevice_t device = NULL; lockdownd_client_t client = NULL; char **dev_list = NULL; char *devname = NULL; int ret = 0; int i; int mode = MODE_SHOW_ID; const char* udid = NULL; /* parse cmdline args */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) { idevice_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 udid was passed */ if (mode == MODE_SHOW_ID) { i--; if (!argv[i] || (strlen(argv[i]) != 40)) { print_usage(argc, argv); return 0; } udid = argv[i]; } switch (mode) { case MODE_SHOW_ID: idevice_new(&device, udid); if (!device) { fprintf(stderr, "ERROR: No device with UDID=%s attached.\n", udid); return -2; } if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(device, &client, "idevice_id")) { idevice_free(device); 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); idevice_free(device); if (ret == 0) { printf("%s\n", devname); } if (devname) { free(devname); } return ret; case MODE_LIST_DEVICES: default: if (idevice_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]); } idevice_device_list_free(dev_list); return 0; } }
int main(int argc, char** argv) { int res = -1; char* udid = NULL; int c = 0; int optidx = 0; const struct option longopts[] = { { "udid", required_argument, NULL, 'u' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0} }; while ((c = getopt_long(argc, argv, "du:h", longopts, &optidx)) != -1) { switch (c) { case 'u': udid = strdup(optarg); break; case 'h': print_usage(); return 0; case 'd': idevice_set_debug_level(1); break; default: print_usage(); return -1; } } argc -= optind; argv += optind; if (argc > 1) { print_usage(); return -1; } idevice_t device = NULL; if (idevice_new(&device, udid) != IDEVICE_E_SUCCESS) { fprintf(stderr, "ERROR: Could not connect to device\n"); return -1; } lockdownd_client_t lockdown = NULL; lockdownd_error_t lerr = lockdownd_client_new_with_handshake(device, &lockdown, "idevicename"); if (lerr != LOCKDOWN_E_SUCCESS) { idevice_free(device); fprintf(stderr, "ERROR: lockdown connection failed, lockdown error %d\n", lerr); return -1; } if (argc == 0) { // getting device name char* name = NULL; lerr = lockdownd_get_device_name(lockdown, &name); if (name) { printf("%s\n", name); free(name); res = 0; } else { fprintf(stderr, "ERROR: Could not get device name, lockdown error %d\n", lerr); } } else { // setting device name lerr = lockdownd_set_value(lockdown, NULL, "DeviceName", plist_new_string(argv[0])); if (lerr == LOCKDOWN_E_SUCCESS) { printf("device name set to '%s'\n", argv[0]); res = 0; } else { fprintf(stderr, "ERROR: Could not set device name, lockdown error %d\n", lerr); } } lockdownd_client_free(lockdown); idevice_free(device); if (udid) { free(udid); } return res; }
int main(int argc, const char **argv) { char *errmsg = ""; idevice_t device = NULL; lockdownd_client_t client = NULL; lockdownd_service_descriptor_t service = NULL; house_arrest_client_t hac = NULL; const char *service_name = "com.apple.afc"; const char *appid = NULL; char *device_name = NULL; int result = 0; char* udid = NULL; int cmd = CMD_INTERACTIVE; const char *cmdstr = NULL; int i; cwd = strdup("/"); /* parse cmdline args */ for (i = 1; i < argc; i++) { if (str_is_equal(argv[i], "-d") || str_is_equal(argv[i], "--debug")) { idevice_set_debug_level(1); continue; } else if (str_is_equal(argv[i], "-u") || str_is_equal(argv[i], "--udid")) { i++; if (!argv[i] || (strlen(argv[i]) != 40)) { print_usage(argc, argv); exit(EXIT_FAILURE); } udid = strdup(argv[i]); continue; } else if (str_is_equal(argv[i], "-2") || str_is_equal(argv[i], "--afc2")) { service_name = "com.apple.afc2"; continue; } else if (str_is_equal(argv[i], "-a") || str_is_equal(argv[i], "--appid")) { if (++i >= argc) { print_usage(argc, argv); exit(EXIT_FAILURE); } appid = argv[i]; } else if (str_is_equal(argv[i], "-h") || str_is_equal(argv[i], "--help")) { print_usage(argc, argv); exit(EXIT_SUCCESS); } else if ((cmd = str_to_cmd(argv[i])) != CMD_UNKNOWN) { cmdstr = argv[i]; i++; break; } } argc -= i; argv += i; /* Connect to device */ if (udid) { result = idevice_new(&device, udid); if (result != IDEVICE_E_SUCCESS) errx(EXIT_FAILURE, "No device found with udid %s, is it plugged in?", udid); } else { result = idevice_new(&device, NULL); if (result != IDEVICE_E_SUCCESS) errx(EXIT_FAILURE, "No device found, is it plugged in?"); idevice_get_udid(device, &udid); } /* Connect to lockdownd */ result = lockdownd_client_new_with_handshake(device, &client, "afccl"); if (result != LOCKDOWN_E_SUCCESS) { asprintf(&errmsg, "ERROR: Connecting to lockdownd service failed!"); goto bail; } result = lockdownd_get_device_name(client, &device_name); if ((result != LOCKDOWN_E_SUCCESS) || !device_name) { asprintf(&errmsg, "ERROR: Could not get device name!"); goto bail; } if (appid) { result = lockdownd_start_service(client, "com.apple.mobile.house_arrest", &service); if (result != LOCKDOWN_E_SUCCESS || !service || !service->port) { asprintf(&errmsg, "error starting house arrest service: (%d) %s", result, afc_strerror(result)); goto bail; } if (client) { lockdownd_client_free(client); client = NULL; } if (house_arrest_client_new(device, service, &hac) != HOUSE_ARREST_E_SUCCESS) { asprintf(&errmsg, "could not connect to house_arrest service!\n"); goto bail; } if (service) { lockdownd_service_descriptor_free(service); service = NULL; } result = house_arrest_send_command(hac, "VendDocuments", appid); if (result != HOUSE_ARREST_E_SUCCESS) { asprintf(&errmsg, "error %d when trying to get VendDocuments\n", result); goto bail; } plist_t dict = NULL; if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) { if (house_arrest_get_result(hac, &dict) != HOUSE_ARREST_E_SUCCESS) { asprintf(&errmsg, "hmmm....\n"); goto bail; } } plist_t node = plist_dict_get_item(dict, "Error"); if (node) { char *str = NULL; plist_get_string_val(node, &str); asprintf(&errmsg, "Error: %s\n", str); if (str) free(str); plist_free(dict); dict = NULL; goto bail; } node = plist_dict_get_item(dict, "Status"); if (node) { char *str = NULL; plist_get_string_val(node, &str); if (str && (strcmp(str, "Complete") != 0)) { printf("Warning: Status is not 'Complete' but '%s'\n", str); } if (str) free(str); } if (dict) { plist_free(dict); } afc_error_t ae = afc_client_new_from_house_arrest_client(hac, &afc); if (ae != AFC_E_SUCCESS) { printf("afc error %d\n", ae); } } else { result = lockdownd_start_service(client, service_name, &service); if (result != LOCKDOWN_E_SUCCESS || !service || !service->port) { asprintf(&errmsg, "error starting AFC service: (%d) %s", result, afc_strerror(result)); goto bail; } /* Connect to AFC */ result = afc_client_new(device, service, &afc); lockdownd_client_free(client); idevice_free(device); if (result != AFC_E_SUCCESS) { errx(EXIT_FAILURE, "AFC connection failed (%d) %s", result, afc_strerror(result)); } } result = do_cmd(cmd, argc, argv); if (hac) house_arrest_client_free(hac); afc_client_free(afc); exit(result == 0 ? EXIT_SUCCESS : EXIT_FAILURE); bail: if (hac) house_arrest_client_free(hac); if (service) lockdownd_service_descriptor_free(service); if (client) lockdownd_client_free(client); if (device) idevice_free(device); errx(EXIT_FAILURE, "%s", errmsg); }
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[]) { unsigned int bytes = 0; uint16_t i = 0; lockdownd_service_descriptor_t service = NULL; lockdownd_client_t client = NULL; idevice_t phone = NULL; uint64_t lockfile = 0; np_client_t gnp = NULL; if (argc > 1 && !strcasecmp(argv[1], "--debug")) { idevice_set_debug_level(1); } else { idevice_set_debug_level(0); } if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) { printf("No device found, is it plugged in?\n"); return -1; } char *udid = NULL; if (IDEVICE_E_SUCCESS == idevice_get_udid(phone, &udid)) { printf("DeviceUniqueID : %s\n", udid); } if (udid) free(udid); if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "ideviceclient")) { idevice_free(phone); printf("Exiting.\n"); return -1; } char *nnn = NULL; if (LOCKDOWN_E_SUCCESS == lockdownd_get_device_name(client, &nnn)) { printf("DeviceName : %s\n", nnn); free(nnn); } lockdownd_start_service(client, "com.apple.afc", &service); if (service && service->port) { afc_client_t afc = NULL; afc_client_new(phone, service, &afc); if (afc) { service->port = 0; service->ssl_enabled = 0; lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service); if (service->port) { printf("Notification Proxy started.\n"); np_client_new(phone, service, &gnp); } else { printf("ERROR: Notification proxy could not be started.\n"); } if (gnp) { const char *nspec[5] = { NP_SYNC_CANCEL_REQUEST, NP_SYNC_SUSPEND_REQUEST, NP_SYNC_RESUME_REQUEST, NP_ITDBPREP_DID_END, NULL }; np_observe_notifications(gnp, nspec); np_set_notify_callback(gnp, notifier, NULL); } perform_notification(phone, client, NP_SYNC_WILL_START); afc_file_open(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); if (lockfile) { printf("locking file\n"); afc_file_lock(afc, lockfile, AFC_LOCK_EX); perform_notification(phone, client, NP_SYNC_DID_START); } char **dirs = NULL; afc_read_directory(afc, "/eafaedf", &dirs); if (!dirs) afc_read_directory(afc, "/", &dirs); printf("Directory time.\n"); for (i = 0; dirs[i]; i++) { printf("/%s\n", dirs[i]); free(dirs[i]); } if (dirs) free(dirs); dirs = NULL; afc_get_device_info(afc, &dirs); if (dirs) { for (i = 0; dirs[i]; i += 2) { printf("%s: %s\n", dirs[i], dirs[i + 1]); free(dirs[i]); } free(dirs); } uint64_t my_file = 0; char **info = NULL; uint64_t fsize = 0; if (AFC_E_SUCCESS == afc_get_file_info(afc, "/readme.libimobiledevice.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 (AFC_E_SUCCESS == afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { printf("A file size: %llu\n", (long long)fsize); char *file_data = (char *) malloc(sizeof(char) * fsize); afc_file_read(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"); afc_file_close(afc, my_file); free(file_data); } else printf("couldn't open a file\n"); afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_WR, &my_file); if (my_file) { char *outdatafile = strdup("this is a bitchin text file\n"); afc_file_write(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"); afc_file_close(afc, my_file); } printf("Deleting a file...\n"); bytes = afc_remove_path(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 = afc_rename_path(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"); afc_file_open(afc, "/readme.libimobiledevice.fx", AFC_FOPEN_RDONLY, &my_file); if (AFC_E_SUCCESS != afc_file_seek(afc, my_file, 5, SEEK_CUR)) printf("WARN: SEEK DID NOT WORK\n"); char *threeletterword = (char *) malloc(sizeof(char) * 5); afc_file_read(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); afc_file_close(afc, my_file); } if (gnp && lockfile) { printf("XXX sleeping\n"); sleep(5); printf("XXX unlocking file\n"); afc_file_lock(afc, lockfile, AFC_LOCK_UN); printf("XXX closing file\n"); afc_file_close(afc, lockfile); printf("XXX sleeping\n"); sleep(5); //perform_notification(phone, client, NP_SYNC_DID_FINISH); } if (gnp) { np_client_free(gnp); gnp = NULL; } afc_client_free(afc); lockdownd_service_descriptor_free(service); service = NULL; } else { printf("Start service failure.\n"); } printf("All done.\n"); lockdownd_client_free(client); idevice_free(phone); return 0; }