diff options
| author | 2011-03-09 20:14:12 +0100 | |
|---|---|---|
| committer | 2011-03-09 20:14:12 +0100 | |
| commit | ee84c231a361ccb85f9eebc40a4c2e1551bcf010 (patch) | |
| tree | e1706dd7100b2ce827e1f7802f697f5af2799682 | |
| parent | 95fb4802fe4d76d3ed76a77197ec48ad51f28deb (diff) | |
| download | libirecovery-ee84c231a361ccb85f9eebc40a4c2e1551bcf010.tar.gz libirecovery-ee84c231a361ccb85f9eebc40a4c2e1551bcf010.tar.bz2 | |
Added irecv_get_srnm (serial number) and irecv_get_imei (imei) to libirecovery and /deviceinfo to the irecovery shell which displays basic device information.
| -rw-r--r-- | irecovery.c | 34 | ||||
| -rw-r--r-- | libirecovery.c | 43 |
2 files changed, 75 insertions, 2 deletions
diff --git a/irecovery.c b/irecovery.c index 40e6021..a7d6429 100644 --- a/irecovery.c +++ b/irecovery.c | |||
| @@ -46,6 +46,7 @@ void shell_usage() { | |||
| 46 | printf("Usage:\n"); | 46 | printf("Usage:\n"); |
| 47 | printf("\t/upload <file>\tSend file to client.\n"); | 47 | printf("\t/upload <file>\tSend file to client.\n"); |
| 48 | printf("\t/exploit [file]\tSend usb exploit with optional payload\n"); | 48 | printf("\t/exploit [file]\tSend usb exploit with optional payload\n"); |
| 49 | printf("\t/deviceinfo\tShow device information (ECID, IMEI, etc.)\n"); | ||
| 49 | printf("\t/help\t\tShow this help.\n"); | 50 | printf("\t/help\t\tShow this help.\n"); |
| 50 | printf("\t/exit\t\tExit interactive shell.\n"); | 51 | printf("\t/exit\t\tExit interactive shell.\n"); |
| 51 | } | 52 | } |
| @@ -70,6 +71,38 @@ void parse_command(irecv_client_t client, unsigned char* command, unsigned int s | |||
| 70 | } | 71 | } |
| 71 | } else | 72 | } else |
| 72 | 73 | ||
| 74 | if (!strcmp(cmd, "/deviceinfo")) { | ||
| 75 | int ret; | ||
| 76 | unsigned int cpid, bdid; | ||
| 77 | unsigned long long ecid; | ||
| 78 | unsigned char srnm[12], imei[15], bt[15]; | ||
| 79 | |||
| 80 | ret = irecv_get_cpid(client, &cpid); | ||
| 81 | if(ret == IRECV_E_SUCCESS) { | ||
| 82 | printf("CPID: %d\n", cpid); | ||
| 83 | } | ||
| 84 | |||
| 85 | ret = irecv_get_bdid(client, &bdid); | ||
| 86 | if(ret == IRECV_E_SUCCESS) { | ||
| 87 | printf("BDID: %d\n", bdid); | ||
| 88 | } | ||
| 89 | |||
| 90 | ret = irecv_get_ecid(client, &ecid); | ||
| 91 | if(ret == IRECV_E_SUCCESS) { | ||
| 92 | printf("ECID: %lld\n", ecid); | ||
| 93 | } | ||
| 94 | |||
| 95 | ret = irecv_get_srnm(client, srnm); | ||
| 96 | if(ret == IRECV_E_SUCCESS) { | ||
| 97 | printf("SRNM: %s\n", srnm); | ||
| 98 | } | ||
| 99 | |||
| 100 | ret = irecv_get_imei(client, imei); | ||
| 101 | if(ret == IRECV_E_SUCCESS) { | ||
| 102 | printf("IMEI: %s\n", imei); | ||
| 103 | } | ||
| 104 | } else | ||
| 105 | |||
| 73 | if (!strcmp(cmd, "/exploit")) { | 106 | if (!strcmp(cmd, "/exploit")) { |
| 74 | char* filename = strtok(NULL, " "); | 107 | char* filename = strtok(NULL, " "); |
| 75 | debug("Sending exploit %s\n", filename); | 108 | debug("Sending exploit %s\n", filename); |
| @@ -109,6 +142,7 @@ void init_shell(irecv_client_t client) { | |||
| 109 | irecv_event_subscribe(client, IRECV_POSTCOMMAND, &postcommand_cb, NULL); | 142 | irecv_event_subscribe(client, IRECV_POSTCOMMAND, &postcommand_cb, NULL); |
| 110 | while (!quit) { | 143 | while (!quit) { |
| 111 | error = irecv_receive(client); | 144 | error = irecv_receive(client); |
| 145 | |||
| 112 | if (error != IRECV_E_SUCCESS) { | 146 | if (error != IRECV_E_SUCCESS) { |
| 113 | debug("%s\n", irecv_strerror(error)); | 147 | debug("%s\n", irecv_strerror(error)); |
| 114 | break; | 148 | break; |
diff --git a/libirecovery.c b/libirecovery.c index 84c7b6f..540e01c 100644 --- a/libirecovery.c +++ b/libirecovery.c | |||
| @@ -844,7 +844,7 @@ irecv_error_t irecv_get_cpid(irecv_client_t client, unsigned int* cpid) { | |||
| 844 | 844 | ||
| 845 | irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid) { | 845 | irecv_error_t irecv_get_bdid(irecv_client_t client, unsigned int* bdid) { |
| 846 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; | 846 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; |
| 847 | 847 | ||
| 848 | char* bdid_string = strstr(client->serial, "BDID:"); | 848 | char* bdid_string = strstr(client->serial, "BDID:"); |
| 849 | if (bdid_string == NULL) { | 849 | if (bdid_string == NULL) { |
| 850 | *bdid = 0; | 850 | *bdid = 0; |
| @@ -868,6 +868,45 @@ irecv_error_t irecv_get_ecid(irecv_client_t client, unsigned long long* ecid) { | |||
| 868 | return IRECV_E_SUCCESS; | 868 | return IRECV_E_SUCCESS; |
| 869 | } | 869 | } |
| 870 | 870 | ||
| 871 | irecv_error_t irecv_get_srnm(irecv_client_t client, unsigned char* srnm) { | ||
| 872 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; | ||
| 873 | |||
| 874 | char* srnmp; | ||
| 875 | char* srnm_string = strstr(client->serial, "SRNM:["); | ||
| 876 | if(srnm_string == NULL) { | ||
| 877 | srnm = NULL; | ||
| 878 | return IRECV_E_UNKNOWN_ERROR; | ||
| 879 | } | ||
| 880 | |||
| 881 | sscanf(srnm_string, "SRNM:[%s]", srnm); | ||
| 882 | srnmp = strrchr(srnm, ']'); | ||
| 883 | if(srnmp != NULL) { | ||
| 884 | *srnmp = '\0'; | ||
| 885 | } | ||
| 886 | |||
| 887 | return IRECV_E_SUCCESS; | ||
| 888 | } | ||
| 889 | |||
| 890 | irecv_error_t irecv_get_imei(irecv_client_t client, unsigned char* imei) { | ||
| 891 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; | ||
| 892 | |||
| 893 | char* imeip; | ||
| 894 | char* imei_string = strstr(client->serial, "IMEI:["); | ||
| 895 | if (imei_string == NULL) { | ||
| 896 | *imei = 0; | ||
| 897 | return IRECV_E_UNKNOWN_ERROR; | ||
| 898 | } | ||
| 899 | |||
| 900 | |||
| 901 | sscanf(imei_string, "IMEI:[%s]", imei); | ||
| 902 | imeip = strrchr(imei, ']'); | ||
| 903 | if(imeip != NULL) { | ||
| 904 | *imeip = '\0'; | ||
| 905 | } | ||
| 906 | |||
| 907 | return IRECV_E_SUCCESS; | ||
| 908 | } | ||
| 909 | |||
| 871 | irecv_error_t irecv_send_exploit(irecv_client_t client) { | 910 | irecv_error_t irecv_send_exploit(irecv_client_t client) { |
| 872 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; | 911 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; |
| 873 | irecv_control_transfer(client, 0x21, 2, 0, 0, NULL, 0, 1000); | 912 | irecv_control_transfer(client, 0x21, 2, 0, 0, NULL, 0, 1000); |
| @@ -877,7 +916,7 @@ irecv_error_t irecv_send_exploit(irecv_client_t client) { | |||
| 877 | irecv_error_t irecv_execute_script(irecv_client_t client, const char* filename) { | 916 | irecv_error_t irecv_execute_script(irecv_client_t client, const char* filename) { |
| 878 | irecv_error_t error = IRECV_E_SUCCESS; | 917 | irecv_error_t error = IRECV_E_SUCCESS; |
| 879 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; | 918 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; |
| 880 | 919 | ||
| 881 | char* file_data = NULL; | 920 | char* file_data = NULL; |
| 882 | unsigned int file_size = 0; | 921 | unsigned int file_size = 0; |
| 883 | if(irecv_read_file(filename, &file_data, &file_size) < 0) { | 922 | if(irecv_read_file(filename, &file_data, &file_size) < 0) { |
