summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libirecovery.c53
-rw-r--r--src/libirecovery.h1
2 files changed, 54 insertions, 0 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c
index 374dcf0..a2d409d 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -917,6 +917,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 {
+ error("%s: ERROR: unexpected data in nonce result (%2s)\n", __func__, nonce_string+(i*2));
+ break;
+ }
+ }
+
+ if (i != nlen) {
+ error("%s: ERROR: unable to parse nonce\n");
+ 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);
diff --git a/src/libirecovery.h b/src/libirecovery.h
index 12e6698..b59a592 100644
--- a/src/libirecovery.h
+++ b/src/libirecovery.h
@@ -215,6 +215,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();