summaryrefslogtreecommitdiffstats
path: root/dev/plutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'dev/plutil.c')
-rw-r--r--dev/plutil.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/dev/plutil.c b/dev/plutil.c
index e76506e..3d93797 100644
--- a/dev/plutil.c
+++ b/dev/plutil.c
@@ -14,9 +14,7 @@
14int main(int argc, char *argv[]) 14int main(int argc, char *argv[])
15{ 15{
16 struct stat *filestats = (struct stat *) malloc(sizeof(struct stat)); 16 struct stat *filestats = (struct stat *) malloc(sizeof(struct stat));
17 uint32_t position = 0;
18 Options *options = parse_arguments(argc, argv); 17 Options *options = parse_arguments(argc, argv);
19 int argh = 0;
20 18
21 if (!options) { 19 if (!options) {
22 print_usage(); 20 print_usage();
@@ -25,29 +23,42 @@ int main(int argc, char *argv[])
25 23
26 iphone_set_debug(options->debug); 24 iphone_set_debug(options->debug);
27 25
28 FILE *bplist = fopen(options->in_file, "r"); 26 //read input file
29 27 FILE *iplist = fopen(options->in_file, "r");
28 if (!iplist)
29 return 1;
30 stat(options->in_file, filestats); 30 stat(options->in_file, filestats);
31 char *plist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1));
32 fread(plist_entire, sizeof(char), filestats->st_size, iplist);
33 fclose(iplist);
31 34
32 char *bplist_entire = (char *) malloc(sizeof(char) * (filestats->st_size + 1));
33 argh = fread(bplist_entire, sizeof(char), filestats->st_size, bplist);
34 fclose(bplist);
35 // bplist_entire contains our stuff
36 35
36 //convert one format to another
37 plist_t root_node = NULL; 37 plist_t root_node = NULL;
38 char *plist_out = NULL; 38 char *plist_out = NULL;
39 int size = 0; 39 int size = 0;
40 40
41 if (memcmp(bplist_entire, "bplist00", 8) == 0) { 41 if (memcmp(plist_entire, "bplist00", 8) == 0) {
42 bin_to_plist(bplist_entire, filestats->st_size, &root_node); 42 bin_to_plist(plist_entire, filestats->st_size, &root_node);
43 plist_to_xml(root_node, &plist_out, &size); 43 plist_to_xml(root_node, &plist_out, &size);
44 } else { 44 } else {
45 xml_to_plist(bplist_entire, filestats->st_size, &root_node); 45 xml_to_plist(plist_entire, filestats->st_size, &root_node);
46 plist_to_bin(root_node, &plist_out, &size); 46 plist_to_bin(root_node, &plist_out, &size);
47 } 47 }
48 48
49 49 if (plist_out) {
50 printf("%s\n", plist_out); 50 if (options->out_file != NULL) {
51 FILE *oplist = fopen(options->out_file, "wb");
52 if (!oplist)
53 return 1;
54 fwrite(plist_out, size, sizeof(char), oplist);
55 fclose(oplist);
56 }
57 //if no output file specified, write to stdout
58 else
59 fwrite(plist_out, size, sizeof(char), stdout);
60 } else
61 printf("ERROR\n");
51 return 0; 62 return 0;
52} 63}
53 64