annotate dumpblocks.c @ 1:43e8802f08c5 debian libpst_0_5_1

imported from debian 0.5.1
author carl
date Thu, 23 Dec 2004 11:17:37 -0800
parents 6b1b602514db
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1 #include <stdio.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
2 #include <stdlib.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
3 #include <unistd.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
4 #include "libpst.h"
6b1b602514db Initial revision
carl
parents:
diff changeset
5 #include "define.h"
6b1b602514db Initial revision
carl
parents:
diff changeset
6
6b1b602514db Initial revision
carl
parents:
diff changeset
7 #define OUT_BUF 20
6b1b602514db Initial revision
carl
parents:
diff changeset
8 int main(int argc, char **argv) {
6b1b602514db Initial revision
carl
parents:
diff changeset
9 pst_file pstfile;
6b1b602514db Initial revision
carl
parents:
diff changeset
10 pst_index_ll *ptr;
6b1b602514db Initial revision
carl
parents:
diff changeset
11 char *outdir=NULL, *file=NULL, *outname=NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
12 unsigned char *buf=NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
13 int c;
6b1b602514db Initial revision
carl
parents:
diff changeset
14 FILE *fp;
6b1b602514db Initial revision
carl
parents:
diff changeset
15
6b1b602514db Initial revision
carl
parents:
diff changeset
16 while ((c=getopt(argc, argv, "o:"))!=-1) {
6b1b602514db Initial revision
carl
parents:
diff changeset
17 switch(c) {
6b1b602514db Initial revision
carl
parents:
diff changeset
18 case 'o':
6b1b602514db Initial revision
carl
parents:
diff changeset
19 outdir=optarg;
6b1b602514db Initial revision
carl
parents:
diff changeset
20 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
21 default:
6b1b602514db Initial revision
carl
parents:
diff changeset
22 printf("Unknown switch %c\n", c);
6b1b602514db Initial revision
carl
parents:
diff changeset
23 }
6b1b602514db Initial revision
carl
parents:
diff changeset
24 }
6b1b602514db Initial revision
carl
parents:
diff changeset
25 if (optind < argc) {
6b1b602514db Initial revision
carl
parents:
diff changeset
26 file = argv[optind];
6b1b602514db Initial revision
carl
parents:
diff changeset
27 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
28 printf("Usage: dumpblocks [options] pstfile\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
29 printf("\tcopies the datablocks from the pst file into seperate files\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
30 printf("Options: \n");
6b1b602514db Initial revision
carl
parents:
diff changeset
31 printf("\t-o target\tSpecify the output directory\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
32 exit(1);
6b1b602514db Initial revision
carl
parents:
diff changeset
33 }
6b1b602514db Initial revision
carl
parents:
diff changeset
34 DEBUG_INIT("dumpblocks.log");
6b1b602514db Initial revision
carl
parents:
diff changeset
35 DEBUG_REGISTER_CLOSE();
6b1b602514db Initial revision
carl
parents:
diff changeset
36 DEBUG_ENT("main");
6b1b602514db Initial revision
carl
parents:
diff changeset
37
6b1b602514db Initial revision
carl
parents:
diff changeset
38 printf("Opening file %s\n",file);
6b1b602514db Initial revision
carl
parents:
diff changeset
39 if (pst_open(&pstfile, file, "r")) {
6b1b602514db Initial revision
carl
parents:
diff changeset
40 printf("Failed to open file %s\n", file);
6b1b602514db Initial revision
carl
parents:
diff changeset
41 exit(1);
6b1b602514db Initial revision
carl
parents:
diff changeset
42 }
6b1b602514db Initial revision
carl
parents:
diff changeset
43
6b1b602514db Initial revision
carl
parents:
diff changeset
44 printf("Reading Indexes\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
45 if (pst_load_index(&pstfile)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
46 printf("Failed to load indexes in file %s\n", argv[1]);
6b1b602514db Initial revision
carl
parents:
diff changeset
47 exit(1);
6b1b602514db Initial revision
carl
parents:
diff changeset
48 }
6b1b602514db Initial revision
carl
parents:
diff changeset
49
6b1b602514db Initial revision
carl
parents:
diff changeset
50 if (outdir != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
51 if (chdir(outdir)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
52 printf("Failed to change into directory %s\n", outdir);
6b1b602514db Initial revision
carl
parents:
diff changeset
53 exit(1);
6b1b602514db Initial revision
carl
parents:
diff changeset
54 }
6b1b602514db Initial revision
carl
parents:
diff changeset
55
6b1b602514db Initial revision
carl
parents:
diff changeset
56 ptr = pstfile.i_head;
6b1b602514db Initial revision
carl
parents:
diff changeset
57 outname = (char*) xmalloc(OUT_BUF);
6b1b602514db Initial revision
carl
parents:
diff changeset
58 printf("Saving blocks\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
59 while (ptr != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
60 /* if (pstfile.encryption == PST_ENC) {
6b1b602514db Initial revision
carl
parents:
diff changeset
61 c = _pst_ff_getIDblock_dec(&pstfile, ptr->id, buf);
6b1b602514db Initial revision
carl
parents:
diff changeset
62 } else {*/
6b1b602514db Initial revision
carl
parents:
diff changeset
63 if ((ptr->id & 0x02)==0 && pstfile.encryption == PST_ENC) {
6b1b602514db Initial revision
carl
parents:
diff changeset
64 c = _pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf);
6b1b602514db Initial revision
carl
parents:
diff changeset
65 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
66 c = _pst_ff_getIDblock(&pstfile, ptr->id, &buf);
6b1b602514db Initial revision
carl
parents:
diff changeset
67 }
6b1b602514db Initial revision
carl
parents:
diff changeset
68
6b1b602514db Initial revision
carl
parents:
diff changeset
69 if (c > 0) {
6b1b602514db Initial revision
carl
parents:
diff changeset
70 snprintf(outname, OUT_BUF, "%x", ptr->id);
6b1b602514db Initial revision
carl
parents:
diff changeset
71 if ((fp = fopen(outname, "wb")) == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
72 printf("Failed to open file %s\n", outname);
6b1b602514db Initial revision
carl
parents:
diff changeset
73 continue;
6b1b602514db Initial revision
carl
parents:
diff changeset
74 }
6b1b602514db Initial revision
carl
parents:
diff changeset
75 fwrite(buf, 1, c, fp);
6b1b602514db Initial revision
carl
parents:
diff changeset
76 fclose(fp);
6b1b602514db Initial revision
carl
parents:
diff changeset
77 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
78 printf("Failed to read block id %#x\n", ptr->id);
6b1b602514db Initial revision
carl
parents:
diff changeset
79 }
6b1b602514db Initial revision
carl
parents:
diff changeset
80 ptr = ptr->next;
6b1b602514db Initial revision
carl
parents:
diff changeset
81 }
6b1b602514db Initial revision
carl
parents:
diff changeset
82 pst_close(&pstfile);
6b1b602514db Initial revision
carl
parents:
diff changeset
83 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
84 return 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
85 }