diff options
author | Nikias Bassen | 2012-07-04 13:51:17 +0200 |
---|---|---|
committer | Nikias Bassen | 2012-07-04 13:51:17 +0200 |
commit | 09ddfb9c0b3f9ee5ad399ef860976295fb4dc890 (patch) | |
tree | 28ae1aec8366a6d6dfec2dd5c90155fc020a4997 | |
parent | 51489dbb69a4e4a0131a74b34235152f131588d1 (diff) | |
download | libirecovery-09ddfb9c0b3f9ee5ad399ef860976295fb4dc890.tar.gz libirecovery-09ddfb9c0b3f9ee5ad399ef860976295fb4dc890.tar.bz2 |
implemented irecv_get_nonce()
-rw-r--r-- | include/libirecovery.h | 1 | ||||
-rw-r--r-- | libirecovery.c | 53 |
2 files changed, 54 insertions, 0 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h index b524cd3..9272ab4 100644 --- a/include/libirecovery.h +++ b/include/libirecovery.h @@ -210,6 +210,7 @@ irecv_error_t irecv_set_interface(irecv_client_t client, int interface, int alt_ irecv_error_t irecv_get_cpid(irecv_client_t client, unsigned int* cpid); irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid); irecv_error_t irecv_get_ecid(irecv_client_t client, unsigned long long* ecid); +irecv_error_t irecv_get_nonce(irecv_client_t client, unsigned char** nonce, int* nonce_size); void irecv_hexdump(unsigned char* buf, unsigned int len, unsigned int addr); void irecv_init(); diff --git a/libirecovery.c b/libirecovery.c index 18763ed..f8f33ca 100644 --- a/libirecovery.c +++ b/libirecovery.c @@ -1059,6 +1059,59 @@ irecv_error_t irecv_get_imei(irecv_client_t client, unsigned char* imei) { return IRECV_E_SUCCESS; } +irecv_error_t irecv_get_nonce(irecv_client_t client, unsigned char** nonce, int* nonce_size) { + if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; + + unsigned char buf[255]; + int len; + + *nonce = NULL; + *nonce_size = 0; + + len = irecv_get_string_descriptor_ascii(client, 1, (unsigned char*) buf, 255); + debug("%s: got length: %d\n", __func__, len); + if (len < 0) { + return len; + } + + buf[len] = 0; + debug("%s: buf='%s'\n", __func__, buf); + + char* nonce_string = strstr(buf, "NONC:"); + if (nonce_string == NULL) { + return IRECV_E_UNKNOWN_ERROR; + } + nonce_string+=5; + + int nlen = (len - ((unsigned char*)nonce_string - &buf[0])) / 2; + unsigned char *nn = malloc(nlen); + if (!nn) { + return IRECV_E_OUT_OF_MEMORY; + } + + int i = 0; + for (i = 0; i < nlen; i++) { + int val = 0; + if (sscanf(nonce_string+(i*2), "%02X", &val) == 1) { + nn[i] = (unsigned char)val; + } else { + debug("%s: ERROR: unexpected data in nonce result (%2s)\n", __func__, nonce_string+(i*2)); + break; + } + } + + if (i != nlen) { + debug("%s: ERROR: unable to parse nonce\n", __func__); + free(nn); + return IRECV_E_UNKNOWN_ERROR; + } + + *nonce = nn; + *nonce_size = nlen; + + return IRECV_E_SUCCESS; +} + irecv_error_t irecv_send_exploit(irecv_client_t client) { if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; irecv_control_transfer(client, 0x21, 2, 0, 0, NULL, 0, USB_TIMEOUT); |