diff options
| author | 2008-08-25 23:25:56 +0200 | |
|---|---|---|
| committer | 2008-08-31 19:32:27 +0200 | |
| commit | 6ac4ceb4c6ee63c279f4841381a3eb09598f3517 (patch) | |
| tree | 37de86e9d99a56c2e4ef1e7b5db28bd252cd4a39 | |
| parent | c042f7ca2731fa5c8a5aa13789f5901ae5a3af7a (diff) | |
| download | libimobiledevice-6ac4ceb4c6ee63c279f4841381a3eb09598f3517.tar.gz libimobiledevice-6ac4ceb4c6ee63c279f4841381a3eb09598f3517.tar.bz2 | |
migrate main.c
| -rw-r--r-- | include/libiphone/libiphone.h | 11 | ||||
| -rw-r--r-- | src/AFC.c | 2 | ||||
| -rw-r--r-- | src/AFC.h | 11 | ||||
| -rw-r--r-- | src/ifuse.c | 20 | ||||
| -rw-r--r-- | src/main.c | 68 |
5 files changed, 48 insertions, 64 deletions
diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 89b8529..768ff21 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h | |||
| @@ -46,6 +46,17 @@ extern "C" { | |||
| 46 | //afc specific error | 46 | //afc specific error |
| 47 | #define IPHONE_E_NO_SUCH_FILE -10 | 47 | #define IPHONE_E_NO_SUCH_FILE -10 |
| 48 | 48 | ||
| 49 | enum { | ||
| 50 | AFC_FILE_READ = 0x00000002, // seems to be able to read and write files | ||
| 51 | AFC_FILE_WRITE = 0x00000003, // writes and creates a file, blanks it out, etc. | ||
| 52 | AFC_FILE_RW = 0x00000005, // seems to do the same as 2. Might even create the file. | ||
| 53 | AFC_FILE_OP4 = 0x00000004, // no idea -- appears to be "write" -- clears file beforehand like 3 | ||
| 54 | AFC_FILE_OP6 = 0x00000006, // no idea yet -- appears to be the same as 5. | ||
| 55 | AFC_FILE_OP1 = 0x00000001, // no idea juuust yet... probably read. | ||
| 56 | AFC_FILE_OP0 = 0x00000000, | ||
| 57 | AFC_FILE_OP10 = 0x0000000a | ||
| 58 | }; | ||
| 59 | |||
| 49 | struct iphone_device_int; | 60 | struct iphone_device_int; |
| 50 | typedef struct iphone_device_int *iphone_device_t; | 61 | typedef struct iphone_device_int *iphone_device_t; |
| 51 | 62 | ||
| @@ -596,7 +596,7 @@ int iphone_afc_get_file_attr ( iphone_afc_client_t client, const char *filename, | |||
| 596 | if (!file){ | 596 | if (!file){ |
| 597 | ret = IPHONE_E_NO_SUCH_FILE; | 597 | ret = IPHONE_E_NO_SUCH_FILE; |
| 598 | } else { | 598 | } else { |
| 599 | stbuf->st_mode = file->type | 0644; // but we don't want anything on the iPhone executable, like, ever | 599 | stbuf->st_mode = file->type | (S_ISDIR(file->type) ? 0755 : 0644); |
| 600 | stbuf->st_size = file->size; | 600 | stbuf->st_size = file->size; |
| 601 | stbuf->st_blksize = 2048; // FIXME: Is this the actual block size used on the iPhone? | 601 | stbuf->st_blksize = 2048; // FIXME: Is this the actual block size used on the iPhone? |
| 602 | stbuf->st_blocks = file->blocks; | 602 | stbuf->st_blocks = file->blocks; |
| @@ -52,16 +52,7 @@ struct iphone_afc_file_int { | |||
| 52 | uint32 filehandle, blocks, size, type; | 52 | uint32 filehandle, blocks, size, type; |
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | enum { | 55 | |
| 56 | AFC_FILE_READ = 0x00000002, // seems to be able to read and write files | ||
| 57 | AFC_FILE_WRITE = 0x00000003, // writes and creates a file, blanks it out, etc. | ||
| 58 | AFC_FILE_RW = 0x00000005, // seems to do the same as 2. Might even create the file. | ||
| 59 | AFC_FILE_OP4 = 0x00000004, // no idea -- appears to be "write" -- clears file beforehand like 3 | ||
| 60 | AFC_FILE_OP6 = 0x00000006, // no idea yet -- appears to be the same as 5. | ||
| 61 | AFC_FILE_OP1 = 0x00000001, // no idea juuust yet... probably read. | ||
| 62 | AFC_FILE_OP0 = 0x00000000, | ||
| 63 | AFC_FILE_OP10 = 0x0000000a | ||
| 64 | }; | ||
| 65 | 56 | ||
| 66 | enum { | 57 | enum { |
| 67 | AFC_ERROR = 0x00000001, | 58 | AFC_ERROR = 0x00000001, |
diff --git a/src/ifuse.c b/src/ifuse.c index 7672bb9..cc2072f 100644 --- a/src/ifuse.c +++ b/src/ifuse.c | |||
| @@ -42,8 +42,8 @@ | |||
| 42 | GHashTable *file_handles; | 42 | GHashTable *file_handles; |
| 43 | int fh_index = 0; | 43 | int fh_index = 0; |
| 44 | 44 | ||
| 45 | iPhone *phone = NULL; | 45 | iphone_device_t phone = NULL; |
| 46 | lockdownd_client *control = NULL; | 46 | iphone_lckd_client_t control = NULL; |
| 47 | 47 | ||
| 48 | int debug = 0; | 48 | int debug = 0; |
| 49 | 49 | ||
| @@ -52,22 +52,6 @@ static int ifuse_getattr(const char *path, struct stat *stbuf) { | |||
| 52 | AFCFile *file; | 52 | AFCFile *file; |
| 53 | AFClient *afc = fuse_get_context()->private_data; | 53 | AFClient *afc = fuse_get_context()->private_data; |
| 54 | 54 | ||
| 55 | memset(stbuf, 0, sizeof(struct stat)); | ||
| 56 | file = afc_get_file_info(afc, path); | ||
| 57 | if (!file){ | ||
| 58 | res = -ENOENT; | ||
| 59 | } else { | ||
| 60 | stbuf->st_mode = file->type | (S_ISDIR(file->type) ? 0755 : 0644); | ||
| 61 | stbuf->st_size = file->size; | ||
| 62 | stbuf->st_blksize = 2048; // FIXME: Is this the actual block size used on the iPhone? | ||
| 63 | stbuf->st_blocks = file->blocks; | ||
| 64 | stbuf->st_uid = getuid(); | ||
| 65 | stbuf->st_gid = getgid(); | ||
| 66 | |||
| 67 | afc_close_file(afc,file); | ||
| 68 | free(file); | ||
| 69 | } | ||
| 70 | |||
| 71 | return res; | 55 | return res; |
| 72 | } | 56 | } |
| 73 | 57 | ||
| @@ -29,17 +29,15 @@ | |||
| 29 | 29 | ||
| 30 | #include <libxml/parser.h> | 30 | #include <libxml/parser.h> |
| 31 | #include <libxml/tree.h> | 31 | #include <libxml/tree.h> |
| 32 | #include "plist.h" | 32 | |
| 33 | #include "lockdown.h" | 33 | #include <libiphone/libiphone.h> |
| 34 | #include "AFC.h" | ||
| 35 | #include "userpref.h" | ||
| 36 | 34 | ||
| 37 | int debug = 1; | 35 | int debug = 1; |
| 38 | 36 | ||
| 39 | int main(int argc, char *argv[]) { | 37 | int main(int argc, char *argv[]) { |
| 40 | int bytes = 0, port = 0, i = 0; | 38 | int bytes = 0, port = 0, i = 0; |
| 41 | lockdownd_client *control = NULL; | 39 | iphone_lckd_client_t control = NULL; |
| 42 | iPhone *phone = get_iPhone(); | 40 | iphone_device_t phone = NULL; |
| 43 | 41 | ||
| 44 | if (argc > 1 && !strcasecmp(argv[1], "--debug")){ | 42 | if (argc > 1 && !strcasecmp(argv[1], "--debug")){ |
| 45 | debug = 1; | 43 | debug = 1; |
| @@ -47,13 +45,13 @@ int main(int argc, char *argv[]) { | |||
| 47 | debug = 0; | 45 | debug = 0; |
| 48 | } | 46 | } |
| 49 | 47 | ||
| 50 | if (!phone) { | 48 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { |
| 51 | printf("No iPhone found, is it plugged in?\n"); | 49 | printf("No iPhone found, is it plugged in?\n"); |
| 52 | return -1; | 50 | return -1; |
| 53 | } | 51 | } |
| 54 | 52 | ||
| 55 | if (!lockdownd_init(phone, &control)){ | 53 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)){ |
| 56 | free_iPhone(phone); | 54 | iphone_free_device(phone); |
| 57 | return -1; | 55 | return -1; |
| 58 | } | 56 | } |
| 59 | 57 | ||
| @@ -63,21 +61,22 @@ int main(int argc, char *argv[]) { | |||
| 63 | free(uid); | 61 | free(uid); |
| 64 | } | 62 | } |
| 65 | 63 | ||
| 66 | port = lockdownd_start_service(control, "com.apple.afc"); | 64 | port = iphone_lckd_start_service(control, "com.apple.afc"); |
| 67 | 65 | ||
| 68 | if (port) { | 66 | if (port) { |
| 69 | AFClient *afc = afc_connect(phone, 3432, port); | 67 | iphone_afc_client_t afc = NULL; |
| 68 | iphone_afc_new_client(phone, 3432, port, &afc); | ||
| 70 | if (afc) { | 69 | if (afc) { |
| 71 | char **dirs; | 70 | char **dirs; |
| 72 | dirs = afc_get_dir_list(afc, "/eafaedf"); | 71 | dirs = iphone_afc_get_dir_list(afc, "/eafaedf"); |
| 73 | if (!dirs) dirs = afc_get_dir_list(afc, "/"); | 72 | if (!dirs) dirs = iphone_afc_get_dir_list(afc, "/"); |
| 74 | printf("Directory time.\n"); | 73 | printf("Directory time.\n"); |
| 75 | for (i = 0; dirs[i]; i++) { | 74 | for (i = 0; dirs[i]; i++) { |
| 76 | printf("/%s\n", dirs[i]); | 75 | printf("/%s\n", dirs[i]); |
| 77 | } | 76 | } |
| 78 | 77 | ||
| 79 | g_strfreev(dirs); | 78 | g_strfreev(dirs); |
| 80 | dirs = afc_get_devinfo(afc); | 79 | dirs = iphone_afc_get_devinfo(afc); |
| 81 | if (dirs) { | 80 | if (dirs) { |
| 82 | for (i = 0; dirs[i]; i+=2) { | 81 | for (i = 0; dirs[i]; i+=2) { |
| 83 | printf("%s: %s\n", dirs[i], dirs[i+1]); | 82 | printf("%s: %s\n", dirs[i], dirs[i+1]); |
| @@ -85,64 +84,63 @@ int main(int argc, char *argv[]) { | |||
| 85 | } | 84 | } |
| 86 | g_strfreev(dirs); | 85 | g_strfreev(dirs); |
| 87 | 86 | ||
| 88 | AFCFile *my_file = afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ); | 87 | iphone_afc_file_t my_file = NULL; |
| 89 | if (my_file) { | 88 | struct stat stbuf; |
| 90 | printf("A file size: %i\n", my_file->size); | 89 | iphone_afc_get_file_attr ( afc, "/iTunesOnTheGoPlaylist.plist", &stbuf ); |
| 91 | char *file_data = (char*)malloc(sizeof(char) * my_file->size); | 90 | if (IPHONE_E_SUCCESS == iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ, &my_file) && my_file) { |
| 92 | bytes = afc_read_file(afc, my_file, file_data, my_file->size); | 91 | printf("A file size: %i\n", stbuf.st_size); |
| 92 | char *file_data = (char*)malloc(sizeof(char) * stbuf.st_size); | ||
| 93 | bytes = iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size); | ||
| 93 | if (bytes >= 0) { | 94 | if (bytes >= 0) { |
| 94 | printf("The file's data:\n"); | 95 | printf("The file's data:\n"); |
| 95 | fwrite(file_data, 1, bytes, stdout); | 96 | fwrite(file_data, 1, bytes, stdout); |
| 96 | } | 97 | } |
| 97 | printf("\nClosing my file.\n"); | 98 | printf("\nClosing my file.\n"); |
| 98 | afc_close_file(afc, my_file); | 99 | iphone_afc_close_file(afc, my_file); |
| 99 | free(my_file); | ||
| 100 | free(file_data); | 100 | free(file_data); |
| 101 | } else printf("couldn't open a file\n"); | 101 | } else printf("couldn't open a file\n"); |
| 102 | 102 | ||
| 103 | my_file = afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE); | 103 | iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE, &my_file); |
| 104 | if (my_file) { | 104 | if (my_file) { |
| 105 | char *outdatafile = strdup("this is a bitchin text file\n"); | 105 | char *outdatafile = strdup("this is a bitchin text file\n"); |
| 106 | bytes = afc_write_file(afc, my_file, outdatafile, strlen(outdatafile)); | 106 | bytes = iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile)); |
| 107 | free(outdatafile); | 107 | free(outdatafile); |
| 108 | if (bytes > 0) printf("Wrote a surprise. ;)\n"); | 108 | if (bytes > 0) printf("Wrote a surprise. ;)\n"); |
| 109 | else printf("I wanted to write a surprise, but... :(\n"); | 109 | else printf("I wanted to write a surprise, but... :(\n"); |
| 110 | afc_close_file(afc, my_file); | 110 | iphone_afc_close_file(afc, my_file); |
| 111 | free(my_file); | ||
| 112 | } | 111 | } |
| 113 | printf("Deleting a file...\n"); | 112 | printf("Deleting a file...\n"); |
| 114 | bytes = afc_delete_file(afc, "/delme"); | 113 | bytes = iphone_afc_delete_file(afc, "/delme"); |
| 115 | if (bytes) printf("Success.\n"); | 114 | if (bytes) printf("Success.\n"); |
| 116 | else printf("Failure. (expected unless you have a /delme file on your phone)\n"); | 115 | else printf("Failure. (expected unless you have a /delme file on your phone)\n"); |
| 117 | 116 | ||
| 118 | printf("Renaming a file...\n"); | 117 | printf("Renaming a file...\n"); |
| 119 | bytes = afc_rename_file(afc, "/renme", "/renme2"); | 118 | bytes = iphone_afc_rename_file(afc, "/renme", "/renme2"); |
| 120 | if (bytes > 0) printf("Success.\n"); | 119 | if (bytes > 0) printf("Success.\n"); |
| 121 | else printf("Failure. (expected unless you have a /renme file on your phone)\n"); | 120 | else printf("Failure. (expected unless you have a /renme file on your phone)\n"); |
| 122 | 121 | ||
| 123 | printf("Seek & read\n"); | 122 | printf("Seek & read\n"); |
| 124 | my_file = afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_READ); | 123 | iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_READ, &my_file); |
| 125 | bytes = afc_seek_file(afc, my_file, 5); | 124 | bytes = iphone_afc_seek_file(afc, my_file, 5); |
| 126 | if (bytes) printf("WARN: SEEK DID NOT WORK\n"); | 125 | if (bytes) printf("WARN: SEEK DID NOT WORK\n"); |
| 127 | char *threeletterword = (char*)malloc(sizeof(char) * 5); | 126 | char *threeletterword = (char*)malloc(sizeof(char) * 5); |
| 128 | bytes = afc_read_file(afc, my_file, threeletterword, 3); | 127 | bytes = iphone_afc_read_file(afc, my_file, threeletterword, 3); |
| 129 | threeletterword[3] = '\0'; | 128 | threeletterword[3] = '\0'; |
| 130 | if (bytes > 0) printf("Result: %s\n", threeletterword); | 129 | if (bytes > 0) printf("Result: %s\n", threeletterword); |
| 131 | else printf("Couldn't read!\n"); | 130 | else printf("Couldn't read!\n"); |
| 132 | free(threeletterword); | 131 | free(threeletterword); |
| 133 | afc_close_file(afc, my_file); | 132 | iphone_afc_close_file(afc, my_file); |
| 134 | free(my_file); | ||
| 135 | 133 | ||
| 136 | } | 134 | } |
| 137 | afc_disconnect(afc); | 135 | iphone_afc_free_client(afc); |
| 138 | } else { | 136 | } else { |
| 139 | printf("Start service failure.\n"); | 137 | printf("Start service failure.\n"); |
| 140 | } | 138 | } |
| 141 | 139 | ||
| 142 | printf("All done.\n"); | 140 | printf("All done.\n"); |
| 143 | 141 | ||
| 144 | lockdownd_close(control); | 142 | iphone_lckd_free_client(control); |
| 145 | free_iPhone(phone); | 143 | iphone_free_device(phone); |
| 146 | 144 | ||
| 147 | return 0; | 145 | return 0; |
| 148 | } | 146 | } |
