void minst_client(const char *operation, plist_t status, void *unused) { cb++; if (cb == 8) { } if (status && operation) { plist_t npercent = plist_dict_get_item(status, "PercentComplete"); plist_t nstatus = plist_dict_get_item(status, "Status"); plist_t nerror = plist_dict_get_item(status, "Error"); int percent = 0; char *status_msg = NULL; if (npercent) { uint64_t val = 0; plist_get_uint_val(npercent, &val); percent = val; } if (nstatus) { plist_get_string_val(nstatus, &status_msg); if (!strcmp(status_msg, "Complete")) { sleep(1); installing = 0; } } if (nerror) { char *err_msg = NULL; plist_get_string_val(nerror, &err_msg); free(err_msg); installing = 0; installError = 1; } } else { } }
int restore_handle_progress_msg(restored_client_t client, plist_t msg) { plist_t node = NULL; uint64_t progress = 0; uint64_t operation = 0; node = plist_dict_get_item(msg, "Operation"); if (!node || plist_get_node_type(node) != PLIST_UINT) { debug("Failed to parse operation from ProgressMsg plist\n"); return -1; } plist_get_uint_val(node, &operation); node = plist_dict_get_item(msg, "Progress"); if (!node || plist_get_node_type(node) != PLIST_UINT) { debug("Failed to parse progress from ProgressMsg plist \n"); return -1; } plist_get_uint_val(node, &progress); if ((progress > 0) && (progress < 100)) { print_progress_bar(restore_progress_string(operation), (double) progress); } else { info("%s\n", restore_progress_string(operation)); } return 0; }
/** * Checks if a notification has been sent by the device. * * @param client NP to get a notification from * @param notification Pointer to a buffer that will be allocated and filled * with the notification that has been received. * * @return 0 if a notification has been received or nothing has been received, * or a negative value if an error occured. * * @note You probably want to check out np_set_notify_callback * @see np_set_notify_callback */ static int np_get_notification(np_client_t client, char **notification) { int res = 0; plist_t dict = NULL; if (!client || !client->parent || *notification) return -1; np_lock(client); property_list_service_error_t perr = property_list_service_receive_plist_with_timeout(client->parent, &dict, 500); if (perr == PROPERTY_LIST_SERVICE_E_RECEIVE_TIMEOUT) { debug_info("NotificationProxy: no notification received!"); res = 0; } else if (perr != PROPERTY_LIST_SERVICE_E_SUCCESS) { debug_info("NotificationProxy: error %d occured!", perr); res = perr; } if (dict) { char *cmd_value = NULL; plist_t cmd_value_node = plist_dict_get_item(dict, "Command"); if (plist_get_node_type(cmd_value_node) == PLIST_STRING) { plist_get_string_val(cmd_value_node, &cmd_value); } if (cmd_value && !strcmp(cmd_value, "RelayNotification")) { char *name_value = NULL; plist_t name_value_node = plist_dict_get_item(dict, "Name"); if (plist_get_node_type(name_value_node) == PLIST_STRING) { plist_get_string_val(name_value_node, &name_value); } res = -2; if (name_value_node && name_value) { *notification = name_value; debug_info("got notification %s", __func__, name_value); res = 0; } } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { debug_info("NotificationProxy died!"); res = -1; } else if (cmd_value) { debug_info("unknown NotificationProxy command '%s' received!", cmd_value); res = -1; } else { res = -2; } if (cmd_value) { free(cmd_value); } plist_free(dict); dict = NULL; } np_unlock(client); return res; }
static int ignore_pl(plist_t pl, const char *name) { uint64_t kind; int smart; uint8_t master; uint8_t party; kind = 0; smart = 0; master = 0; party = 0; /* Special (builtin) playlists */ get_dictval_int_from_key(pl, "Distinguished Kind", &kind); /* Import smart playlists (optional) */ if (!cfg_getbool(cfg_getsec(cfg, "library"), "itunes_smartpl") && (plist_dict_get_item(pl, "Smart Info") || plist_dict_get_item(pl, "Smart Criteria"))) smart = 1; /* Not interested in the Master playlist */ get_dictval_bool_from_key(pl, "Master", &master); /* Not interested in Party Shuffle playlists */ get_dictval_bool_from_key(pl, "Party Shuffle", &party); if ((kind > 0) || smart || party || master) { DPRINTF(E_INFO, L_SCAN, "Ignoring playlist '%s' (k %" PRIu64 " s%d p%d m%d)\n", name, kind, smart, party, master); return 1; } return 0; }
void build_manifest_print_information(plist_t build_manifest) { char* value = NULL; plist_t node = NULL; node = plist_dict_get_item(build_manifest, "ProductVersion"); if (!node || plist_get_node_type(node) != PLIST_STRING) { error("ERROR: Unable to find ProductVersion node\n"); return; } plist_get_string_val(node, &value); info("Product Version: %s\n", value); free(value); node = plist_dict_get_item(build_manifest, "ProductBuildVersion"); if (!node || plist_get_node_type(node) != PLIST_STRING) { error("ERROR: Unable to find ProductBuildVersion node\n"); return; } plist_get_string_val(node, &value); info("Product Build: %s\n", value); free(value); node = NULL; }
static int ignore_pl(plist_t pl, char *name) { uint64_t kind; int smart; uint8_t master; uint8_t party; kind = 0; smart = 0; master = 0; party = 0; /* Special (builtin) playlists */ get_dictval_int_from_key(pl, "Distinguished Kind", &kind); /* If only we could recover the smart playlists ... */ if (plist_dict_get_item(pl, "Smart Info") || plist_dict_get_item(pl, "Smart Criteria")) smart = 1; /* Not interested in the Master playlist */ get_dictval_bool_from_key(pl, "Master", &master); /* Not interested in Party Shuffle playlists */ get_dictval_bool_from_key(pl, "Party Shuffle", &party); if ((kind > 0) || smart || party || master) { DPRINTF(E_INFO, L_SCAN, "Ignoring playlist '%s' (k %" PRIu64 " s%d p%d m%d)\n", name, kind, smart, party, master); return 1; } return 0; }
LIBIMOBILEDEVICE_API mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, const char *request, const char *target_identifier, const char *source_identifier, plist_t options) { if (!client || !client->parent || !request || !target_identifier) return MOBILEBACKUP2_E_INVALID_ARG; plist_t dict = plist_new_dict(); plist_dict_set_item(dict, "TargetIdentifier", plist_new_string(target_identifier)); if (source_identifier) { plist_dict_set_item(dict, "SourceIdentifier", plist_new_string(source_identifier)); } if (options) { plist_dict_set_item(dict, "Options", plist_copy(options)); } if (!strcmp(request, "Unback") && options) { plist_t node = plist_dict_get_item(options, "Password"); if (node) { plist_dict_set_item(dict, "Password", plist_copy(node)); } } if (!strcmp(request, "EnableCloudBackup") && options) { plist_t node = plist_dict_get_item(options, "CloudBackupState"); if (node) { plist_dict_set_item(dict, "CloudBackupState", plist_copy(node)); } } mobilebackup2_error_t err = mobilebackup2_send_message(client, request, dict); plist_free(dict); return err; }
LIBIMOBILEDEVICE_API restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version) { if (!client) return RESTORE_E_INVALID_ARG; restored_error_t ret = RESTORE_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_add_label(dict, client->label); plist_dict_set_item(dict,"Request", plist_new_string("QueryType")); debug_info("called"); ret = restored_send(client, dict); plist_free(dict); dict = NULL; ret = restored_receive(client, &dict); if (RESTORE_E_SUCCESS != ret) return ret; ret = RESTORE_E_UNKNOWN_ERROR; plist_t type_node = plist_dict_get_item(dict, "Type"); if (type_node && (plist_get_node_type(type_node) == PLIST_STRING)) { char* typestr = NULL; /* save our device information info */ client->info = dict; plist_get_string_val(type_node, &typestr); debug_info("success with type %s", typestr); /* return the type if requested */ if (type) { *type = typestr; } else { free(typestr); } /* fetch the restore protocol version */ if (version) { plist_t version_node = plist_dict_get_item(dict, "RestoreProtocolVersion"); if (version_node && PLIST_UINT == plist_get_node_type(version_node)) { plist_get_uint_val(version_node, version); debug_info("restored protocol version %llu", *version); } else { return RESTORE_E_UNKNOWN_ERROR; } } ret = RESTORE_E_SUCCESS; } else { debug_info("hmm. QueryType response does not contain a type?!"); debug_plist(dict); plist_free(dict); } return ret; }
LIBIMOBILEDEVICE_API instproxy_error_t instproxy_get_app_path_by_name(instproxy_client_t client, const char* app_name, char ** app_path, char ** exec_path) { instproxy_error_t res = INSTPROXY_E_UNKNOWN_ERROR; plist_t apps = NULL; plist_t client_options = instproxy_client_options_new(); instproxy_client_options_add(client_options, "ApplicationType", "Any", NULL); res = instproxy_browse(client, client_options, &apps); instproxy_client_options_free(client_options); int app_count = plist_array_get_size(apps); for(int app_index = 0; app_index < app_count; app_index++){ plist_t app_info_plist = plist_array_get_item(apps, app_index); plist_t app_bundle_display_name_plist = plist_dict_get_item(app_info_plist, "CFBundleDisplayName"); char* app_name_tmp = NULL; plist_t app_path_plist = NULL; plist_t exec_path_plist = NULL; if (app_bundle_display_name_plist) { plist_get_string_val(app_bundle_display_name_plist, &app_name_tmp); } if (app_name_tmp == NULL || strcasecmp(app_name_tmp, app_name) != 0) { continue; } char * app_path_tmp = NULL; char * exec_path_tmp = NULL; app_path_plist = plist_dict_get_item(app_info_plist, "Path"); if (app_path_plist) { plist_get_string_val(app_path_plist, &app_path_tmp); } exec_path_plist = plist_dict_get_item(app_info_plist, "CFBundleExecutable"); if (exec_path_plist) { plist_get_string_val(exec_path_plist, &exec_path_tmp); } size_t app_path_length = strlen(app_path_tmp); size_t exec_path_length = strlen(exec_path_tmp); *app_path = (char *)alloca(app_path_length + 1); *exec_path = (char *)alloca(exec_path_length + 1); memset(*app_path, 0, app_path_length + 1); memset(*exec_path, 0, exec_path_length + 1); memcpy(*app_path, app_path_tmp, strlen(app_path_tmp)); memcpy(*exec_path, exec_path_tmp, strlen(exec_path_tmp)); break; } return res; }
wi_status wi_parse_plist(wi_t self, const char *from_buf, size_t length, plist_t *to_rpc_dict, bool *to_is_partial) { wi_private_t my = self->private_state; *to_is_partial = false; *to_rpc_dict = NULL; if (my->is_sim) { plist_from_bin(from_buf, length, to_rpc_dict); } else { plist_t wi_dict = NULL; plist_from_bin(from_buf, length, &wi_dict); if (!wi_dict) { return WI_ERROR; } plist_t wi_rpc = plist_dict_get_item(wi_dict, "WIRFinalMessageKey"); if (!wi_rpc) { wi_rpc = plist_dict_get_item(wi_dict, "WIRPartialMessageKey"); if (!wi_rpc) { return WI_ERROR; } *to_is_partial = true; } uint64_t rpc_len = 0; char *rpc_bin = NULL; plist_get_data_val(wi_rpc, &rpc_bin, &rpc_len); plist_free(wi_dict); // also frees wi_rpc if (!rpc_bin) { return WI_ERROR; } // assert rpc_len < MAX_RPC_LEN? size_t p_length = my->partial->tail - my->partial->head; if (*to_is_partial || p_length) { if (cb_ensure_capacity(my->partial, rpc_len)) { return self->on_error(self, "Out of memory"); } memcpy(my->partial->tail, rpc_bin, rpc_len); my->partial->tail += rpc_len; p_length += rpc_len; free(rpc_bin); if (*to_is_partial) { return WI_SUCCESS; } } if (p_length) { plist_from_bin(my->partial->head, (uint32_t)p_length, to_rpc_dict); cb_clear(my->partial); } else { plist_from_bin(rpc_bin, (uint32_t)rpc_len, to_rpc_dict); free(rpc_bin); } } return (*to_rpc_dict ? WI_SUCCESS : WI_ERROR); }
/** * Performs the mobilebackup2 protocol version exchange. * * @param client The MobileBackup client to use. * @param local_versions An array of supported versions to send to the remote. * @param count The number of items in local_versions. * @param remote_version Holds the protocol version of the remote on success. * * @return MOBILEBACKUP2_E_SUCCESS on success, or a MOBILEBACKUP2_E_* error * code otherwise. */ mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version) { int i; if (!client || !client->parent) return MOBILEBACKUP2_E_INVALID_ARG; plist_t dict = plist_new_dict(); plist_t array = plist_new_array(); for (i = 0; i < count; i++) { plist_array_append_item(array, plist_new_real(local_versions[i])); } plist_dict_insert_item(dict, "SupportedProtocolVersions", array); mobilebackup2_error_t err = mobilebackup2_send_message(client, "Hello", dict); plist_free(dict); if (err != MOBILEBACKUP2_E_SUCCESS) goto leave; dict = NULL; err = internal_mobilebackup2_receive_message(client, "Response", &dict); if (err != MOBILEBACKUP2_E_SUCCESS) goto leave; /* check if we received an error */ plist_t node = plist_dict_get_item(dict, "ErrorCode"); if (!node || (plist_get_node_type(node) != PLIST_UINT)) { err = MOBILEBACKUP2_E_PLIST_ERROR; goto leave; } uint64_t val = 0; plist_get_uint_val(node, &val); if (val != 0) { if (val == 1) { err = MOBILEBACKUP2_E_NO_COMMON_VERSION; } else { err = MOBILEBACKUP2_E_REPLY_NOT_OK; } goto leave; } /* retrieve the protocol version of the device */ node = plist_dict_get_item(dict, "ProtocolVersion"); if (!node || (plist_get_node_type(node) != PLIST_REAL)) { err = MOBILEBACKUP2_E_PLIST_ERROR; goto leave; } *remote_version = 0.0; plist_get_real_val(node, remote_version); leave: if (dict) plist_free(dict); return err; }
int tss_request_add_ap_img3_tags(plist_t request, plist_t parameters) { plist_t node = NULL; if (!parameters) { error("ERROR: Missing required AP parameters\n"); return -1; } /* ApNonce */ node = plist_dict_get_item(parameters, "ApNonce"); if (node) { if (plist_get_node_type(node) != PLIST_DATA) { error("ERROR: Unable to find required ApNonce in parameters\n"); return -1; } plist_dict_set_item(request, "ApNonce", plist_copy(node)); node = NULL; } /* @APTicket */ plist_dict_set_item(request, "@APTicket", plist_new_bool(1)); /* ApBoardID */ node = plist_dict_get_item(request, "ApBoardID"); if (!node || plist_get_node_type(node) != PLIST_UINT) { error("ERROR: Unable to find required ApBoardID in request\n"); return -1; } node = NULL; /* ApChipID */ node = plist_dict_get_item(request, "ApChipID"); if (!node || plist_get_node_type(node) != PLIST_UINT) { error("ERROR: Unable to find required ApChipID in request\n"); return -1; } node = NULL; /* ApSecurityDomain */ node = plist_dict_get_item(request, "ApSecurityDomain"); if (!node || plist_get_node_type(node) != PLIST_UINT) { error("ERROR: Unable to find required ApSecurityDomain in request\n"); return -1; } node = NULL; /* ApProductionMode */ node = plist_dict_get_item(parameters, "ApProductionMode"); if (!node || plist_get_node_type(node) != PLIST_BOOLEAN) { error("ERROR: Unable to find required ApProductionMode in parameters\n"); return -1; } plist_dict_set_item(request, "ApProductionMode", plist_copy(node)); node = NULL; return 0; }
int tss_response_get_blob_by_path(plist_t tss, const char* path, unsigned char** blob) { uint32_t i = 0; uint32_t tss_size = 0; uint64_t blob_size = 0; char* entry_key = NULL; char* blob_data = NULL; char* entry_path = NULL; plist_t tss_entry = NULL; plist_t blob_node = NULL; plist_t path_node = NULL; plist_dict_iter iter = NULL; *blob = NULL; plist_dict_new_iter(tss, &iter); tss_size = plist_dict_get_size(tss); for (i = 0; i < tss_size; i++) { plist_dict_next_item(tss, iter, &entry_key, &tss_entry); if (entry_key == NULL) break; if (!tss_entry || plist_get_node_type(tss_entry) != PLIST_DICT) { continue; } path_node = plist_dict_get_item(tss_entry, "Path"); if (!path_node || plist_get_node_type(path_node) != PLIST_STRING) { error("ERROR: Unable to find TSS path node in entry %s\n", entry_key); free(iter); return -1; } plist_get_string_val(path_node, &entry_path); if (strcmp(path, entry_path) == 0) { blob_node = plist_dict_get_item(tss_entry, "Blob"); if (!blob_node || plist_get_node_type(blob_node) != PLIST_DATA) { error("ERROR: Unable to find TSS blob node in entry %s\n", entry_key); free(iter); return -1; } plist_get_data_val(blob_node, &blob_data, &blob_size); break; } free(entry_key); } free(iter); if (blob_data == NULL || blob_size <= 0) { return -1; } *blob = (unsigned char*)blob_data; return 0; }
/** * Query the type of the service daemon. Depending on whether the device is * queried in normal mode or restore mode, different types will be returned. * * @param client The restored client * @param type The type returned by the service daemon. Pass NULL to ignore. * @param version The restore protocol version. Pass NULL to ignore. * * @return RESTORE_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL */ restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version) { if (!client) return RESTORE_E_INVALID_ARG; restored_error_t ret = RESTORE_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_add_label(dict, client->label); plist_dict_insert_item(dict,"Request", plist_new_string("QueryType")); debug_info("called"); ret = restored_send(client, dict); plist_free(dict); dict = NULL; ret = restored_receive(client, &dict); if (RESTORE_E_SUCCESS != ret) return ret; ret = RESTORE_E_UNKNOWN_ERROR; if (restored_check_result(dict) == RESULT_SUCCESS) { /* save our device information info */ client->info = dict; /* return the type if requested */ if (type) { plist_t type_node = plist_dict_get_item(dict, "Type"); if (type_node && PLIST_STRING == plist_get_node_type(type_node)) { plist_get_string_val(type_node, type); debug_info("success with type %s", *type); ret = RESTORE_E_SUCCESS; } else { return RESTORE_E_UNKNOWN_ERROR; } } /* fetch the restore protocol version */ if (version) { plist_t version_node = plist_dict_get_item(dict, "RestoreProtocolVersion"); if (version_node && PLIST_UINT == plist_get_node_type(version_node)) { plist_get_uint_val(version_node, version); debug_info("restored protocol version %llu", *version); ret = RESTORE_E_SUCCESS; } else { return RESTORE_E_UNKNOWN_ERROR; } } ret = RESTORE_E_SUCCESS; } return ret; }
/** * Get a screen shot from the connected device. * * @param client The connection screenshotr service client. * @param imgdata Pointer that will point to a newly allocated buffer * containing TIFF image data upon successful return. It is up to the * caller to free the memory. * @param imgsize Pointer to a uint64_t that will be set to the size of the * buffer imgdata points to upon successful return. * * @return SCREENSHOTR_E_SUCCESS on success, SCREENSHOTR_E_INVALID_ARG if * one or more parameters are invalid, or another error code if an * error occured. */ screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize) { if (!client || !client->parent || !imgdata) return SCREENSHOTR_E_INVALID_ARG; screenshotr_error_t res = SCREENSHOTR_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_insert_item(dict, "MessageType", plist_new_string("ScreenShotRequest")); res = screenshotr_error(device_link_service_send_process_message(client->parent, dict)); plist_free(dict); if (res != SCREENSHOTR_E_SUCCESS) { debug_info("could not send plist, error %d", res); return res; } dict = NULL; res = screenshotr_error(device_link_service_receive_process_message(client->parent, &dict)); if (res != SCREENSHOTR_E_SUCCESS) { debug_info("could not get screenshot data, error %d", res); goto leave; } if (!dict) { debug_info("did not receive screenshot data!"); res = SCREENSHOTR_E_PLIST_ERROR; goto leave; } plist_t node = plist_dict_get_item(dict, "MessageType"); char *strval = NULL; plist_get_string_val(node, &strval); if (!strval || strcmp(strval, "ScreenShotReply")) { debug_info("invalid screenshot data received!"); res = SCREENSHOTR_E_PLIST_ERROR; goto leave; } node = plist_dict_get_item(dict, "ScreenShotData"); if (!node || plist_get_node_type(node) != PLIST_DATA) { debug_info("no PNG data received!"); res = SCREENSHOTR_E_PLIST_ERROR; goto leave; } plist_get_data_val(node, imgdata, imgsize); res = SCREENSHOTR_E_SUCCESS; leave: if (dict) plist_free(dict); return res; }
static void status_cb(const char *operation, plist_t status) #endif { if (status && operation) { plist_t npercent = plist_dict_get_item(status, "PercentComplete"); plist_t nstatus = plist_dict_get_item(status, "Status"); plist_t nerror = plist_dict_get_item(status, "Error"); int percent = 0; char *status_msg = NULL; if (npercent) { uint64_t val = 0; plist_get_uint_val(npercent, &val); percent = val; } if (nstatus) { plist_get_string_val(nstatus, &status_msg); if (!strcmp(status_msg, "Complete")) { op_completed = 1; } } if (!nerror) { if (last_status && (strcmp(last_status, status_msg))) { printf("\r"); } if (!npercent) { printf("%s - %s\n", operation, status_msg); } else { printf("%s - %s (%d%%)\n", operation, status_msg, percent); } } else { char *err_msg = NULL; plist_get_string_val(nerror, &err_msg); printf("%s - Error occured: %s\n", operation, err_msg); free(err_msg); err_occured = 1; } if (last_status) { free(last_status); last_status = NULL; } if (status_msg) { last_status = strdup(status_msg); free(status_msg); } } else { printf("%s: called with invalid data!\n", __func__); } }
int isManifestSignedForDevice(char *buildManifestPath, char **device, uint64_t ecid, int checkBaseband, char **version){ int isSigned = 0; #define reterror(a ...) {error(a); isSigned = -1; goto error;} plist_t manifest = NULL; plist_t ProductVersion = NULL; plist_t SupportedProductTypes = NULL; plist_t mDevice = NULL; info("[TSSC] opening %s\n",buildManifestPath); //filehandling FILE *fmanifest = fopen(buildManifestPath, "r"); if (!fmanifest) reterror("[TSSC] ERROR: file %s nof found!\n",buildManifestPath); fseek(fmanifest, 0, SEEK_END); long fsize = ftell(fmanifest); fseek(fmanifest, 0, SEEK_SET); char *bufManifest = (char*)malloc(fsize + 1); fread(bufManifest, fsize, 1, fmanifest); fclose(fmanifest); plist_from_xml(bufManifest, (unsigned)strlen(bufManifest), &manifest); if (version && !*version){ if (!manifest){ warning("[TSSC] WARNING: could not find ProductVersion in BuildManifest.plist, failing to properly display iOS version\n"); }else{ ProductVersion = plist_dict_get_item(manifest, "ProductVersion"); plist_get_string_val(ProductVersion, version); } } if (!*device) { if (manifest){ SupportedProductTypes = plist_dict_get_item(manifest, "SupportedProductTypes"); if (SupportedProductTypes) { mDevice = plist_array_get_item(SupportedProductTypes, 0); plist_get_string_val(mDevice, device); } } if (!*device) reterror("[TSSR] ERROR: device wasn't specified and could not be fetched from BuildManifest\n") else info("[TSSR] requesting ticket for %s\n",*device); } isSigned = isManifestBufSignedForDevice(bufManifest, *device, ecid, checkBaseband); error: if (manifest) plist_free(manifest); free(bufManifest); return isSigned; #undef reterror }
int tss_populate_basebandvals(plist_t tssreq, plist_t tssparameters, int64_t BbGoldCertId){ plist_t parameters = plist_new_dict(); char bbnonce[noncelen+1]; char bbsnum[5]; int64_t BbChipID = 0; getRandNum(bbnonce, noncelen, 256); getRandNum(bbsnum, 4, 256); int n=0; for (int i=1; i<7; i++) BbChipID += (arc4random() % 10) * pow(10, ++n); plist_dict_set_item(parameters, "BbNonce", plist_new_data(bbnonce, noncelen)); plist_dict_set_item(parameters, "BbChipID", plist_new_uint(BbChipID)); plist_dict_set_item(parameters, "BbGoldCertId", plist_new_uint(BbGoldCertId)); plist_dict_set_item(parameters, "BbSNUM", plist_new_data(bbsnum, 4)); /* BasebandFirmware */ plist_t BasebandFirmware = plist_access_path(tssparameters, 2, "Manifest", "BasebandFirmware"); if (!BasebandFirmware || plist_get_node_type(BasebandFirmware) != PLIST_DICT) { error("ERROR: Unable to get BasebandFirmware node\n"); return -1; } plist_t bbfwdict = plist_copy(BasebandFirmware); BasebandFirmware = NULL; if (plist_dict_get_item(bbfwdict, "Info")) { plist_dict_remove_item(bbfwdict, "Info"); } plist_dict_set_item(tssreq, "BasebandFirmware", bbfwdict); tss_request_add_baseband_tags(tssreq, parameters, NULL); return 0; }
static mobileactivation_error_t mobileactivation_send_command_plist(mobileactivation_client_t client, plist_t command, plist_t *result) { if (!client || !command) return MOBILEACTIVATION_E_INVALID_ARG; plist_t cmd = plist_dict_get_item(command, "Command"); char* command_str = NULL; if (cmd) { plist_get_string_val(cmd, &command_str); } if (!command_str) return MOBILEACTIVATION_E_INVALID_ARG; mobileactivation_error_t ret = MOBILEACTIVATION_E_UNKNOWN_ERROR; *result = NULL; ret = mobileactivation_error(property_list_service_send_binary_plist(client->parent, command)); plist_t dict = NULL; ret = mobileactivation_error(property_list_service_receive_plist(client->parent, &dict)); if (!dict) { debug_info("ERROR: Did not get reply for %s command", command_str); free(command_str); return MOBILEACTIVATION_E_PLIST_ERROR; } *result = dict; ret = mobileactivation_check_result(dict, command_str); free(command_str); return ret; }
/** * Internally used function for checking the result from restore's answer * plist to a previously sent request. * * @param dict The plist to evaluate. * @param query_match Name of the request to match. * * @return RESULT_SUCCESS when the result is 'Success', * RESULT_FAILURE when the result is 'Failure', * or a negative value if an error occured during evaluation. */ static int restored_check_result(plist_t dict) { int ret = -1; plist_t result_node = plist_dict_get_item(dict, "Result"); if (!result_node) { return ret; } plist_type result_type = plist_get_node_type(result_node); if (result_type == PLIST_STRING) { char *result_value = NULL; plist_get_string_val(result_node, &result_value); if (result_value) { if (!strcmp(result_value, "Success")) { ret = RESULT_SUCCESS; } else if (!strcmp(result_value, "Failure")) { ret = RESULT_FAILURE; } else { debug_info("ERROR: unknown result value '%s'", result_value); } } if (result_value) free(result_value); } return ret; }
void plist_dict_merge(plist_t *target, plist_t source) { if (!target || !*target || (plist_get_node_type(*target) != PLIST_DICT) || !source || (plist_get_node_type(source) != PLIST_DICT)) return; char* key = NULL; plist_dict_iter it = NULL; plist_t subnode = NULL; plist_dict_new_iter(source, &it); if (!it) return; do { plist_dict_next_item(source, it, &key, &subnode); if (!key) break; if (plist_dict_get_item(*target, key) != NULL) plist_dict_remove_item(*target, key); plist_dict_insert_item(*target, key, plist_copy(subnode)); free(key); key = NULL; } while (1); free(it); }
DeviceStatus Device::getApps() { plist_t apps = NULL; plist_t opts; opts = instproxy_client_options_new(); instproxy_client_options_add(opts, "ApplicationType", "Any", NULL); if (instproxy_browse(this->mInstProxy, opts, &apps) != INSTPROXY_E_SUCCESS) { instproxy_client_options_free(opts); return StatusError; } int count = plist_array_get_size(apps) / 2; for (int i = 0; i < count; i++) { plist_t app; app = plist_array_get_item(apps, i); plist_t appId; appId = plist_dict_get_item(app, "CFBundleIdentifier"); char *sAppId; plist_get_string_val(appId, &sAppId); this->mApps.insert(sAppId); //cout << i << "\t" << sAppId << endl; free(sAppId); plist_free(appId); plist_free(app); } plist_free(apps); instproxy_client_options_free(opts); return StatusOK; }
/** * Retrieves a value from information plist specified by a key. * * @param client An initialized restored client. * @param key The key name to request or NULL to query for all keys * @param value A plist node representing the result value node * * @return RESTORE_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL, RESTORE_E_PLIST_ERROR if value for key can't be found */ restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value) { if (!client || !value || (value && *value)) return RESTORE_E_INVALID_ARG; if (!client->info) return RESTORE_E_NOT_ENOUGH_DATA; restored_error_t ret = RESTORE_E_SUCCESS; plist_t item = NULL; if (!key) { *value = plist_copy(client->info); return RESTORE_E_SUCCESS; } else { item = plist_dict_get_item(client->info, key); } if (item) { *value = plist_copy(item); } else { ret = RESTORE_E_PLIST_ERROR; } return ret; }
/** * Get the home screen wallpaper as PNG data. * * @param client The connected sbservices client to use. * @param pngdata Pointer that will point to a newly allocated buffer * containing the PNG data upon successful return. It is up to the caller * to free the memory. * @param pngsize Pointer to a uint64_t that will be set to the size of the * buffer pngdata points to upon successful return. * * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when * client or pngdata are invalid, or an SBSERVICES_E_* error * code otherwise. */ sbservices_error_t sbservices_get_home_screen_wallpaper_pngdata(sbservices_client_t client, char **pngdata, uint64_t *pngsize) { if (!client || !client->parent || !pngdata) return SBSERVICES_E_INVALID_ARG; sbservices_error_t res = SBSERVICES_E_UNKNOWN_ERROR; plist_t dict = plist_new_dict(); plist_dict_insert_item(dict, "command", plist_new_string("getHomeScreenWallpaperPNGData")); sbs_lock(client); res = sbservices_error(property_list_service_send_binary_plist(client->parent, dict)); if (res != SBSERVICES_E_SUCCESS) { debug_info("could not send plist, error %d", res); goto leave_unlock; } plist_free(dict); dict = NULL; res = sbservices_error(property_list_service_receive_plist(client->parent, &dict)); if (res == SBSERVICES_E_SUCCESS) { plist_t node = plist_dict_get_item(dict, "pngData"); if (node) { plist_get_data_val(node, pngdata, pngsize); } } leave_unlock: if (dict) { plist_free(dict); } sbs_unlock(client); return res; }
int tss_request_add_common_tags(plist_t request, plist_t parameters, plist_t overrides) { plist_t node = NULL; /* ApECID */ node = plist_dict_get_item(parameters, "ApECID"); if (!node || plist_get_node_type(node) != PLIST_UINT) { error("ERROR: Unable to find required ApECID in parameters\n"); return -1; } plist_dict_set_item(request, "ApECID", plist_copy(node)); node = NULL; /* UniqueBuildID */ node = plist_dict_get_item(parameters, "UniqueBuildID"); if (node) { plist_dict_set_item(request, "UniqueBuildID", plist_copy(node)); } node = NULL; /* ApChipID */ node = plist_dict_get_item(parameters, "ApChipID"); if (node) { plist_dict_set_item(request, "ApChipID", plist_copy(node)); } node = NULL; /* ApBoardID */ node = plist_dict_get_item(parameters, "ApBoardID"); if (node) { plist_dict_set_item(request, "ApBoardID", plist_copy(node)); } node = NULL; /* ApSecurityDomain */ node = plist_dict_get_item(parameters, "ApSecurityDomain"); if (node) { plist_dict_set_item(request, "ApSecurityDomain", plist_copy(node)); } node = NULL; /* apply overrides */ if (overrides) { plist_dict_merge(&request, overrides); } return 0; }
/** * Request a backup from the connected device. * * @param client The connected MobileBackup client to use. * @param backup_manifest The backup manifest, a plist_t of type PLIST_DICT * containing the backup state of the last backup. For a first-time backup * set this parameter to NULL. * @param base_path The base path on the device to use for the backup * operation, usually "/". * @param proto_version A string denoting the version of the backup protocol * to use. Latest known version is "1.6" * * @return MOBILEBACKUP_E_SUCCESS on success, MOBILEBACKUP_E_INVALID_ARG if * one of the parameters is invalid, MOBILEBACKUP_E_PLIST_ERROR if * backup_manifest is not of type PLIST_DICT, MOBILEBACKUP_E_MUX_ERROR * if a communication error occurs, MOBILEBACKUP_E_REPLY_NOT_OK */ mobilebackup_error_t mobilebackup_request_backup(mobilebackup_client_t client, plist_t backup_manifest, const char *base_path, const char *proto_version) { if (!client || !client->parent || !base_path || !proto_version) return MOBILEBACKUP_E_INVALID_ARG; if (backup_manifest && (plist_get_node_type(backup_manifest) != PLIST_DICT)) return MOBILEBACKUP_E_PLIST_ERROR; mobilebackup_error_t err; /* construct request plist */ plist_t dict = plist_new_dict(); if (backup_manifest) plist_dict_insert_item(dict, "BackupManifestKey", plist_copy(backup_manifest)); plist_dict_insert_item(dict, "BackupComputerBasePathKey", plist_new_string(base_path)); plist_dict_insert_item(dict, "BackupMessageTypeKey", plist_new_string("BackupMessageBackupRequest")); plist_dict_insert_item(dict, "BackupProtocolVersion", plist_new_string(proto_version)); /* send request */ err = mobilebackup_send_message(client, NULL, dict); plist_free(dict); dict = NULL; if (err != MOBILEBACKUP_E_SUCCESS) { debug_info("ERROR: Could not send backup request message (%d)!", err); goto leave; } /* now receive and hopefully get a BackupMessageBackupReplyOK */ err = mobilebackup_receive_message(client, "BackupMessageBackupReplyOK", &dict); if (err != MOBILEBACKUP_E_SUCCESS) { debug_info("ERROR: Could not receive BackupReplyOK message (%d)!", err); goto leave; } plist_t node = plist_dict_get_item(dict, "BackupProtocolVersion"); if (node) { char *str = NULL; plist_get_string_val(node, &str); if (str) { if (strcmp(str, proto_version) != 0) { err = MOBILEBACKUP_E_BAD_VERSION; } free(str); } } if (err != MOBILEBACKUP_E_SUCCESS) goto leave; /* BackupMessageBackupReplyOK received, send it back */ err = mobilebackup_send_message(client, NULL, dict); if (err != MOBILEBACKUP_E_SUCCESS) { debug_info("ERROR: Could not send BackupReplyOK ACK (%d)", err); } leave: if (dict) plist_free(dict); return err; }
LIBIMOBILEDEVICE_API void instproxy_command_get_name(plist_t command, char** name) { *name = NULL; plist_t node = plist_dict_get_item(command, "Command"); if (node) { plist_get_string_val(node, name); } }
int asr_handle_oob_data_request(asr_client_t asr, plist_t packet, FILE* file) { char* oob_data = NULL; uint64_t oob_offset = 0; uint64_t oob_length = 0; plist_t oob_length_node = NULL; plist_t oob_offset_node = NULL; oob_length_node = plist_dict_get_item(packet, "OOB Length"); if (!oob_length_node || PLIST_UINT != plist_get_node_type(oob_length_node)) { error("ERROR: Unable to find OOB data length\n"); return -1; } plist_get_uint_val(oob_length_node, &oob_length); oob_offset_node = plist_dict_get_item(packet, "OOB Offset"); if (!oob_offset_node || PLIST_UINT != plist_get_node_type(oob_offset_node)) { error("ERROR: Unable to find OOB data offset\n"); return -1; } plist_get_uint_val(oob_offset_node, &oob_offset); oob_data = (char*) malloc(oob_length); if (oob_data == NULL) { error("ERROR: Out of memory\n"); plist_free(packet); return -1; } fseek(file, oob_offset, SEEK_SET); if (fread(oob_data, 1, oob_length, file) != oob_length) { error("ERROR: Unable to read OOB data from filesystem offset\n"); plist_free(packet); free(oob_data); return -1; } if (asr_send_buffer(asr, oob_data, oob_length) < 0) { error("ERROR: Unable to send OOB data to ASR\n"); plist_free(packet); free(oob_data); return -1; } free(oob_data); return 0; }
static void instproxy_copy_lookup_result_cb(plist_t command, plist_t status, void *user_data) { plist_t* result = (plist_t*)user_data; plist_t node = plist_dict_get_item(status, "LookupResult"); if (node) { *result = plist_copy(node); } }
LIBIMOBILEDEVICE_API void instproxy_status_get_name(plist_t status, char **name) { *name = NULL; if (name) { plist_t node = plist_dict_get_item(status, "Status"); if (node) { plist_get_string_val(node, name); } } }