Commit 8333ca94 authored by Jonathan Beck's avatar Jonathan Beck

use new function signature and few bugfixes.

parent 86f61988
...@@ -42,9 +42,11 @@ extern "C" { ...@@ -42,9 +42,11 @@ extern "C" {
#define IPHONE_E_INVALID_CONF -7 #define IPHONE_E_INVALID_CONF -7
#define IPHONE_E_PAIRING_FAILED -8 #define IPHONE_E_PAIRING_FAILED -8
#define IPHONE_E_SSL_ERROR -9 #define IPHONE_E_SSL_ERROR -9
#define IPHONE_E_PLIST_ERROR -10
#define IPHONE_E_DICT_ERROR -11
//afc specific error //afc specific error
#define IPHONE_E_NO_SUCH_FILE -10 #define IPHONE_E_NO_SUCH_FILE -12
typedef short iphone_error_t; typedef short iphone_error_t;
......
...@@ -159,7 +159,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int ...@@ -159,7 +159,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int
return -1; return -1;
} }
memcpy(buffer+sizeof(AFCPacket), data, offset); memcpy(buffer+sizeof(AFCPacket), data, offset);
bytes = iphone_mux_send(client->connection, buffer, client->afc_packet->this_length); iphone_mux_send(client->connection, buffer, client->afc_packet->this_length, &bytes);
free(buffer); free(buffer);
if (bytes <= 0) { if (bytes <= 0) {
return bytes; return bytes;
...@@ -172,7 +172,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int ...@@ -172,7 +172,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int
fwrite(data+offset, 1, length-offset, stdout); fwrite(data+offset, 1, length-offset, stdout);
} }
bytes = iphone_mux_send(client->connection, data+offset, length-offset); iphone_mux_send(client->connection, data+offset, length-offset, &bytes);
return bytes; return bytes;
} else { } else {
if (debug) fprintf(stderr, "dispatch_AFC_packet doin things the old way\n"); if (debug) fprintf(stderr, "dispatch_AFC_packet doin things the old way\n");
...@@ -183,7 +183,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int ...@@ -183,7 +183,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int
if (length > 0) { memcpy(buffer+sizeof(AFCPacket), data, length); buffer[sizeof(AFCPacket)+length] = '\0'; } if (length > 0) { memcpy(buffer+sizeof(AFCPacket), data, length); buffer[sizeof(AFCPacket)+length] = '\0'; }
if (debug) fwrite(buffer, 1, client->afc_packet->this_length, stdout); if (debug) fwrite(buffer, 1, client->afc_packet->this_length, stdout);
if (debug) fprintf(stderr, "\n"); if (debug) fprintf(stderr, "\n");
bytes = iphone_mux_send(client->connection, buffer, client->afc_packet->this_length); iphone_mux_send(client->connection, buffer, client->afc_packet->this_length, &bytes);
if (buffer) { if (buffer) {
free(buffer); free(buffer);
...@@ -212,7 +212,7 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) { ...@@ -212,7 +212,7 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) {
int bytes = 0, recv_len = 0, current_count=0; int bytes = 0, recv_len = 0, current_count=0;
int retval = 0; int retval = 0;
bytes = iphone_mux_recv(client->connection, buffer, sizeof(AFCPacket) * 4); iphone_mux_recv(client->connection, buffer, sizeof(AFCPacket) * 4, &bytes);
if (bytes <= 0) { if (bytes <= 0) {
free(buffer); free(buffer);
fprintf(stderr, "Just didn't get enough.\n"); fprintf(stderr, "Just didn't get enough.\n");
...@@ -265,7 +265,7 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) { ...@@ -265,7 +265,7 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) {
buffer = (char*)malloc(sizeof(char) * (recv_len < MAXIMUM_PACKET_SIZE) ? recv_len : MAXIMUM_PACKET_SIZE); buffer = (char*)malloc(sizeof(char) * (recv_len < MAXIMUM_PACKET_SIZE) ? recv_len : MAXIMUM_PACKET_SIZE);
final_buffer = (char*)malloc(sizeof(char) * recv_len); final_buffer = (char*)malloc(sizeof(char) * recv_len);
while(current_count < recv_len){ while(current_count < recv_len){
bytes = iphone_mux_recv(client->connection, buffer, recv_len-current_count); iphone_mux_recv(client->connection, buffer, recv_len-current_count, &bytes);
if (debug) fprintf(stderr, "receive_AFC_data: still collecting packets\n"); if (debug) fprintf(stderr, "receive_AFC_data: still collecting packets\n");
if (bytes < 0) if (bytes < 0)
{ {
...@@ -331,7 +331,7 @@ iphone_error_t iphone_afc_get_dir_list ( iphone_afc_client_t client, const char ...@@ -331,7 +331,7 @@ iphone_error_t iphone_afc_get_dir_list ( iphone_afc_client_t client, const char
char *data = NULL, **list_loc = NULL; char *data = NULL, **list_loc = NULL;
iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
if (!client || !dir || !list) return IPHONE_E_INVALID_ARG; if (!client || !dir || !list || (list && *list)) return IPHONE_E_INVALID_ARG;
afc_lock(client); afc_lock(client);
...@@ -714,11 +714,11 @@ iphone_error_t iphone_afc_read_file ( iphone_afc_client_t client, iphone_afc_fil ...@@ -714,11 +714,11 @@ iphone_error_t iphone_afc_read_file ( iphone_afc_client_t client, iphone_afc_fil
// Receive the data // Receive the data
bytes_loc = receive_AFC_data(client, &input); bytes_loc = receive_AFC_data(client, &input);
if (debug) fprintf(stderr, "afc_read_file: bytes returned: %i\n", bytes_loc); if (debug) fprintf(stderr, "afc_read_file: bytes returned: %i\n", bytes_loc);
if (bytes < 0) { if (bytes_loc < 0) {
if (input) free(input); if (input) free(input);
afc_unlock(client); afc_unlock(client);
return IPHONE_E_NOT_ENOUGH_DATA; return IPHONE_E_NOT_ENOUGH_DATA;
} else if (bytes == 0) { } else if (bytes_loc == 0) {
if (input) free(input); if (input) free(input);
afc_unlock(client); afc_unlock(client);
*bytes = current_count; *bytes = current_count;
...@@ -756,7 +756,7 @@ iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_fi ...@@ -756,7 +756,7 @@ iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_fi
uint32 zero = 0, bytes_loc = 0, segments = (length / MAXIMUM_WRITE_SIZE), current_count = 0, i = 0; uint32 zero = 0, bytes_loc = 0, segments = (length / MAXIMUM_WRITE_SIZE), current_count = 0, i = 0;
char *out_buffer = NULL; char *out_buffer = NULL;
if (!client ||!client->afc_packet || !client->connection || !file || !bytes_loc) return IPHONE_E_INVALID_ARG; if (!client ||!client->afc_packet || !client->connection || !file || !bytes) return IPHONE_E_INVALID_ARG;
afc_lock(client); afc_lock(client);
...@@ -821,8 +821,8 @@ iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_fi ...@@ -821,8 +821,8 @@ iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, iphone_afc_fi
if (bytes_loc < 0) { if (bytes_loc < 0) {
if (debug) fprintf(stderr, "afc_write_file: uh oh?\n"); if (debug) fprintf(stderr, "afc_write_file: uh oh?\n");
} }
*bytes = current_count;
return IPHONE_E_UNKNOWN_ERROR; return IPHONE_E_SUCCESS;
} }
/** Closes a file on the phone. /** Closes a file on the phone.
......
...@@ -57,7 +57,7 @@ static int ifuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, ...@@ -57,7 +57,7 @@ static int ifuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
char **dirs; char **dirs;
iphone_afc_client_t afc = fuse_get_context()->private_data; iphone_afc_client_t afc = fuse_get_context()->private_data;
dirs = iphone_afc_get_dir_list(afc, path); iphone_afc_get_dir_list(afc, path, &dirs);
if(!dirs) if(!dirs)
return -ENOENT; return -ENOENT;
...@@ -119,8 +119,8 @@ static int ifuse_read(const char *path, char *buf, size_t size, off_t offset, ...@@ -119,8 +119,8 @@ static int ifuse_read(const char *path, char *buf, size_t size, off_t offset,
return -ENOENT; return -ENOENT;
} }
bytes = iphone_afc_seek_file(afc, file, offset); if (IPHONE_E_SUCCESS == iphone_afc_seek_file(afc, file, offset))
bytes = iphone_afc_read_file(afc, file, buf, size); iphone_afc_read_file(afc, file, buf, size, &bytes);
return bytes; return bytes;
} }
...@@ -134,8 +134,8 @@ static int ifuse_write(const char *path, const char *buf, size_t size, off_t off ...@@ -134,8 +134,8 @@ static int ifuse_write(const char *path, const char *buf, size_t size, off_t off
file = g_hash_table_lookup(file_handles, &(fi->fh)); file = g_hash_table_lookup(file_handles, &(fi->fh));
if (!file) return -ENOENT; if (!file) return -ENOENT;
bytes = iphone_afc_seek_file(afc, file, offset); if (IPHONE_E_SUCCESS == iphone_afc_seek_file(afc, file, offset))
bytes = iphone_afc_write_file(afc, file, buf, size); iphone_afc_write_file(afc, file, buf, size, &bytes);
return bytes; return bytes;
} }
...@@ -179,8 +179,7 @@ void *ifuse_init(struct fuse_conn_info *conn) { ...@@ -179,8 +179,7 @@ void *ifuse_init(struct fuse_conn_info *conn) {
return NULL; return NULL;
} }
port = iphone_lckd_start_service(control, "com.apple.afc"); if (IPHONE_E_SUCCESS == iphone_lckd_start_service(control, "com.apple.afc", &port) && !port) {
if (!port) {
iphone_lckd_free_client(control); iphone_lckd_free_client(control);
iphone_free_device(phone); iphone_free_device(phone);
fprintf(stderr, "Something went wrong when starting AFC."); fprintf(stderr, "Something went wrong when starting AFC.");
...@@ -206,9 +205,10 @@ int ifuse_flush(const char *path, struct fuse_file_info *fi) { ...@@ -206,9 +205,10 @@ int ifuse_flush(const char *path, struct fuse_file_info *fi) {
int ifuse_statfs(const char *path, struct statvfs *stats) { int ifuse_statfs(const char *path, struct statvfs *stats) {
iphone_afc_client_t afc = fuse_get_context()->private_data; iphone_afc_client_t afc = fuse_get_context()->private_data;
char **info_raw = iphone_afc_get_devinfo(afc); char **info_raw = NULL;
uint32_t totalspace = 0, freespace = 0, blocksize = 0, i = 0; uint32_t totalspace = 0, freespace = 0, blocksize = 0, i = 0;
iphone_afc_get_devinfo(afc, &info_raw);
if (!info_raw) return -ENOENT; if (!info_raw) return -ENOENT;
for (i = 0; info_raw[i]; i++) { for (i = 0; info_raw[i]; i++) {
......
...@@ -140,6 +140,7 @@ iphone_error_t iphone_free_device ( iphone_device_t device ) { ...@@ -140,6 +140,7 @@ iphone_error_t iphone_free_device ( iphone_device_t device ) {
if (device->buffer) { if (device->buffer) {
free(device->buffer); free(device->buffer);
}
if (device->device) { if (device->device) {
usb_release_interface(device->device, 1); usb_release_interface(device->device, 1);
usb_reset(device->device); usb_reset(device->device);
...@@ -147,7 +148,6 @@ iphone_error_t iphone_free_device ( iphone_device_t device ) { ...@@ -147,7 +148,6 @@ iphone_error_t iphone_free_device ( iphone_device_t device ) {
ret = IPHONE_E_SUCCESS; ret = IPHONE_E_SUCCESS;
} }
free(device); free(device);
}
return ret; return ret;
} }
......
This diff is collapsed.
...@@ -43,19 +43,17 @@ struct iphone_lckd_client_int { ...@@ -43,19 +43,17 @@ struct iphone_lckd_client_int {
char *lockdownd_generate_hostid(); char *lockdownd_generate_hostid();
iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone);
int lockdownd_hello(iphone_lckd_client_t control); iphone_error_t lockdownd_hello(iphone_lckd_client_t control);
int lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid);
int lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key); iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key);
int lockdownd_gen_pair_cert(char *public_key_b64, char **device_cert_b64, char **host_cert_b64, char **root_cert_b64); iphone_error_t lockdownd_gen_pair_cert(char *public_key_b64, char **device_cert_b64, char **host_cert_b64, char **root_cert_b64);
int lockdownd_pair_device(iphone_lckd_client_t control, char *public_key, char *host_id); iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *public_key, char *host_id);
int lockdownd_recv(iphone_lckd_client_t control, char **dump_data);
int lockdownd_send(iphone_lckd_client_t control, char *raw_data, uint32 length);
void lockdownd_close(iphone_lckd_client_t control); void lockdownd_close(iphone_lckd_client_t control);
// SSL functions // SSL functions
int lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID); iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID);
ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_t length); ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_t length);
ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length); ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length);
......
...@@ -56,27 +56,27 @@ int main(int argc, char *argv[]) { ...@@ -56,27 +56,27 @@ int main(int argc, char *argv[]) {
} }
char *uid = NULL; char *uid = NULL;
if (lockdownd_get_device_uid(control, &uid)) { if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) {
printf("DeviceUniqueID : %s\n", uid); printf("DeviceUniqueID : %s\n", uid);
free(uid); free(uid);
} }
port = iphone_lckd_start_service(control, "com.apple.afc"); iphone_lckd_start_service(control, "com.apple.afc", &port);
if (port) { if (port) {
iphone_afc_client_t afc = NULL; iphone_afc_client_t afc = NULL;
iphone_afc_new_client(phone, 3432, port, &afc); iphone_afc_new_client(phone, 3432, port, &afc);
if (afc) { if (afc) {
char **dirs; char **dirs = NULL;
dirs = iphone_afc_get_dir_list(afc, "/eafaedf"); iphone_afc_get_dir_list(afc, "/eafaedf", &dirs);
if (!dirs) dirs = iphone_afc_get_dir_list(afc, "/"); if (!dirs) iphone_afc_get_dir_list(afc, "/", &dirs);
printf("Directory time.\n"); printf("Directory time.\n");
for (i = 0; dirs[i]; i++) { for (i = 0; dirs[i]; i++) {
printf("/%s\n", dirs[i]); printf("/%s\n", dirs[i]);
} }
g_strfreev(dirs); g_strfreev(dirs);
dirs = iphone_afc_get_devinfo(afc); iphone_afc_get_devinfo(afc, &dirs);
if (dirs) { if (dirs) {
for (i = 0; dirs[i]; i+=2) { for (i = 0; dirs[i]; i+=2) {
printf("%s: %s\n", dirs[i], dirs[i+1]); printf("%s: %s\n", dirs[i], dirs[i+1]);
...@@ -90,7 +90,7 @@ int main(int argc, char *argv[]) { ...@@ -90,7 +90,7 @@ int main(int argc, char *argv[]) {
if (IPHONE_E_SUCCESS == iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ, &my_file) && my_file) { if (IPHONE_E_SUCCESS == iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ, &my_file) && my_file) {
printf("A file size: %i\n", stbuf.st_size); printf("A file size: %i\n", stbuf.st_size);
char *file_data = (char*)malloc(sizeof(char) * stbuf.st_size); char *file_data = (char*)malloc(sizeof(char) * stbuf.st_size);
bytes = iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size); iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes);
if (bytes >= 0) { if (bytes >= 0) {
printf("The file's data:\n"); printf("The file's data:\n");
fwrite(file_data, 1, bytes, stdout); fwrite(file_data, 1, bytes, stdout);
...@@ -103,7 +103,7 @@ int main(int argc, char *argv[]) { ...@@ -103,7 +103,7 @@ int main(int argc, char *argv[]) {
iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE, &my_file); iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE, &my_file);
if (my_file) { if (my_file) {
char *outdatafile = strdup("this is a bitchin text file\n"); char *outdatafile = strdup("this is a bitchin text file\n");
bytes = iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile)); iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes);
free(outdatafile); free(outdatafile);
if (bytes > 0) printf("Wrote a surprise. ;)\n"); if (bytes > 0) printf("Wrote a surprise. ;)\n");
else printf("I wanted to write a surprise, but... :(\n"); else printf("I wanted to write a surprise, but... :(\n");
...@@ -121,10 +121,9 @@ int main(int argc, char *argv[]) { ...@@ -121,10 +121,9 @@ int main(int argc, char *argv[]) {
printf("Seek & read\n"); printf("Seek & read\n");
iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_READ, &my_file); iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_READ, &my_file);
bytes = iphone_afc_seek_file(afc, my_file, 5); if (IPHONE_E_SUCCESS != iphone_afc_seek_file(afc, my_file, 5)) printf("WARN: SEEK DID NOT WORK\n");
if (bytes) printf("WARN: SEEK DID NOT WORK\n");
char *threeletterword = (char*)malloc(sizeof(char) * 5); char *threeletterword = (char*)malloc(sizeof(char) * 5);
bytes = iphone_afc_read_file(afc, my_file, threeletterword, 3); iphone_afc_read_file(afc, my_file, threeletterword, 3, &bytes);
threeletterword[3] = '\0'; threeletterword[3] = '\0';
if (bytes > 0) printf("Result: %s\n", threeletterword); if (bytes > 0) printf("Result: %s\n", threeletterword);
else printf("Couldn't read!\n"); else printf("Couldn't read!\n");
......
...@@ -250,7 +250,7 @@ iphone_error_t iphone_mux_send ( iphone_umux_client_t client, const char *data, ...@@ -250,7 +250,7 @@ iphone_error_t iphone_mux_send ( iphone_umux_client_t client, const char *data,
*sent_bytes = *sent_bytes - 28; // actual length sent. :/ *sent_bytes = *sent_bytes - 28; // actual length sent. :/
} }
return IPHONE_E_UNKNOWN_ERROR; return IPHONE_E_SUCCESS;
} }
/** This is a higher-level USBMuxTCP-like function /** This is a higher-level USBMuxTCP-like function
...@@ -371,6 +371,6 @@ iphone_error_t iphone_mux_recv ( iphone_umux_client_t client, char *data, uint32 ...@@ -371,6 +371,6 @@ iphone_error_t iphone_mux_recv ( iphone_umux_client_t client, char *data, uint32
// If we get to this point, 'tis probably bad. // If we get to this point, 'tis probably bad.
if (debug) printf("mux_recv: Heisenbug: bytes and datalen not matching up\n"); if (debug) printf("mux_recv: Heisenbug: bytes and datalen not matching up\n");
return -1; return IPHONE_E_UNKNOWN_ERROR;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment