Mercurial > libpst
annotate src/dumpblocks.c @ 59:7d5c637aaafb
General cleanup and code fixes.
Use autoscan to cleanup our autoconf system.
Use autoconf to detect when we need to use our XGetopt files and other header files.
Decode BCC field.
Fix missing LE32_CPU byte swapping for FILETIME types.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 14 Feb 2008 14:55:32 -0800 |
parents | 034641c26ab9 |
children | 3cb02cb1e6cd |
rev | line source |
---|---|
48 | 1 #include "define.h" |
2 | |
16 | 3 #include <stdio.h> |
4 #include <stdlib.h> | |
5 #include <unistd.h> | |
6 #include "libpst.h" | |
7 | |
8 #define OUT_BUF 20 | |
9 int main(int argc, char **argv) { | |
10 pst_file pstfile; | |
11 pst_index_ll *ptr; | |
12 char *outdir=NULL, *file=NULL, *outname=NULL; | |
52 | 13 char *buf=NULL; |
16 | 14 int c; |
15 FILE *fp; | |
16 | |
17 while ((c=getopt(argc, argv, "o:"))!=-1) { | |
18 switch(c) { | |
19 case 'o': | |
20 outdir=optarg; | |
21 break; | |
22 default: | |
23 printf("Unknown switch %c\n", c); | |
24 } | |
25 } | |
26 if (optind < argc) { | |
27 file = argv[optind]; | |
28 } else { | |
29 printf("Usage: dumpblocks [options] pstfile\n"); | |
30 printf("\tcopies the datablocks from the pst file into seperate files\n"); | |
31 printf("Options: \n"); | |
32 printf("\t-o target\tSpecify the output directory\n"); | |
33 exit(1); | |
34 } | |
35 DEBUG_INIT("dumpblocks.log"); | |
36 DEBUG_REGISTER_CLOSE(); | |
37 DEBUG_ENT("main"); | |
46 | 38 |
16 | 39 printf("Opening file %s\n",file); |
59
7d5c637aaafb
General cleanup and code fixes.
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
40 if (pst_open(&pstfile, file)) { |
16 | 41 printf("Failed to open file %s\n", file); |
42 exit(1); | |
43 } | |
44 | |
45 printf("Reading Indexes\n"); | |
46 if (pst_load_index(&pstfile)) { | |
47 printf("Failed to load indexes in file %s\n", argv[1]); | |
48 exit(1); | |
49 } | |
46 | 50 |
16 | 51 if (outdir != NULL) |
52 if (chdir(outdir)) { | |
53 printf("Failed to change into directory %s\n", outdir); | |
54 exit(1); | |
55 } | |
46 | 56 |
16 | 57 ptr = pstfile.i_head; |
58 outname = (char*) xmalloc(OUT_BUF); | |
59 printf("Saving blocks\n"); | |
60 while (ptr != NULL) { | |
61 /* if (pstfile.encryption == PST_ENC) { | |
46 | 62 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, buf); |
16 | 63 } else {*/ |
64 if ((ptr->id & 0x02)==0 && pstfile.encryption == PST_ENC) { | |
46 | 65 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf); |
16 | 66 } else { |
46 | 67 c = pst_ff_getIDblock(&pstfile, ptr->id, &buf); |
16 | 68 } |
69 | |
70 if (c > 0) { | |
46 | 71 snprintf(outname, OUT_BUF, "%llx", ptr->id); |
16 | 72 if ((fp = fopen(outname, "wb")) == NULL) { |
73 printf("Failed to open file %s\n", outname); | |
74 continue; | |
75 } | |
76 fwrite(buf, 1, c, fp); | |
77 fclose(fp); | |
78 } else { | |
46 | 79 printf("Failed to read block id %#llx\n", ptr->id); |
16 | 80 } |
81 ptr = ptr->next; | |
82 } | |
83 pst_close(&pstfile); | |
84 DEBUG_RET(); | |
85 return 0; | |
86 } |