diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/AFC.h | 2 | ||||
| -rw-r--r-- | src/ifuse.c | 4 | ||||
| -rw-r--r-- | src/initconf.c | 4 | ||||
| -rw-r--r-- | src/iphone.c | 128 |
4 files changed, 79 insertions, 59 deletions
| @@ -28,9 +28,7 @@ | |||
| 28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
| 29 | 29 | ||
| 30 | typedef struct { | 30 | typedef struct { |
| 31 | //const uint32 header1 = 0x36414643; // '6AFC' or 'CFA6' when sent ;) | ||
| 32 | uint32 header1, header2; | 31 | uint32 header1, header2; |
| 33 | //const uint32 header2 = 0x4141504C; // 'AAPL' or 'LPAA' when sent ;) | ||
| 34 | uint32 entire_length, unknown1, this_length, unknown2, packet_num, unknown3, operation, unknown4; | 32 | uint32 entire_length, unknown1, this_length, unknown2, packet_num, unknown3, operation, unknown4; |
| 35 | } AFCPacket; | 33 | } AFCPacket; |
| 36 | 34 | ||
diff --git a/src/ifuse.c b/src/ifuse.c index 6a24bad..4967112 100644 --- a/src/ifuse.c +++ b/src/ifuse.c | |||
| @@ -53,10 +53,8 @@ static int ifuse_getattr(const char *path, struct stat *stbuf) { | |||
| 53 | if (!file){ | 53 | if (!file){ |
| 54 | res = -ENOENT; | 54 | res = -ENOENT; |
| 55 | } else { | 55 | } else { |
| 56 | //stbuf->st_mode = file->type | 0444; // testing write access too now | ||
| 57 | stbuf->st_mode = file->type | 0644; // but we don't want anything on the iPhone executable, like, ever | 56 | stbuf->st_mode = file->type | 0644; // but we don't want anything on the iPhone executable, like, ever |
| 58 | stbuf->st_size = file->size; | 57 | stbuf->st_size = file->size; |
| 59 | //stbuf->st_nlink = 2; | ||
| 60 | } | 58 | } |
| 61 | 59 | ||
| 62 | return res; | 60 | return res; |
| @@ -98,8 +96,6 @@ static int ifuse_open(const char *path, struct fuse_file_info *fi) { | |||
| 98 | AFCFile *file; | 96 | AFCFile *file; |
| 99 | AFClient *afc = fuse_get_context()->private_data; | 97 | AFClient *afc = fuse_get_context()->private_data; |
| 100 | uint32 mode = 0; | 98 | uint32 mode = 0; |
| 101 | /*if((fi->flags & 3) != O_RDONLY) | ||
| 102 | return -EACCES;*/ // trying to test write access here | ||
| 103 | 99 | ||
| 104 | if ((fi->flags & 3) == O_RDWR || (fi->flags & 3) == O_WRONLY) { | 100 | if ((fi->flags & 3) == O_RDWR || (fi->flags & 3) == O_WRONLY) { |
| 105 | mode = AFC_FILE_READ; | 101 | mode = AFC_FILE_READ; |
diff --git a/src/initconf.c b/src/initconf.c index 0149ac9..795b4ac 100644 --- a/src/initconf.c +++ b/src/initconf.c | |||
| @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) { | |||
| 56 | gnutls_global_init(); | 56 | gnutls_global_init(); |
| 57 | 57 | ||
| 58 | size_t size; | 58 | size_t size; |
| 59 | char* host_id = NULL; //"29942970-207913891623273984" | 59 | char* host_id = NULL; |
| 60 | gnutls_x509_privkey_t root_privkey; | 60 | gnutls_x509_privkey_t root_privkey; |
| 61 | gnutls_x509_privkey_t host_privkey; | 61 | gnutls_x509_privkey_t host_privkey; |
| 62 | 62 | ||
| @@ -73,6 +73,7 @@ int main(int argc, char *argv[]) { | |||
| 73 | //TODO | 73 | //TODO |
| 74 | host_id = lockdownd_generate_hostid(); | 74 | host_id = lockdownd_generate_hostid(); |
| 75 | if (debug) printf("HostID: %s\n", host_id); | 75 | if (debug) printf("HostID: %s\n", host_id); |
| 76 | |||
| 76 | /* generate keys */ | 77 | /* generate keys */ |
| 77 | gnutls_x509_privkey_generate(root_privkey, GNUTLS_PK_RSA, 2048, 0); | 78 | gnutls_x509_privkey_generate(root_privkey, GNUTLS_PK_RSA, 2048, 0); |
| 78 | gnutls_x509_privkey_generate(host_privkey, GNUTLS_PK_RSA, 2048, 0); | 79 | gnutls_x509_privkey_generate(host_privkey, GNUTLS_PK_RSA, 2048, 0); |
| @@ -132,7 +133,6 @@ int main(int argc, char *argv[]) { | |||
| 132 | 133 | ||
| 133 | 134 | ||
| 134 | /* store values in config file */ | 135 | /* store values in config file */ |
| 135 | |||
| 136 | init_config_file(host_id, &root_key_pem, &host_key_pem, &root_cert_pem, &host_cert_pem); | 136 | init_config_file(host_id, &root_key_pem, &host_key_pem, &root_cert_pem, &host_cert_pem); |
| 137 | 137 | ||
| 138 | gnutls_free(root_key_pem.data); | 138 | gnutls_free(root_key_pem.data); |
diff --git a/src/iphone.c b/src/iphone.c index 558dd9a..104418f 100644 --- a/src/iphone.c +++ b/src/iphone.c | |||
| @@ -29,30 +29,36 @@ | |||
| 29 | 29 | ||
| 30 | extern int debug; | 30 | extern int debug; |
| 31 | 31 | ||
| 32 | /** | 32 | /** Gets a handle to an iPhone |
| 33 | * | 33 | * |
| 34 | * @return A structure with data on the first iPhone it finds. (Or NULL, on | 34 | * @return A structure with data on the first iPhone it finds. (Or NULL, on |
| 35 | * error) | 35 | * error) |
| 36 | */ | 36 | */ |
| 37 | iPhone *get_iPhone() { | 37 | iPhone *get_iPhone() { |
| 38 | iPhone *phone = (iPhone*)malloc(sizeof(iPhone)); | 38 | iPhone *phone = (iPhone*)malloc(sizeof(iPhone)); |
| 39 | usbmux_version_header *version = version_header(); | 39 | usbmux_version_header *version = version_header(); |
| 40 | struct usb_bus *bus, *busses; | ||
| 41 | struct usb_device *dev; | ||
| 40 | 42 | ||
| 41 | // initialize the struct | 43 | // Initialize the struct |
| 42 | phone->device = NULL; | 44 | phone->device = NULL; |
| 43 | phone->__device = NULL; | 45 | phone->__device = NULL; |
| 44 | phone->buffer = NULL; | 46 | phone->buffer = NULL; |
| 45 | 47 | ||
| 46 | // Initialize libusb. | 48 | // Initialize libusb |
| 47 | usb_init(); | 49 | usb_init(); |
| 48 | usb_find_busses(); | 50 | usb_find_busses(); |
| 49 | usb_find_devices(); | 51 | usb_find_devices(); |
| 50 | struct usb_bus *busses = usb_get_busses(), *bus; | 52 | busses = usb_get_busses(); |
| 51 | struct usb_device *dev; | ||
| 52 | 53 | ||
| 53 | for (bus = busses; bus; bus = bus->next) { | 54 | for (bus = busses; bus; bus = bus->next) { |
| 54 | for (dev = bus->devices; dev; dev = dev->next) { | 55 | for (dev = bus->devices; dev; dev = dev->next) { |
| 55 | if (dev->descriptor.idVendor == 0x05ac && (dev->descriptor.idProduct == 0x1290 || dev->descriptor.idProduct == 0x1291 || dev->descriptor.idProduct == 0x1292)) { | 56 | if (dev->descriptor.idVendor == 0x05ac && |
| 57 | (dev->descriptor.idProduct == 0x1290 || | ||
| 58 | dev->descriptor.idProduct == 0x1291 || | ||
| 59 | dev->descriptor.idProduct == 0x1292 | ||
| 60 | ) | ||
| 61 | ) { | ||
| 56 | phone->__device = dev; | 62 | phone->__device = dev; |
| 57 | phone->device = usb_open(phone->__device); | 63 | phone->device = usb_open(phone->__device); |
| 58 | usb_reset(phone->device); | 64 | usb_reset(phone->device); |
| @@ -60,12 +66,18 @@ iPhone *get_iPhone() { | |||
| 60 | } | 66 | } |
| 61 | } | 67 | } |
| 62 | 68 | ||
| 63 | phone->device = NULL; // :( sorry Daniel | 69 | phone->device = NULL; |
| 64 | phone->__device = NULL; // :( sorry Daniel | 70 | phone->__device = NULL; |
| 65 | 71 | ||
| 66 | for (bus = busses; bus; bus = bus->next) { // do it again as per libusb documentation | 72 | // Set the device configuration |
| 73 | for (bus = busses; bus; bus = bus->next) { | ||
| 67 | for (dev = bus->devices; dev; dev = dev->next) { | 74 | for (dev = bus->devices; dev; dev = dev->next) { |
| 68 | if (dev->descriptor.idVendor == 0x05ac && (dev->descriptor.idProduct == 0x1290 || dev->descriptor.idProduct == 0x1291 || dev->descriptor.idProduct == 0x1292)) { | 75 | if (dev->descriptor.idVendor == 0x05ac && |
| 76 | (dev->descriptor.idProduct == 0x1290 || | ||
| 77 | dev->descriptor.idProduct == 0x1291 || | ||
| 78 | dev->descriptor.idProduct == 0x1292 | ||
| 79 | ) | ||
| 80 | ) { | ||
| 69 | phone->__device = dev; | 81 | phone->__device = dev; |
| 70 | phone->device = usb_open(phone->__device); | 82 | phone->device = usb_open(phone->__device); |
| 71 | usb_set_configuration(phone->device, 3); | 83 | usb_set_configuration(phone->device, 3); |
| @@ -76,58 +88,73 @@ iPhone *get_iPhone() { | |||
| 76 | if (phone->__device && phone->device) break; | 88 | if (phone->__device && phone->device) break; |
| 77 | } | 89 | } |
| 78 | 90 | ||
| 79 | if (!phone->device || !phone->__device) { // nothing connected | 91 | // Check to see if we are connected |
| 92 | if (!phone->device || !phone->__device) { | ||
| 80 | free_iPhone(phone); | 93 | free_iPhone(phone); |
| 81 | if (debug) printf("get_iPhone(): iPhone not found\n"); | 94 | if (debug) fprintf(stderr, "get_iPhone(): iPhone not found\n"); |
| 82 | return NULL; | 95 | return NULL; |
| 83 | } | 96 | } |
| 84 | 97 | ||
| 85 | // Okay, initialize the phone now. | 98 | // Send the version command to the phone |
| 86 | int bytes = 0; | 99 | int bytes = 0; |
| 87 | bytes = usb_bulk_write(phone->device, BULKOUT, (char*)version, sizeof(*version), 800); | 100 | bytes = usb_bulk_write(phone->device, BULKOUT, (char*)version, sizeof(*version), 800); |
| 88 | if (bytes < 20 && debug) { | 101 | if (bytes < 20 && debug) { |
| 89 | printf("get_iPhone(): libusb did NOT send enough!\n"); | 102 | fprintf(stderr, "get_iPhone(): libusb did NOT send enough!\n"); |
| 90 | if (bytes < 0) { | 103 | if (bytes < 0) { |
| 91 | printf("get_iPhone(): libusb gave me the error %d: %s (%s)\n", | 104 | fprintf(stderr, "get_iPhone(): libusb gave me the error %d: %s (%s)\n", |
| 92 | bytes, usb_strerror(), strerror(-bytes)); | 105 | bytes, usb_strerror(), strerror(-bytes)); |
| 93 | } | 106 | } |
| 94 | } | 107 | } |
| 108 | |||
| 109 | // Read the phone's response | ||
| 95 | bytes = usb_bulk_read(phone->device, BULKIN, (char*)version, sizeof(*version), 800); | 110 | bytes = usb_bulk_read(phone->device, BULKIN, (char*)version, sizeof(*version), 800); |
| 111 | |||
| 112 | // Check for bad response | ||
| 96 | if (bytes < 20) { | 113 | if (bytes < 20) { |
| 97 | free_iPhone(phone); | 114 | free_iPhone(phone); |
| 98 | if (debug) printf("get_iPhone(): Invalid version message -- header too short.\n"); | 115 | free(version); |
| 99 | if (debug && bytes < 0) printf("get_iPhone(): libusb error message %d: %s (%s)\n", bytes, usb_strerror(), strerror(-bytes)); | 116 | if (debug) fprintf(stderr, "get_iPhone(): Invalid version message -- header too short.\n"); |
| 117 | if (debug && bytes < 0) fprintf(stderr, "get_iPhone(): libusb error message %d: %s (%s)\n", | ||
| 118 | bytes, usb_strerror(), strerror(-bytes)); | ||
| 119 | return NULL; | ||
| 120 | } | ||
| 121 | |||
| 122 | // Check for correct version | ||
| 123 | if (ntohl(version->major) == 1 && ntohl(version->minor) == 0) { | ||
| 124 | // We're all ready to roll. | ||
| 125 | fprintf(stderr, "get_iPhone() success\n"); | ||
| 126 | free(version); | ||
| 127 | return phone; | ||
| 128 | } else { | ||
| 129 | // Bad header | ||
| 130 | free_iPhone(phone); | ||
| 131 | free(version); | ||
| 132 | if (debug) fprintf(stderr, "get_iPhone(): Received a bad header/invalid version number."); | ||
| 100 | return NULL; | 133 | return NULL; |
| 101 | } else { | ||
| 102 | if (ntohl(version->major) == 1 && ntohl(version->minor) == 0) { | ||
| 103 | // We're all ready to roll. | ||
| 104 | printf("get_iPhone() success\n"); | ||
| 105 | return phone; | ||
| 106 | } else { // BAD HEADER | ||
| 107 | free_iPhone(phone); | ||
| 108 | if (debug) printf("get_iPhone(): Received a bad header/invalid version number."); | ||
| 109 | return NULL; | ||
| 110 | } | ||
| 111 | } | 134 | } |
| 112 | 135 | ||
| 113 | if (debug) printf("get_iPhone(): Unknown error.\n"); | 136 | |
| 114 | return NULL; // if it got to this point it's gotta be bad | 137 | // If it got to this point it's gotta be bad |
| 138 | if (debug) fprintf(stderr, "get_iPhone(): Unknown error.\n"); | ||
| 139 | free_iPhone(phone); | ||
| 140 | free(version); | ||
| 141 | return NULL; | ||
| 115 | } | 142 | } |
| 116 | 143 | ||
| 117 | /** Cleans up an iPhone structure, then frees the structure itself. | 144 | /** Cleans up an iPhone structure, then frees the structure itself. |
| 118 | * This is a library-level function; deals directly with the iPhone to tear | 145 | * This is a library-level function; deals directly with the iPhone to tear |
| 119 | * down relations, but otherwise is mostly internal. | 146 | * down relations, but otherwise is mostly internal. |
| 120 | * | 147 | * |
| 121 | * @param victim A pointer to an iPhone structure. | 148 | * @param phone A pointer to an iPhone structure. |
| 122 | */ | 149 | */ |
| 123 | void free_iPhone(iPhone *victim) { | 150 | void free_iPhone(iPhone *phone) { |
| 124 | if (victim->buffer) free(victim->buffer); | 151 | if (phone->buffer) free(phone->buffer); |
| 125 | if (victim->device) { | 152 | if (phone->device) { |
| 126 | usb_release_interface(victim->device, 1); | 153 | usb_release_interface(phone->device, 1); |
| 127 | usb_reset(victim->device); | 154 | usb_reset(phone->device); |
| 128 | usb_close(victim->device); | 155 | usb_close(phone->device); |
| 129 | } | 156 | } |
| 130 | free(victim); | 157 | free(phone); |
| 131 | } | 158 | } |
| 132 | 159 | ||
| 133 | /** Sends data to the phone | 160 | /** Sends data to the phone |
| @@ -139,16 +166,15 @@ void free_iPhone(iPhone *victim) { | |||
| 139 | * @return The number of bytes sent, or -1 on error or something. | 166 | * @return The number of bytes sent, or -1 on error or something. |
| 140 | */ | 167 | */ |
| 141 | int send_to_phone(iPhone *phone, char *data, int datalen) { | 168 | int send_to_phone(iPhone *phone, char *data, int datalen) { |
| 142 | if (!phone) return -1; | ||
| 143 | int bytes = 0; | 169 | int bytes = 0; |
| 144 | // it may die here | 170 | |
| 145 | if (debug) printf("dying here?\ndatalen = %i\ndata = %p\n", datalen, data); | 171 | if (!phone) return -1; |
| 172 | if (debug) fprintf(stderr, "send_to_phone: Attempting to send datalen = %i data = %p\n", datalen, data); | ||
| 146 | 173 | ||
| 147 | bytes = usb_bulk_write(phone->device, BULKOUT, data, datalen, 800); | 174 | bytes = usb_bulk_write(phone->device, BULKOUT, data, datalen, 800); |
| 148 | if (debug) printf("noooo...?\n"); | ||
| 149 | if (bytes < datalen) { | 175 | if (bytes < datalen) { |
| 150 | if(debug && bytes < 0) | 176 | if(debug && bytes < 0) |
| 151 | printf("send_to_iphone(): libusb gave me the error %d: %s - %s\n", bytes, usb_strerror(), strerror(-bytes)); | 177 | fprintf(stderr, "send_to_iphone(): libusb gave me the error %d: %s - %s\n", bytes, usb_strerror(), strerror(-bytes)); |
| 152 | return -1; | 178 | return -1; |
| 153 | } else { | 179 | } else { |
| 154 | return bytes; | 180 | return bytes; |
| @@ -157,8 +183,7 @@ int send_to_phone(iPhone *phone, char *data, int datalen) { | |||
| 157 | return -1; | 183 | return -1; |
| 158 | } | 184 | } |
| 159 | 185 | ||
| 160 | /** | 186 | /** This function is a low-level (i.e. direct to iPhone) function. |
| 161 | * This function is a low-level (i.e. direct to iPhone) function. | ||
| 162 | * | 187 | * |
| 163 | * @param phone The iPhone to receive data from | 188 | * @param phone The iPhone to receive data from |
| 164 | * @param data Where to put data read | 189 | * @param data Where to put data read |
| @@ -167,15 +192,16 @@ int send_to_phone(iPhone *phone, char *data, int datalen) { | |||
| 167 | * @return How many bytes were read in, or -1 on error. | 192 | * @return How many bytes were read in, or -1 on error. |
| 168 | */ | 193 | */ |
| 169 | int recv_from_phone(iPhone *phone, char *data, int datalen) { | 194 | int recv_from_phone(iPhone *phone, char *data, int datalen) { |
| 170 | if (!phone) return -1; | ||
| 171 | int bytes = 0; | 195 | int bytes = 0; |
| 172 | if (debug) printf("recv_from_phone(): attempting to receive %i bytes\n", datalen); | 196 | |
| 197 | if (!phone) return -1; | ||
| 198 | if (debug) fprintf(stderr, "recv_from_phone(): attempting to receive %i bytes\n", datalen); | ||
| 199 | |||
| 173 | bytes = usb_bulk_read(phone->device, BULKIN, data, datalen, 3500); | 200 | bytes = usb_bulk_read(phone->device, BULKIN, data, datalen, 3500); |
| 174 | if(bytes < 0) | 201 | if (bytes < 0) { |
| 175 | { | 202 | if(debug) fprintf(stderr, "recv_from_phone(): libusb gave me the error %d: %s (%s)\n", bytes, usb_strerror(), strerror(-bytes)); |
| 176 | if(debug) printf("recv_from_phone(): libusb gave me the error %d: %s (%s)\n", bytes, usb_strerror(), strerror(-bytes)); | ||
| 177 | return -1; | 203 | return -1; |
| 178 | } | 204 | } |
| 205 | |||
| 179 | return bytes; | 206 | return bytes; |
| 180 | } | 207 | } |
| 181 | |||
