diff options
Diffstat (limited to 'src/AFC.c')
| -rw-r--r-- | src/AFC.c | 51 |
1 files changed, 25 insertions, 26 deletions
| @@ -21,8 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | #include <stdio.h> | 22 | #include <stdio.h> |
| 23 | #include "AFC.h" | 23 | #include "AFC.h" |
| 24 | #include "plist.h" | 24 | |
| 25 | #include "utils.h" | ||
| 26 | 25 | ||
| 27 | 26 | ||
| 28 | // This is the maximum size an AFC data packet can be | 27 | // This is the maximum size an AFC data packet can be |
| @@ -246,7 +245,7 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) | |||
| 246 | return retval; | 245 | return retval; |
| 247 | } | 246 | } |
| 248 | 247 | ||
| 249 | uint32 param1 = buffer[sizeof(AFCPacket)]; | 248 | uint32_t param1 = buffer[sizeof(AFCPacket)]; |
| 250 | free(buffer); | 249 | free(buffer); |
| 251 | 250 | ||
| 252 | if (r_packet->operation == AFC_ERROR && !(client->afc_packet->operation == AFC_DELETE && param1 == 7)) { | 251 | if (r_packet->operation == AFC_ERROR && !(client->afc_packet->operation == AFC_DELETE && param1 == 7)) { |
| @@ -475,7 +474,7 @@ iphone_error_t iphone_afc_delete_file(iphone_afc_client_t client, const char *pa | |||
| 475 | iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *from, const char *to) | 474 | iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *from, const char *to) |
| 476 | { | 475 | { |
| 477 | char *response = NULL; | 476 | char *response = NULL; |
| 478 | char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32))); | 477 | char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t))); |
| 479 | int bytes = 0; | 478 | int bytes = 0; |
| 480 | 479 | ||
| 481 | if (!client || !from || !to || !client->afc_packet || !client->connection) | 480 | if (!client || !from || !to || !client->afc_packet || !client->connection) |
| @@ -661,7 +660,7 @@ iphone_afc_open_file(iphone_afc_client_t client, const char *filename, | |||
| 661 | iphone_afc_file_mode_t file_mode, iphone_afc_file_t * file) | 660 | iphone_afc_file_mode_t file_mode, iphone_afc_file_t * file) |
| 662 | { | 661 | { |
| 663 | iphone_afc_file_t file_loc = NULL; | 662 | iphone_afc_file_t file_loc = NULL; |
| 664 | uint32 ag = 0; | 663 | uint32_t ag = 0; |
| 665 | int bytes = 0, length = 0; | 664 | int bytes = 0, length = 0; |
| 666 | char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); | 665 | char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); |
| 667 | 666 | ||
| @@ -796,8 +795,8 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file, | |||
| 796 | { | 795 | { |
| 797 | char *acknowledgement = NULL; | 796 | char *acknowledgement = NULL; |
| 798 | const int MAXIMUM_WRITE_SIZE = 1 << 15; | 797 | const int MAXIMUM_WRITE_SIZE = 1 << 15; |
| 799 | uint32 zero = 0, current_count = 0, i = 0; | 798 | uint32_t zero = 0, current_count = 0, i = 0; |
| 800 | uint32 segments = (length / MAXIMUM_WRITE_SIZE); | 799 | uint32_t segments = (length / MAXIMUM_WRITE_SIZE); |
| 801 | int bytes_loc = 0; | 800 | int bytes_loc = 0; |
| 802 | char *out_buffer = NULL; | 801 | char *out_buffer = NULL; |
| 803 | 802 | ||
| @@ -815,8 +814,8 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file, | |||
| 815 | client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE; | 814 | client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE; |
| 816 | client->afc_packet->operation = AFC_WRITE; | 815 | client->afc_packet->operation = AFC_WRITE; |
| 817 | out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); | 816 | out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); |
| 818 | memcpy(out_buffer, (char *) &file->filehandle, sizeof(uint32)); | 817 | memcpy(out_buffer, (char *) &file->filehandle, sizeof(uint32_t)); |
| 819 | memcpy(out_buffer + 4, (char *) &zero, sizeof(uint32)); | 818 | memcpy(out_buffer + 4, (char *) &zero, sizeof(uint32_t)); |
| 820 | memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE); | 819 | memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE); |
| 821 | bytes_loc = dispatch_AFC_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8); | 820 | bytes_loc = dispatch_AFC_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8); |
| 822 | if (bytes_loc < 0) { | 821 | if (bytes_loc < 0) { |
| @@ -848,8 +847,8 @@ iphone_afc_write_file(iphone_afc_client_t client, iphone_afc_file_t file, | |||
| 848 | client->afc_packet->entire_length = client->afc_packet->this_length + (length - current_count); | 847 | client->afc_packet->entire_length = client->afc_packet->this_length + (length - current_count); |
| 849 | client->afc_packet->operation = AFC_WRITE; | 848 | client->afc_packet->operation = AFC_WRITE; |
| 850 | out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); | 849 | out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); |
| 851 | memcpy(out_buffer, (char *) &file->filehandle, sizeof(uint32)); | 850 | memcpy(out_buffer, (char *) &file->filehandle, sizeof(uint32_t)); |
| 852 | memcpy(out_buffer + 4, (char *) &zero, sizeof(uint32)); | 851 | memcpy(out_buffer + 4, (char *) &zero, sizeof(uint32_t)); |
| 853 | memcpy(out_buffer + 8, data + current_count, (length - current_count)); | 852 | memcpy(out_buffer + 8, data + current_count, (length - current_count)); |
| 854 | bytes_loc = dispatch_AFC_packet(client, out_buffer, (length - current_count) + 8); | 853 | bytes_loc = dispatch_AFC_packet(client, out_buffer, (length - current_count) + 8); |
| 855 | free(out_buffer); | 854 | free(out_buffer); |
| @@ -884,7 +883,7 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file | |||
| 884 | if (!client || !file) | 883 | if (!client || !file) |
| 885 | return IPHONE_E_INVALID_ARG; | 884 | return IPHONE_E_INVALID_ARG; |
| 886 | char *buffer = malloc(sizeof(char) * 8); | 885 | char *buffer = malloc(sizeof(char) * 8); |
| 887 | uint32 zero = 0; | 886 | uint32_t zero = 0; |
| 888 | int bytes = 0; | 887 | int bytes = 0; |
| 889 | 888 | ||
| 890 | afc_lock(client); | 889 | afc_lock(client); |
| @@ -892,8 +891,8 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file | |||
| 892 | log_debug_msg("afc_close_file: File handle %i\n", file->filehandle); | 891 | log_debug_msg("afc_close_file: File handle %i\n", file->filehandle); |
| 893 | 892 | ||
| 894 | // Send command | 893 | // Send command |
| 895 | memcpy(buffer, &file->filehandle, sizeof(uint32)); | 894 | memcpy(buffer, &file->filehandle, sizeof(uint32_t)); |
| 896 | memcpy(buffer + sizeof(uint32), &zero, sizeof(zero)); | 895 | memcpy(buffer + sizeof(uint32_t), &zero, sizeof(zero)); |
| 897 | client->afc_packet->operation = AFC_FILE_CLOSE; | 896 | client->afc_packet->operation = AFC_FILE_CLOSE; |
| 898 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 897 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| 899 | bytes = dispatch_AFC_packet(client, buffer, sizeof(char) * 8); | 898 | bytes = dispatch_AFC_packet(client, buffer, sizeof(char) * 8); |
| @@ -929,7 +928,7 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, iphone_afc_file | |||
| 929 | iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, iphone_afc_file_t file, int seekpos) | 928 | iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, iphone_afc_file_t file, int seekpos) |
| 930 | { | 929 | { |
| 931 | char *buffer = (char *) malloc(sizeof(char) * 24); | 930 | char *buffer = (char *) malloc(sizeof(char) * 24); |
| 932 | uint32 seekto = 0, zero = 0; | 931 | uint32_t seekto = 0, zero = 0; |
| 933 | int bytes = 0; | 932 | int bytes = 0; |
| 934 | 933 | ||
| 935 | if (seekpos < 0) | 934 | if (seekpos < 0) |
| @@ -939,12 +938,12 @@ iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, iphone_afc_file_ | |||
| 939 | 938 | ||
| 940 | // Send the command | 939 | // Send the command |
| 941 | seekto = seekpos; | 940 | seekto = seekpos; |
| 942 | memcpy(buffer, &file->filehandle, sizeof(uint32)); // handle | 941 | memcpy(buffer, &file->filehandle, sizeof(uint32_t)); // handle |
| 943 | memcpy(buffer + 4, &zero, sizeof(uint32)); // pad | 942 | memcpy(buffer + 4, &zero, sizeof(uint32_t)); // pad |
| 944 | memcpy(buffer + 8, &zero, sizeof(uint32)); // fromwhere | 943 | memcpy(buffer + 8, &zero, sizeof(uint32_t)); // fromwhere |
| 945 | memcpy(buffer + 12, &zero, sizeof(uint32)); // pad | 944 | memcpy(buffer + 12, &zero, sizeof(uint32_t)); // pad |
| 946 | memcpy(buffer + 16, &seekto, sizeof(uint32)); // offset | 945 | memcpy(buffer + 16, &seekto, sizeof(uint32_t)); // offset |
| 947 | memcpy(buffer + 20, &zero, sizeof(uint32)); // pad | 946 | memcpy(buffer + 20, &zero, sizeof(uint32_t)); // pad |
| 948 | client->afc_packet->operation = AFC_FILE_SEEK; | 947 | client->afc_packet->operation = AFC_FILE_SEEK; |
| 949 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; | 948 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; |
| 950 | bytes = dispatch_AFC_packet(client, buffer, 23); | 949 | bytes = dispatch_AFC_packet(client, buffer, 23); |
| @@ -984,14 +983,14 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, iphone_afc_f | |||
| 984 | { | 983 | { |
| 985 | char *buffer = (char *) malloc(sizeof(char) * 16); | 984 | char *buffer = (char *) malloc(sizeof(char) * 16); |
| 986 | int bytes = 0; | 985 | int bytes = 0; |
| 987 | uint32 zero = 0; | 986 | uint32_t zero = 0; |
| 988 | 987 | ||
| 989 | afc_lock(client); | 988 | afc_lock(client); |
| 990 | 989 | ||
| 991 | // Send command | 990 | // Send command |
| 992 | memcpy(buffer, &file->filehandle, sizeof(uint32)); // handle | 991 | memcpy(buffer, &file->filehandle, sizeof(uint32_t)); // handle |
| 993 | memcpy(buffer + 4, &zero, sizeof(uint32)); // pad | 992 | memcpy(buffer + 4, &zero, sizeof(uint32_t)); // pad |
| 994 | memcpy(buffer + 8, &newsize, sizeof(uint32)); // newsize | 993 | memcpy(buffer + 8, &newsize, sizeof(uint32_t)); // newsize |
| 995 | memcpy(buffer + 12, &zero, 3); // pad | 994 | memcpy(buffer + 12, &zero, 3); // pad |
| 996 | client->afc_packet->operation = AFC_FILE_TRUNCATE; | 995 | client->afc_packet->operation = AFC_FILE_TRUNCATE; |
| 997 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; | 996 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; |
| @@ -1017,7 +1016,7 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, iphone_afc_f | |||
| 1017 | } | 1016 | } |
| 1018 | } | 1017 | } |
| 1019 | 1018 | ||
| 1020 | uint32 iphone_afc_get_file_handle(iphone_afc_file_t file) | 1019 | uint32_t iphone_afc_get_file_handle(iphone_afc_file_t file) |
| 1021 | { | 1020 | { |
| 1022 | return file->filehandle; | 1021 | return file->filehandle; |
| 1023 | } | 1022 | } |
