int ipsw_get_component_by_path(const char* ipsw, plist_t tss, const char* path, char** data, uint32_t* size) {
	img3_file* img3 = NULL;
	uint32_t component_size = 0;
	char* component_data = NULL;
	char* component_blob = NULL;
	char* component_name = NULL;

	component_name = strrchr(path, '/');
	if (component_name != NULL)
		component_name++;
	else
		component_name = (char*) path;

	info("Extracting %s\n", component_name);
	if (ipsw_extract_to_memory(ipsw, path, &component_data, &component_size) < 0) {
		error("ERROR: Unable to extract %s from %s\n", component_name, ipsw);
		return -1;
	}

	if (tss) {
		img3 = img3_parse_file(component_data, component_size);
		if (img3 == NULL) {
			error("ERROR: Unable to parse IMG3: %s\n", component_name);
			free(component_data);
			return -1;
		}
		free(component_data);

		/* sign the blob if required */
		if (tss_get_blob_by_path(tss, path, &component_blob) < 0) {
			error("ERROR: Unable to get SHSH blob for TSS %s entry\n", component_name);
			img3_free(img3);
			return -1;
		}

		info("Signing %s\n", component_name);
		if (img3_replace_signature(img3, component_blob) < 0) {
			error("ERROR: Unable to replace IMG3 signature\n");
			free(component_blob);
			img3_free(img3);
			return -1;
		}

		if (component_blob)
			free(component_blob);

		if (img3_get_data(img3, &component_data, &component_size) < 0) {
			error("ERROR: Unable to reconstruct IMG3\n");
			img3_free(img3);
			return -1;
		}
		img3_free(img3);
	}

	if (idevicerestore_debug) {
		write_file(component_name, component_data, component_size);
	}

	*data = component_data;
	*size = component_size;
	return 0;
}
Пример #2
0
int ipsw_get_component_by_path(const char* ipsw, plist_t tss, const char* component, const char* path, unsigned char** data, unsigned int* size) {
	img3_file* img3 = NULL;
	unsigned int component_size = 0;
	unsigned char* component_data = NULL;
	unsigned char* component_blob = NULL;
	char* component_name = NULL;

	component_name = strrchr(path, '/');
	if (component_name != NULL)
		component_name++;
	else
		component_name = (char*) path;

	info("Extracting %s...\n", component_name);

	if (ipsw_extract_to_memory(ipsw, path, &component_data, &component_size) < 0) {
		error("ERROR: Unable to extract %s from %s\n", component_name, ipsw);
		return -1;
	}

	if (tss) {
		/* try to get blob for current component from tss response */
		if (component) {
			if (tss_get_blob_by_name(tss, component, &component_blob) < 0) {
				debug("NOTE: No SHSH blob found for TSS entry %s from component %s\n", component_name, component);
			}
		} else {
			if (tss_get_blob_by_path(tss, path, &component_blob) < 0) {
				debug("NOTE: No SHSH blob found for TSS entry %s from path %s\n", component_name, path);
			}
		}

		if (component_blob != NULL) {
			/* parse current component as img3 */
			img3 = img3_parse_file(component_data, component_size);
			if (img3 == NULL) {
				error("ERROR: Unable to parse IMG3: %s\n", component_name);
				free(component_blob);
				free(component_data);
				return -1;
			}

			/* we no longer require the original data */
			free(component_data);

			info("Personalizing component %s...\n", component_name);

			/* personalize the component using the blob */
			if (img3_replace_signature(img3, component_blob) < 0) {
				error("ERROR: Unable to replace IMG3 signature\n");
				free(component_blob);
				img3_free(img3);
				return -1;
			}

			/* get the img3 file as data */
			if (img3_get_data(img3, &component_data, &component_size) < 0) {
				error("ERROR: Unable to reconstruct IMG3\n");
				free(component_blob);
				img3_free(img3);
				return -1;
			}

			/* cleanup */
			img3_free(img3);
		} else {
			info("Not personalizing component %s...\n", component_name);
		}

		if (component_blob)
			free(component_blob);
	}

	if (idevicerestore_debug) {
		write_file(component_name, component_data, component_size);
	}

	*data = component_data;
	*size = component_size;
	return 0;
}