diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/afccheck.c | 21 | ||||
| -rw-r--r-- | dev/main.c | 47 |
2 files changed, 35 insertions, 33 deletions
diff --git a/dev/afccheck.c b/dev/afccheck.c index 965981b..b107437 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c | |||
| @@ -25,13 +25,14 @@ | |||
| 25 | #include <glib.h> | 25 | #include <glib.h> |
| 26 | 26 | ||
| 27 | #include <libiphone/libiphone.h> | 27 | #include <libiphone/libiphone.h> |
| 28 | #include <libiphone/afc.h> | ||
| 28 | 29 | ||
| 29 | #define BUFFER_SIZE 20000 | 30 | #define BUFFER_SIZE 20000 |
| 30 | #define NB_THREADS 10 | 31 | #define NB_THREADS 10 |
| 31 | 32 | ||
| 32 | 33 | ||
| 33 | typedef struct { | 34 | typedef struct { |
| 34 | iphone_afc_client_t afc; | 35 | afc_client_t afc; |
| 35 | int id; | 36 | int id; |
| 36 | } param; | 37 | } param; |
| 37 | 38 | ||
| @@ -53,18 +54,18 @@ void check_afc(gpointer data) | |||
| 53 | uint64_t file = 0; | 54 | uint64_t file = 0; |
| 54 | char path[50]; | 55 | char path[50]; |
| 55 | sprintf(path, "/Buf%i", ((param *) data)->id); | 56 | sprintf(path, "/Buf%i", ((param *) data)->id); |
| 56 | iphone_afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RW, &file); | 57 | afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RW, &file); |
| 57 | iphone_afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); | 58 | afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); |
| 58 | iphone_afc_close_file(((param *) data)->afc, file); | 59 | afc_close_file(((param *) data)->afc, file); |
| 59 | file = 0; | 60 | file = 0; |
| 60 | if (bytes != buffersize) | 61 | if (bytes != buffersize) |
| 61 | printf("Write operation failed\n"); | 62 | printf("Write operation failed\n"); |
| 62 | 63 | ||
| 63 | //now read it | 64 | //now read it |
| 64 | bytes = 0; | 65 | bytes = 0; |
| 65 | iphone_afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); | 66 | afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); |
| 66 | iphone_afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); | 67 | afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); |
| 67 | iphone_afc_close_file(((param *) data)->afc, file); | 68 | afc_close_file(((param *) data)->afc, file); |
| 68 | if (bytes != buffersize) | 69 | if (bytes != buffersize) |
| 69 | printf("Read operation failed\n"); | 70 | printf("Read operation failed\n"); |
| 70 | 71 | ||
| @@ -77,7 +78,7 @@ void check_afc(gpointer data) | |||
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | //cleanup | 80 | //cleanup |
| 80 | iphone_afc_delete_file(((param *) data)->afc, path); | 81 | afc_delete_file(((param *) data)->afc, path); |
| 81 | g_thread_exit(0); | 82 | g_thread_exit(0); |
| 82 | } | 83 | } |
| 83 | 84 | ||
| @@ -87,7 +88,7 @@ int main(int argc, char *argv[]) | |||
| 87 | iphone_device_t phone = NULL; | 88 | iphone_device_t phone = NULL; |
| 88 | GError *err; | 89 | GError *err; |
| 89 | int port = 0; | 90 | int port = 0; |
| 90 | iphone_afc_client_t afc = NULL; | 91 | afc_client_t afc = NULL; |
| 91 | 92 | ||
| 92 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { | 93 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { |
| 93 | printf("No iPhone found, is it plugged in?\n"); | 94 | printf("No iPhone found, is it plugged in?\n"); |
| @@ -106,7 +107,7 @@ int main(int argc, char *argv[]) | |||
| 106 | return 1; | 107 | return 1; |
| 107 | } | 108 | } |
| 108 | 109 | ||
| 109 | iphone_afc_new_client(phone, port, &afc); | 110 | afc_new_client(phone, port, &afc); |
| 110 | 111 | ||
| 111 | //makes sure thread environment is available | 112 | //makes sure thread environment is available |
| 112 | if (!g_thread_supported()) | 113 | if (!g_thread_supported()) |
| @@ -25,6 +25,7 @@ | |||
| 25 | #include <usb.h> | 25 | #include <usb.h> |
| 26 | 26 | ||
| 27 | #include <libiphone/libiphone.h> | 27 | #include <libiphone/libiphone.h> |
| 28 | #include <libiphone/afc.h> | ||
| 28 | #include "../src/utils.h" | 29 | #include "../src/utils.h" |
| 29 | 30 | ||
| 30 | void notifier(const char *notification) | 31 | void notifier(const char *notification) |
| @@ -97,8 +98,8 @@ int main(int argc, char *argv[]) | |||
| 97 | iphone_lckd_start_service(control, "com.apple.afc", &port); | 98 | iphone_lckd_start_service(control, "com.apple.afc", &port); |
| 98 | 99 | ||
| 99 | if (port) { | 100 | if (port) { |
| 100 | iphone_afc_client_t afc = NULL; | 101 | afc_client_t afc = NULL; |
| 101 | iphone_afc_new_client(phone, port, &afc); | 102 | afc_new_client(phone, port, &afc); |
| 102 | if (afc) { | 103 | if (afc) { |
| 103 | iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); | 104 | iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); |
| 104 | if (npp) { | 105 | if (npp) { |
| @@ -120,18 +121,18 @@ int main(int argc, char *argv[]) | |||
| 120 | 121 | ||
| 121 | perform_notification(phone, control, NP_SYNC_WILL_START); | 122 | perform_notification(phone, control, NP_SYNC_WILL_START); |
| 122 | 123 | ||
| 123 | iphone_afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); | 124 | afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); |
| 124 | if (lockfile) { | 125 | if (lockfile) { |
| 125 | printf("locking file\n"); | 126 | printf("locking file\n"); |
| 126 | iphone_afc_lock_file(afc, lockfile, 2 | 4); | 127 | afc_lock_file(afc, lockfile, 2 | 4); |
| 127 | 128 | ||
| 128 | perform_notification(phone, control, NP_SYNC_DID_START); | 129 | perform_notification(phone, control, NP_SYNC_DID_START); |
| 129 | } | 130 | } |
| 130 | 131 | ||
| 131 | char **dirs = NULL; | 132 | char **dirs = NULL; |
| 132 | iphone_afc_get_dir_list(afc, "/eafaedf", &dirs); | 133 | afc_get_dir_list(afc, "/eafaedf", &dirs); |
| 133 | if (!dirs) | 134 | if (!dirs) |
| 134 | iphone_afc_get_dir_list(afc, "/", &dirs); | 135 | afc_get_dir_list(afc, "/", &dirs); |
| 135 | printf("Directory time.\n"); | 136 | printf("Directory time.\n"); |
| 136 | for (i = 0; dirs[i]; i++) { | 137 | for (i = 0; dirs[i]; i++) { |
| 137 | printf("/%s\n", dirs[i]); | 138 | printf("/%s\n", dirs[i]); |
| @@ -140,7 +141,7 @@ int main(int argc, char *argv[]) | |||
| 140 | g_strfreev(dirs); | 141 | g_strfreev(dirs); |
| 141 | 142 | ||
| 142 | dirs = NULL; | 143 | dirs = NULL; |
| 143 | iphone_afc_get_devinfo(afc, &dirs); | 144 | afc_get_devinfo(afc, &dirs); |
| 144 | if (dirs) { | 145 | if (dirs) { |
| 145 | for (i = 0; dirs[i]; i += 2) { | 146 | for (i = 0; dirs[i]; i += 2) { |
| 146 | printf("%s: %s\n", dirs[i], dirs[i + 1]); | 147 | printf("%s: %s\n", dirs[i], dirs[i + 1]); |
| @@ -151,7 +152,7 @@ int main(int argc, char *argv[]) | |||
| 151 | uint64_t my_file = 0; | 152 | uint64_t my_file = 0; |
| 152 | char **info = NULL; | 153 | char **info = NULL; |
| 153 | uint64_t fsize = 0; | 154 | uint64_t fsize = 0; |
| 154 | if (IPHONE_E_SUCCESS == iphone_afc_get_file_info(afc, "/readme.libiphone.fx", &info) && info) { | 155 | if (IPHONE_E_SUCCESS == afc_get_file_info(afc, "/readme.libiphone.fx", &info) && info) { |
| 155 | for (i = 0; info[i]; i += 2) { | 156 | for (i = 0; info[i]; i += 2) { |
| 156 | printf("%s: %s\n", info[i], info[i+1]); | 157 | printf("%s: %s\n", info[i], info[i+1]); |
| 157 | if (!strcmp(info[i], "st_size")) { | 158 | if (!strcmp(info[i], "st_size")) { |
| @@ -161,58 +162,58 @@ int main(int argc, char *argv[]) | |||
| 161 | } | 162 | } |
| 162 | 163 | ||
| 163 | if (IPHONE_E_SUCCESS == | 164 | if (IPHONE_E_SUCCESS == |
| 164 | iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { | 165 | afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { |
| 165 | printf("A file size: %i\n", fsize); | 166 | printf("A file size: %i\n", fsize); |
| 166 | char *file_data = (char *) malloc(sizeof(char) * fsize); | 167 | char *file_data = (char *) malloc(sizeof(char) * fsize); |
| 167 | iphone_afc_read_file(afc, my_file, file_data, fsize, &bytes); | 168 | afc_read_file(afc, my_file, file_data, fsize, &bytes); |
| 168 | if (bytes >= 0) { | 169 | if (bytes >= 0) { |
| 169 | printf("The file's data:\n"); | 170 | printf("The file's data:\n"); |
| 170 | fwrite(file_data, 1, bytes, stdout); | 171 | fwrite(file_data, 1, bytes, stdout); |
| 171 | } | 172 | } |
| 172 | printf("\nClosing my file.\n"); | 173 | printf("\nClosing my file.\n"); |
| 173 | iphone_afc_close_file(afc, my_file); | 174 | afc_close_file(afc, my_file); |
| 174 | free(file_data); | 175 | free(file_data); |
| 175 | } else | 176 | } else |
| 176 | printf("couldn't open a file\n"); | 177 | printf("couldn't open a file\n"); |
| 177 | 178 | ||
| 178 | iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_WR, &my_file); | 179 | afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_WR, &my_file); |
| 179 | if (my_file) { | 180 | if (my_file) { |
| 180 | char *outdatafile = strdup("this is a bitchin text file\n"); | 181 | char *outdatafile = strdup("this is a bitchin text file\n"); |
| 181 | iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); | 182 | afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); |
| 182 | free(outdatafile); | 183 | free(outdatafile); |
| 183 | if (bytes > 0) | 184 | if (bytes > 0) |
| 184 | printf("Wrote a surprise. ;)\n"); | 185 | printf("Wrote a surprise. ;)\n"); |
| 185 | else | 186 | else |
| 186 | printf("I wanted to write a surprise, but... :(\n"); | 187 | printf("I wanted to write a surprise, but... :(\n"); |
| 187 | iphone_afc_close_file(afc, my_file); | 188 | afc_close_file(afc, my_file); |
| 188 | } | 189 | } |
| 189 | printf("Deleting a file...\n"); | 190 | printf("Deleting a file...\n"); |
| 190 | bytes = iphone_afc_delete_file(afc, "/delme"); | 191 | bytes = afc_delete_file(afc, "/delme"); |
| 191 | if (bytes) | 192 | if (bytes) |
| 192 | printf("Success.\n"); | 193 | printf("Success.\n"); |
| 193 | else | 194 | else |
| 194 | printf("Failure. (expected unless you have a /delme file on your phone)\n"); | 195 | printf("Failure. (expected unless you have a /delme file on your phone)\n"); |
| 195 | 196 | ||
| 196 | printf("Renaming a file...\n"); | 197 | printf("Renaming a file...\n"); |
| 197 | bytes = iphone_afc_rename_file(afc, "/renme", "/renme2"); | 198 | bytes = afc_rename_file(afc, "/renme", "/renme2"); |
| 198 | if (bytes > 0) | 199 | if (bytes > 0) |
| 199 | printf("Success.\n"); | 200 | printf("Success.\n"); |
| 200 | else | 201 | else |
| 201 | printf("Failure. (expected unless you have a /renme file on your phone)\n"); | 202 | printf("Failure. (expected unless you have a /renme file on your phone)\n"); |
| 202 | 203 | ||
| 203 | printf("Seek & read\n"); | 204 | printf("Seek & read\n"); |
| 204 | iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file); | 205 | afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file); |
| 205 | if (IPHONE_E_SUCCESS != iphone_afc_seek_file(afc, my_file, 5, SEEK_CUR)) | 206 | if (IPHONE_E_SUCCESS != afc_seek_file(afc, my_file, 5, SEEK_CUR)) |
| 206 | printf("WARN: SEEK DID NOT WORK\n"); | 207 | printf("WARN: SEEK DID NOT WORK\n"); |
| 207 | char *threeletterword = (char *) malloc(sizeof(char) * 5); | 208 | char *threeletterword = (char *) malloc(sizeof(char) * 5); |
| 208 | iphone_afc_read_file(afc, my_file, threeletterword, 3, &bytes); | 209 | afc_read_file(afc, my_file, threeletterword, 3, &bytes); |
| 209 | threeletterword[3] = '\0'; | 210 | threeletterword[3] = '\0'; |
| 210 | if (bytes > 0) | 211 | if (bytes > 0) |
| 211 | printf("Result: %s\n", threeletterword); | 212 | printf("Result: %s\n", threeletterword); |
| 212 | else | 213 | else |
| 213 | printf("Couldn't read!\n"); | 214 | printf("Couldn't read!\n"); |
| 214 | free(threeletterword); | 215 | free(threeletterword); |
| 215 | iphone_afc_close_file(afc, my_file); | 216 | afc_close_file(afc, my_file); |
| 216 | } | 217 | } |
| 217 | 218 | ||
| 218 | if (gnp && lockfile) { | 219 | if (gnp && lockfile) { |
| @@ -245,10 +246,10 @@ int main(int argc, char *argv[]) | |||
| 245 | //perform_notification(phone, control, NP_SYNC_DID_FINISH); | 246 | //perform_notification(phone, control, NP_SYNC_DID_FINISH); |
| 246 | 247 | ||
| 247 | printf("XXX unlocking file\n"); | 248 | printf("XXX unlocking file\n"); |
| 248 | iphone_afc_lock_file(afc, lockfile, 8 | 4); | 249 | afc_lock_file(afc, lockfile, 8 | 4); |
| 249 | 250 | ||
| 250 | printf("XXX closing file\n"); | 251 | printf("XXX closing file\n"); |
| 251 | iphone_afc_close_file(afc, lockfile); | 252 | afc_close_file(afc, lockfile); |
| 252 | } | 253 | } |
| 253 | 254 | ||
| 254 | if (gnp) { | 255 | if (gnp) { |
| @@ -256,7 +257,7 @@ int main(int argc, char *argv[]) | |||
| 256 | gnp = NULL; | 257 | gnp = NULL; |
| 257 | } | 258 | } |
| 258 | 259 | ||
| 259 | iphone_afc_free_client(afc); | 260 | afc_free_client(afc); |
| 260 | } else { | 261 | } else { |
| 261 | printf("Start service failure.\n"); | 262 | printf("Start service failure.\n"); |
| 262 | } | 263 | } |
