diff options
Diffstat (limited to 'dev')
| -rw-r--r-- | dev/lckdclient.c | 1 | ||||
| -rw-r--r-- | dev/main.c | 2 | ||||
| -rw-r--r-- | dev/plutil.c | 219 |
3 files changed, 115 insertions, 107 deletions
diff --git a/dev/lckdclient.c b/dev/lckdclient.c index 96bc27d..c96f052 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include <stdio.h> | 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> | ||
| 23 | #include <string.h> | 24 | #include <string.h> |
| 24 | #include <glib.h> | 25 | #include <glib.h> |
| 25 | #include <readline/readline.h> | 26 | #include <readline/readline.h> |
| @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) | |||
| 87 | iphone_afc_get_file_attr(afc, "/iTunesOnTheGoPlaylist.plist", &stbuf); | 87 | iphone_afc_get_file_attr(afc, "/iTunesOnTheGoPlaylist.plist", &stbuf); |
| 88 | if (IPHONE_E_SUCCESS == | 88 | if (IPHONE_E_SUCCESS == |
| 89 | iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", IPHONE_AFC_FILE_READ, &my_file) && my_file) { | 89 | iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", IPHONE_AFC_FILE_READ, &my_file) && my_file) { |
| 90 | printf("A file size: %i\n", stbuf.st_size); | 90 | printf("A file size: %i\n", (int) stbuf.st_size); |
| 91 | char *file_data = (char *) malloc(sizeof(char) * stbuf.st_size); | 91 | char *file_data = (char *) malloc(sizeof(char) * stbuf.st_size); |
| 92 | iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes); | 92 | iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes); |
| 93 | if (bytes >= 0) { | 93 | if (bytes >= 0) { |
diff --git a/dev/plutil.c b/dev/plutil.c index 1c7b140..d1c3ddd 100644 --- a/dev/plutil.c +++ b/dev/plutil.c | |||
| @@ -5,171 +5,178 @@ | |||
| 5 | 5 | ||
| 6 | #include "../src/plist.h" | 6 | #include "../src/plist.h" |
| 7 | #include "plutil.h" | 7 | #include "plutil.h" |
| 8 | #include <glib.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <stdlib.h> | ||
| 8 | 12 | ||
| 9 | int debug = 0; | 13 | void print_nodes(bplist_node * root_node) |
| 10 | 14 | { | |
| 11 | void print_nodes(bplist_node *root_node) { | ||
| 12 | // Yay, great. Let's print the list of nodes recursively... | 15 | // Yay, great. Let's print the list of nodes recursively... |
| 13 | int i = 0; | 16 | int i = 0; |
| 14 | if (!root_node) return; // or not, because the programmer's stupid. | 17 | if (!root_node) |
| 15 | 18 | return; // or not, because the programmer's stupid. | |
| 19 | |||
| 16 | switch (root_node->type) { | 20 | switch (root_node->type) { |
| 17 | case BPLIST_DICT: | 21 | case BPLIST_DICT: |
| 18 | printf("Dictionary node.\nLength %i\n", root_node->length); | 22 | printf("Dictionary node.\nLength %lu\n", (long unsigned int) root_node->length); |
| 19 | for (i = 0; i < (root_node->length * 2); i+=2) { | 23 | for (i = 0; i < (root_node->length * 2); i += 2) { |
| 20 | // HI! | 24 | // HI! |
| 21 | printf("Key: "); | 25 | printf("Key: "); |
| 22 | print_nodes(root_node->subnodes[i]); | 26 | print_nodes(root_node->subnodes[i]); |
| 23 | printf("Value: "); | 27 | printf("Value: "); |
| 24 | print_nodes(root_node->subnodes[i+1]); | 28 | print_nodes(root_node->subnodes[i + 1]); |
| 25 | } | 29 | } |
| 26 | printf("End dictionary node.\n\n"); | 30 | printf("End dictionary node.\n\n"); |
| 27 | break; | 31 | break; |
| 28 | 32 | ||
| 29 | case BPLIST_ARRAY: | 33 | case BPLIST_ARRAY: |
| 30 | printf("Array node.\n"); | 34 | printf("Array node.\n"); |
| 31 | for (i = 0; i < root_node->length; i++) { | 35 | for (i = 0; i < root_node->length; i++) { |
| 32 | printf("\tElement %i: ", i); | 36 | printf("\tElement %i: ", i); |
| 33 | print_nodes(root_node->subnodes[i]); | 37 | print_nodes(root_node->subnodes[i]); |
| 34 | } | 38 | } |
| 35 | break; | 39 | break; |
| 36 | 40 | ||
| 37 | case BPLIST_INT: | 41 | case BPLIST_INT: |
| 38 | if (root_node->length == sizeof(uint8_t)) { | 42 | if (root_node->length == sizeof(uint8_t)) { |
| 39 | printf("Integer: %i\n", root_node->intval8); | 43 | printf("Integer: %i\n", root_node->intval8); |
| 40 | } else if (root_node->length == sizeof(uint16_t)) { | 44 | } else if (root_node->length == sizeof(uint16_t)) { |
| 41 | printf("Integer: %i\n", root_node->intval16); | 45 | printf("Integer: %i\n", root_node->intval16); |
| 42 | } else if (root_node->length == sizeof(uint32_t)) { | 46 | } else if (root_node->length == sizeof(uint32_t)) { |
| 43 | printf("Integer: %i\n", root_node->intval32); | 47 | printf("Integer: %i\n", root_node->intval32); |
| 44 | } | 48 | } |
| 45 | break; | 49 | break; |
| 46 | 50 | ||
| 47 | case BPLIST_STRING: | 51 | case BPLIST_STRING: |
| 48 | printf("String: "); | 52 | printf("String: "); |
| 49 | fwrite(root_node->strval, sizeof(char), root_node->length, stdout); | 53 | fwrite(root_node->strval, sizeof(char), root_node->length, stdout); |
| 50 | fflush(stdout); | 54 | fflush(stdout); |
| 51 | printf("\n"); | 55 | printf("\n"); |
| 52 | break; | 56 | break; |
| 53 | 57 | ||
| 54 | case BPLIST_DATA: | 58 | case BPLIST_DATA: |
| 55 | printf("Data: "); | 59 | printf("Data: "); |
| 56 | char* data = g_base64_encode(root_node->strval,root_node->length); | 60 | char *data = g_base64_encode(root_node->strval, root_node->length); |
| 57 | fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout); | 61 | fwrite(format_string(data, 60, 0), sizeof(char), strlen(data), stdout); |
| 58 | fflush(stdout); | 62 | fflush(stdout); |
| 59 | printf("\n"); | 63 | printf("\n"); |
| 60 | break; | 64 | break; |
| 61 | 65 | ||
| 62 | case BPLIST_UNICODE: | 66 | case BPLIST_UNICODE: |
| 63 | printf("Unicode data, may appear crappy: "); | 67 | printf("Unicode data, may appear crappy: "); |
| 64 | fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); | 68 | fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); |
| 65 | fflush(stdout); | 69 | fflush(stdout); |
| 66 | printf("\n"); | 70 | printf("\n"); |
| 67 | break; | 71 | break; |
| 68 | 72 | ||
| 69 | case BPLIST_TRUE: | 73 | case BPLIST_TRUE: |
| 70 | printf("True.\n"); | 74 | printf("True.\n"); |
| 71 | break; | 75 | break; |
| 72 | 76 | ||
| 73 | case BPLIST_FALSE: | 77 | case BPLIST_FALSE: |
| 74 | printf("False.\n"); | 78 | printf("False.\n"); |
| 75 | break; | 79 | break; |
| 76 | 80 | ||
| 77 | case BPLIST_REAL: | 81 | case BPLIST_REAL: |
| 78 | case BPLIST_DATE: | 82 | case BPLIST_DATE: |
| 79 | printf("Real(?): %f\n", root_node->realval); | 83 | printf("Real(?): %f\n", root_node->realval); |
| 80 | break; | 84 | break; |
| 81 | 85 | ||
| 82 | default: | 86 | default: |
| 83 | printf("oops\nType set to %x and length is %i\n", root_node->type, root_node->length); | 87 | printf("oops\nType set to %x and length is %lu\n", root_node->type, (long unsigned int) root_node->length); |
| 84 | break; | 88 | break; |
| 85 | } | 89 | } |
| 86 | } | 90 | } |
| 87 | 91 | ||
| 88 | int main(int argc, char *argv[]) { | 92 | int main(int argc, char *argv[]) |
| 89 | struct stat *filestats = (struct stat *)malloc(sizeof(struct stat)); | 93 | { |
| 94 | struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); | ||
| 90 | uint32_t position = 0; | 95 | uint32_t position = 0; |
| 91 | Options *options = parse_arguments(argc, argv); | 96 | Options *options = parse_arguments(argc, argv); |
| 92 | int argh = 0; | 97 | int argh = 0; |
| 93 | 98 | ||
| 94 | printf("plistutil version 0.2 written by FxChiP\n"); | 99 | printf("plistutil version 0.2 written by FxChiP\n"); |
| 95 | 100 | ||
| 96 | if (!options) { | 101 | if (!options) { |
| 97 | print_usage(); | 102 | print_usage(); |
| 98 | return 0; | 103 | return 0; |
| 99 | } | 104 | } |
| 100 | 105 | ||
| 101 | debug = options->debug; | 106 | iphone_set_debug(options->debug); |
| 102 | 107 | ||
| 103 | FILE *bplist = fopen(options->in_file, "r"); | 108 | FILE *bplist = fopen(options->in_file, "r"); |
| 104 | 109 | ||
| 105 | stat(options->in_file, filestats); | 110 | stat(options->in_file, filestats); |
| 106 | 111 | ||
| 107 | printf("here?\n"); | 112 | printf("here?\n"); |
| 108 | char *bplist_entire = (char*)malloc(sizeof(char) * (filestats->st_size + 1)); | 113 | char *bplist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1)); |
| 109 | //argh = fgets(bplist_entire, filestats->st_size, bplist); | 114 | //argh = fgets(bplist_entire, filestats->st_size, bplist); |
| 110 | argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); | 115 | argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); |
| 111 | printf("read %i bytes\n", argh); | 116 | printf("read %i bytes\n", argh); |
| 112 | fclose(bplist); | 117 | fclose(bplist); |
| 113 | printf("or here?\n"); | 118 | printf("or here?\n"); |
| 114 | // bplist_entire contains our stuff | 119 | // bplist_entire contains our stuff |
| 115 | bplist_node *root_node; | 120 | bplist_node *root_node; |
| 116 | root_node = parse_nodes(bplist_entire, filestats->st_size, &position); | 121 | root_node = parse_nodes(bplist_entire, filestats->st_size, &position); |
| 117 | printf("plutil debug mode\n\n"); | 122 | printf("plutil debug mode\n\n"); |
| 118 | printf("file size %i\n\n", filestats->st_size); | 123 | printf("file size %i\n\n", (int) filestats->st_size); |
| 119 | if (!root_node) { | 124 | if (!root_node) { |
| 120 | printf("Invalid binary plist (or some other error occurred.)\n"); | 125 | printf("Invalid binary plist (or some other error occurred.)\n"); |
| 121 | return 0; | 126 | return 0; |
| 122 | } | 127 | } |
| 123 | print_nodes(root_node); | 128 | print_nodes(root_node); |
| 124 | return 0; | 129 | return 0; |
| 125 | } | 130 | } |
| 126 | 131 | ||
| 127 | Options *parse_arguments(int argc, char *argv[]) { | 132 | Options *parse_arguments(int argc, char *argv[]) |
| 133 | { | ||
| 128 | int i = 0; | 134 | int i = 0; |
| 129 | 135 | ||
| 130 | Options *options = (Options*)malloc(sizeof(Options)); | 136 | Options *options = (Options *) malloc(sizeof(Options)); |
| 131 | memset(options, 0, sizeof(Options)); | 137 | memset(options, 0, sizeof(Options)); |
| 132 | 138 | ||
| 133 | for (i = 1; i < argc; i++) { | 139 | for (i = 1; i < argc; i++) { |
| 134 | if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) { | 140 | if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) { |
| 135 | if ((i+1) == argc) { | 141 | if ((i + 1) == argc) { |
| 136 | free(options); | 142 | free(options); |
| 137 | return NULL; | 143 | return NULL; |
| 138 | } | 144 | } |
| 139 | options->in_file = argv[i+1]; | 145 | options->in_file = argv[i + 1]; |
| 140 | i++; | 146 | i++; |
| 141 | continue; | 147 | continue; |
| 142 | } | 148 | } |
| 143 | 149 | ||
| 144 | if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) { | 150 | if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) { |
| 145 | if ((i+1) == argc) { | 151 | if ((i + 1) == argc) { |
| 146 | free(options); | 152 | free(options); |
| 147 | return NULL; | 153 | return NULL; |
| 148 | } | 154 | } |
| 149 | options->out_file = argv[i+1]; | 155 | options->out_file = argv[i + 1]; |
| 150 | i++; | 156 | i++; |
| 151 | continue; | 157 | continue; |
| 152 | } | 158 | } |
| 153 | 159 | ||
| 154 | if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) { | 160 | if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) { |
| 155 | options->debug = 1; | 161 | options->debug = 1; |
| 156 | } | 162 | } |
| 157 | 163 | ||
| 158 | if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { | 164 | if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { |
| 159 | free(options); | 165 | free(options); |
| 160 | return NULL; | 166 | return NULL; |
| 161 | } | 167 | } |
| 162 | } | 168 | } |
| 163 | 169 | ||
| 164 | if (!options->in_file /*|| !options->out_file*/) { | 170 | if (!options->in_file /*|| !options->out_file */ ) { |
| 165 | free(options); | 171 | free(options); |
| 166 | return NULL; | 172 | return NULL; |
| 167 | } | 173 | } |
| 168 | 174 | ||
| 169 | return options; | 175 | return options; |
| 170 | } | 176 | } |
| 171 | 177 | ||
| 172 | void print_usage() { | 178 | void print_usage() |
| 179 | { | ||
| 173 | printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); | 180 | printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); |
| 174 | printf("\n"); | 181 | printf("\n"); |
| 175 | printf("\t-i or --infile: The file to read in.\n"); | 182 | printf("\t-i or --infile: The file to read in.\n"); |
