diff options
author | Nikias Bassen | 2013-11-18 18:01:16 +0100 |
---|---|---|
committer | Nikias Bassen | 2013-11-18 18:01:16 +0100 |
commit | e5bbb647163e69d4ac0cc09eecfe65eac0f63704 (patch) | |
tree | 14625a6173bad6ab8568e50c2e43ba1bf6655ba6 | |
parent | de4fc4c8d1d60d01d910dd2e0ae1305aab2131e9 (diff) | |
download | libirecovery-e5bbb647163e69d4ac0cc09eecfe65eac0f63704.tar.gz libirecovery-e5bbb647163e69d4ac0cc09eecfe65eac0f63704.tar.bz2 |
change irecv_get_nonce to a more general irecv_get_nonce_with_tag
-rw-r--r-- | include/libirecovery.h | 2 | ||||
-rw-r--r-- | src/libirecovery.c | 48 |
2 files changed, 42 insertions, 8 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h index daf1761..d34e0f2 100644 --- a/include/libirecovery.h +++ b/include/libirecovery.h @@ -127,7 +127,7 @@ irecv_error_t irecv_get_mode(irecv_client_t client, int* mode); 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); +irecv_error_t irecv_get_nonce_with_tag(irecv_client_t client, const char* tag, unsigned char** nonce, int* nonce_size); irecv_error_t irecv_get_srnm(irecv_client_t client, char* srnm); irecv_error_t irecv_get_imei(irecv_client_t client, char* imei); diff --git a/src/libirecovery.c b/src/libirecovery.c index 7ba2dd9..f189838 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c @@ -1310,11 +1310,15 @@ irecv_error_t irecv_get_imei(irecv_client_t client, char* imei) { return IRECV_E_SUCCESS; } -irecv_error_t irecv_get_nonce(irecv_client_t client, unsigned char** nonce, int* nonce_size) { +irecv_error_t irecv_get_nonce_with_tag(irecv_client_t client, const char* tag, unsigned char** nonce, int* nonce_size) { if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; - unsigned char buf[255]; + if (tag == NULL) { + return IRECV_E_INVALID_INPUT; + } + + char buf[255]; int len; *nonce = NULL; @@ -1327,15 +1331,45 @@ irecv_error_t irecv_get_nonce(irecv_client_t client, unsigned char** nonce, int* } buf[len] = 0; - debug("%s: buf='%s'\n", __func__, buf); + debug("%s: buf='%s' tag='%s'\n", __func__, buf, tag); + + int taglen = strlen(tag); + int nlen = 0; + char* nonce_string = NULL; + char* p = buf; + char* colon = NULL; + do { + colon = strchr(p, ':'); + if (!colon) + break; + if (colon-taglen < p) { + break; + } + char *space = strchr(colon, ' '); + if (strncmp(colon-taglen, tag, taglen) == 0) { + p = colon+1; + if (!space) { + nlen = strlen(p); + } else { + nlen = space-p; + } + nonce_string = p; + nlen/=2; + break; + } else { + if (!space) { + break; + } else { + p = space+1; + } + } + } while (colon); - char* nonce_string = strstr((char*)buf, "NONC:"); - if (nonce_string == NULL) { + if (nlen == 0) { + debug("%s: ERROR: couldn't find tag %s in string %s\n", __func__, tag, buf); 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; |