Example #1
0
int recovery_client_new(struct idevicerestore_client_t* client) {
	int i = 0;
	int attempts = 10;
	irecv_client_t recovery = NULL;
	irecv_error_t recovery_error = IRECV_E_UNKNOWN_ERROR;

	if(client->recovery == NULL) {
		client->recovery = (struct recovery_client_t*)malloc(sizeof(struct recovery_client_t));
		if (client->recovery == NULL) {
			error("ERROR: Out of memory\n");
			return -1;
		}
		memset(client->recovery, 0, sizeof(struct recovery_client_t));
	}

	for (i = 1; i <= attempts; i++) {
		recovery_error = irecv_open(&recovery, client->ecid);
		if (recovery_error == IRECV_E_SUCCESS) {
			break;
		}

		if (i >= attempts) {
			error("ERROR: Unable to connect to device in recovery mode\n");
			return -1;
		}

		sleep(4);
		debug("Retrying connection...\n");
	}

	if (client->srnm == NULL) {
		char snbuf[256];
		snbuf[0] = '\0';
		irecv_get_srnm(recovery, snbuf);
		if (snbuf[0] != '\0') {
			client->srnm = strdup(snbuf);
			info("INFO: device serial number is %s\n", client->srnm);
		}
	}

	irecv_event_subscribe(recovery, IRECV_PROGRESS, &recovery_progress_callback, NULL);
	client->recovery->client = recovery;
	return 0;
}
Example #2
0
void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) {
	char* cmd = strdup(command);
	char* action = strtok(cmd, " ");
	debug("Executing %s\n", action);
	if (!strcmp(cmd, "/exit")) {
		quit = 1;
	} else

	if (!strcmp(cmd, "/help")) {
		shell_usage();
	} else

	if (!strcmp(cmd, "/upload")) {
		char* filename = strtok(NULL, " ");
		debug("Uploading files %s\n", filename);
		if (filename != NULL) {
			irecv_send_file(client, filename, 0);
		}
	} else

	if (!strcmp(cmd, "/deviceinfo")) {
		int ret;
		unsigned int cpid, bdid;
		unsigned long long ecid;
		unsigned char srnm[12], imei[15], bt[15];

		ret = irecv_get_cpid(client, &cpid);
		if(ret == IRECV_E_SUCCESS) {
			printf("CPID: %d\n", cpid);
		}

		ret = irecv_get_bdid(client, &bdid);
		if(ret == IRECV_E_SUCCESS) {
			printf("BDID: %d\n", bdid);
		}

		ret = irecv_get_ecid(client, &ecid);
		if(ret == IRECV_E_SUCCESS) {
			printf("ECID: %lld\n", ecid);
		}

		ret = irecv_get_srnm(client, srnm);
		if(ret == IRECV_E_SUCCESS) {
			printf("SRNM: %s\n", srnm);
		}

		ret = irecv_get_imei(client, imei);
		if(ret == IRECV_E_SUCCESS) {
			printf("IMEI: %s\n", imei);
		}
	} else

	if (!strcmp(cmd, "/exploit")) {
		char* filename = strtok(NULL, " ");
		debug("Sending exploit %s\n", filename);
		if (filename != NULL) {
			irecv_send_file(client, filename, 0);
		}
		irecv_send_exploit(client);
	} else

		if (!strcmp(cmd, "/execute")) {
			char* filename = strtok(NULL, " ");
			debug("Executing script %s\n", filename);
			if (filename != NULL) {
				irecv_execute_script(client, filename);
			}
		}


	free(action);
}
Example #3
0
static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) {
	char* cmd = strdup((char*)command);
	char* action = strtok(cmd, " ");

	if (!strcmp(cmd, "/exit")) {
		quit = 1;
	} else if (!strcmp(cmd, "/help")) {
		shell_usage();
	} else if (!strcmp(cmd, "/upload")) {
		char* filename = strtok(NULL, " ");
		debug("Uploading files %s\n", filename);
		if (filename != NULL) {
			irecv_send_file(client, filename, 0);
		}
	} else if (!strcmp(cmd, "/deviceinfo")) {
		int ret, mode;
		unsigned int cpid, bdid;
		unsigned long long ecid;
		char srnm[12], imei[15];

		ret = irecv_get_cpid(client, &cpid);
		if(ret == IRECV_E_SUCCESS) {
			printf("CPID: %d\n", cpid);
		}

		ret = irecv_get_bdid(client, &bdid);
		if(ret == IRECV_E_SUCCESS) {
			printf("BDID: %d\n", bdid);
		}

		ret = irecv_get_ecid(client, &ecid);
		if(ret == IRECV_E_SUCCESS) {
			printf("ECID: " _FMT_lld "\n", ecid);
		}

		ret = irecv_get_srnm(client, srnm);
		if(ret == IRECV_E_SUCCESS) {
			printf("SRNM: %s\n", srnm);
		}

		ret = irecv_get_imei(client, imei);
		if(ret == IRECV_E_SUCCESS) {
			printf("IMEI: %s\n", imei);
		}

		ret = irecv_get_mode(client, &mode);
		if (ret == IRECV_E_SUCCESS) {
			printf("MODE: %s\n", mode_to_str(mode));
		}

	} else if (!strcmp(cmd, "/limera1n")) {
		char* filename = strtok(NULL, " ");
		debug("Sending limera1n payload %s\n", filename);
		if (filename != NULL) {
			irecv_send_file(client, filename, 0);
		}
		irecv_trigger_limera1n_exploit(client);
	} else if (!strcmp(cmd, "/execute")) {
		char* filename = strtok(NULL, " ");
		debug("Executing script %s\n", filename);
		if (filename != NULL) {
			char* buffer = NULL;
			uint64_t buffer_length = 0;
			buffer_read_from_filename(filename, &buffer, &buffer_length);
			if (buffer) {
				buffer[buffer_length] = '\0';
				irecv_execute_script(client, buffer);
				free(buffer);
			} else {
				printf("Could not read file '%s'\n", filename);
			}
		}
	}

	free(action);
}