diff options
| author | 2008-08-31 11:25:22 -0700 | |
|---|---|---|
| committer | 2008-11-24 22:49:07 +0100 | |
| commit | f4c4b783c8dbe2fe8e7e6f6b5f19f0d44b489c9a (patch) | |
| tree | 9ef8c57fe298a4ae9e0a443d7103e6126c869020 /dev/plutil.c | |
| parent | 8c3a01e11bb9c74e2a1bb7da143cb35469f29fba (diff) | |
| download | libimobiledevice-f4c4b783c8dbe2fe8e7e6f6b5f19f0d44b489c9a.tar.gz libimobiledevice-f4c4b783c8dbe2fe8e7e6f6b5f19f0d44b489c9a.tar.bz2 | |
Added binary-plist support (tweaked slightly to move stuff around)
Signed-off-by: Matt Colyer <matt@colyer.name>
fix makefile to take correct main function into account
Diffstat (limited to 'dev/plutil.c')
| -rw-r--r-- | dev/plutil.c | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/dev/plutil.c b/dev/plutil.c new file mode 100644 index 0000000..208d7df --- /dev/null +++ b/dev/plutil.c | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | /* | ||
| 2 | * main.c for plistutil | ||
| 3 | * right now just prints debug shit | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include "../src/plist.h" | ||
| 7 | #include "plutil.h" | ||
| 8 | |||
| 9 | int debug = 0; | ||
| 10 | |||
| 11 | void print_nodes(bplist_node *root_node) { | ||
| 12 | // Yay, great. Let's print the list of nodes recursively... | ||
| 13 | int i = 0; | ||
| 14 | if (!root_node) return; // or not, because the programmer's stupid. | ||
| 15 | |||
| 16 | switch (root_node->type) { | ||
| 17 | case BPLIST_DICT: | ||
| 18 | printf("Dictionary node.\nLength %i\n", root_node->length); | ||
| 19 | for (i = 0; i < (root_node->length * 2); i+=2) { | ||
| 20 | // HI! | ||
| 21 | printf("Key: "); | ||
| 22 | print_nodes(root_node->subnodes[i]); | ||
| 23 | printf("Value: "); | ||
| 24 | print_nodes(root_node->subnodes[i+1]); | ||
| 25 | } | ||
| 26 | printf("End dictionary node.\n\n"); | ||
| 27 | break; | ||
| 28 | |||
| 29 | case BPLIST_ARRAY: | ||
| 30 | printf("Array node.\n"); | ||
| 31 | for (i = 0; i < root_node->length; i++) { | ||
| 32 | printf("\tElement %i: ", i); | ||
| 33 | print_nodes(root_node->subnodes[i]); | ||
| 34 | } | ||
| 35 | break; | ||
| 36 | |||
| 37 | case BPLIST_INT: | ||
| 38 | if (root_node->length == sizeof(uint8_t)) { | ||
| 39 | printf("Integer: %i\n", root_node->intval8); | ||
| 40 | } else if (root_node->length == sizeof(uint16_t)) { | ||
| 41 | printf("Integer: %i\n", root_node->intval16); | ||
| 42 | } else if (root_node->length == sizeof(uint32_t)) { | ||
| 43 | printf("Integer: %i\n", root_node->intval32); | ||
| 44 | } | ||
| 45 | break; | ||
| 46 | |||
| 47 | case BPLIST_STRING: | ||
| 48 | case BPLIST_DATA: | ||
| 49 | printf("String/data: "); | ||
| 50 | fwrite(root_node->strval, sizeof(char), root_node->length, stdout); | ||
| 51 | fflush(stdout); | ||
| 52 | printf("\n"); | ||
| 53 | break; | ||
| 54 | |||
| 55 | case BPLIST_UNICODE: | ||
| 56 | printf("Unicode data, may appear crappy: "); | ||
| 57 | fwrite(root_node->unicodeval, sizeof(wchar_t), root_node->length, stdout); | ||
| 58 | fflush(stdout); | ||
| 59 | printf("\n"); | ||
| 60 | break; | ||
| 61 | |||
| 62 | case BPLIST_TRUE: | ||
| 63 | printf("True.\n"); | ||
| 64 | break; | ||
| 65 | |||
| 66 | case BPLIST_FALSE: | ||
| 67 | printf("False.\n"); | ||
| 68 | break; | ||
| 69 | |||
| 70 | case BPLIST_REAL: | ||
| 71 | case BPLIST_DATE: | ||
| 72 | printf("Real(?): %f\n", root_node->realval); | ||
| 73 | break; | ||
| 74 | |||
| 75 | default: | ||
| 76 | printf("oops\nType set to %x and length is %i\n", root_node->type, root_node->length); | ||
| 77 | break; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | int main(int argc, char *argv[]) { | ||
| 82 | struct stat *filestats = (struct stat *)malloc(sizeof(struct stat)); | ||
| 83 | uint32_t position = 0; | ||
| 84 | Options *options = parse_arguments(argc, argv); | ||
| 85 | int argh = 0; | ||
| 86 | |||
| 87 | printf("plistutil version 0.2 written by FxChiP\n"); | ||
| 88 | |||
| 89 | if (!options) { | ||
| 90 | print_usage(); | ||
| 91 | return 0; | ||
| 92 | } | ||
| 93 | |||
| 94 | debug = options->debug; | ||
| 95 | |||
| 96 | FILE *bplist = fopen(options->in_file, "r"); | ||
| 97 | |||
| 98 | stat(options->in_file, filestats); | ||
| 99 | |||
| 100 | printf("here?\n"); | ||
| 101 | char *bplist_entire = (char*)malloc(sizeof(char) * (filestats->st_size + 1)); | ||
| 102 | //argh = fgets(bplist_entire, filestats->st_size, bplist); | ||
| 103 | argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist); | ||
| 104 | printf("read %i bytes\n", argh); | ||
| 105 | fclose(bplist); | ||
| 106 | printf("or here?\n"); | ||
| 107 | // bplist_entire contains our stuff | ||
| 108 | bplist_node *root_node; | ||
| 109 | root_node = parse_nodes(bplist_entire, filestats->st_size, &position); | ||
| 110 | printf("plutil debug mode\n\n"); | ||
| 111 | printf("file size %i\n\n", filestats->st_size); | ||
| 112 | if (!root_node) { | ||
| 113 | printf("Invalid binary plist (or some other error occurred.)\n"); | ||
| 114 | return 0; | ||
| 115 | } | ||
| 116 | print_nodes(root_node); | ||
| 117 | return 0; | ||
| 118 | } | ||
| 119 | |||
| 120 | Options *parse_arguments(int argc, char *argv[]) { | ||
| 121 | int i = 0; | ||
| 122 | |||
| 123 | Options *options = (Options*)malloc(sizeof(Options)); | ||
| 124 | memset(options, 0, sizeof(Options)); | ||
| 125 | |||
| 126 | for (i = 1; i < argc; i++) { | ||
| 127 | if (!strcmp(argv[i], "--infile") || !strcmp(argv[i], "-i")) { | ||
| 128 | if ((i+1) == argc) { | ||
| 129 | free(options); | ||
| 130 | return NULL; | ||
| 131 | } | ||
| 132 | options->in_file = argv[i+1]; | ||
| 133 | i++; | ||
| 134 | continue; | ||
| 135 | } | ||
| 136 | |||
| 137 | if (!strcmp(argv[i], "--outfile") || !strcmp(argv[i], "-o")) { | ||
| 138 | if ((i+1) == argc) { | ||
| 139 | free(options); | ||
| 140 | return NULL; | ||
| 141 | } | ||
| 142 | options->out_file = argv[i+1]; | ||
| 143 | i++; | ||
| 144 | continue; | ||
| 145 | } | ||
| 146 | |||
| 147 | if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-d") || !strcmp(argv[i], "-v")) { | ||
| 148 | options->debug = 1; | ||
| 149 | } | ||
| 150 | |||
| 151 | if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { | ||
| 152 | free(options); | ||
| 153 | return NULL; | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | if (!options->in_file /*|| !options->out_file*/) { | ||
| 158 | free(options); | ||
| 159 | return NULL; | ||
| 160 | } | ||
| 161 | |||
| 162 | return options; | ||
| 163 | } | ||
| 164 | |||
| 165 | void print_usage() { | ||
| 166 | printf("Usage: plistutil -i|--infile in_file.plist -o|--outfile out_file.plist [--debug]\n"); | ||
| 167 | printf("\n"); | ||
| 168 | printf("\t-i or --infile: The file to read in.\n"); | ||
| 169 | printf("\t-o or --outfile: The file to convert to.\n"); | ||
| 170 | printf("\t-d, -v or --debug: Provide extended debug information.\n\n"); | ||
| 171 | } | ||
