00001 #include "define.h"
00002
00003 #define OUT_BUF 20
00004
00005 int main(int argc, char* const* argv)
00006 {
00007 pst_file pstfile;
00008 pst_index_ll *ptr;
00009 char *outdir = NULL, *file = NULL, *outname = NULL;
00010 char *buf = NULL;
00011 int c;
00012 FILE *fp;
00013
00014 while ((c = getopt(argc, argv, "o:")) != -1) {
00015 switch (c) {
00016 case 'o':
00017 outdir = optarg;
00018 break;
00019 default:
00020 printf("Unknown switch %c\n", c);
00021 }
00022 }
00023 if (optind < argc) {
00024 file = argv[optind];
00025 } else {
00026 printf("Usage: dumpblocks [options] pstfile\n");
00027 printf("\tcopies the datablocks from the pst file into separate files\n");
00028 printf("Options: \n");
00029 printf("\t-o target\tSpecify the output directory\n");
00030 exit(1);
00031 }
00032 DEBUG_INIT("dumpblocks.log");
00033 DEBUG_REGISTER_CLOSE();
00034 DEBUG_ENT("main");
00035
00036 printf("Opening file %s\n", file);
00037 if (pst_open(&pstfile, file)) {
00038 printf("Failed to open file %s\n", file);
00039 exit(1);
00040 }
00041
00042 printf("Reading Indexes\n");
00043 if (pst_load_index(&pstfile)) {
00044 printf("Failed to load indexes in file %s\n", argv[1]);
00045 exit(1);
00046 }
00047
00048 if (outdir != NULL)
00049 if (chdir(outdir)) {
00050 printf("Failed to change into directory %s\n", outdir);
00051 exit(1);
00052 }
00053
00054 ptr = pstfile.i_head;
00055 outname = (char *) xmalloc(OUT_BUF);
00056 printf("Saving blocks\n");
00057 while (ptr != NULL) {
00058
00059
00060
00061 if ((ptr->id & 0x02) == 0 && pstfile.encryption == PST_ENC) {
00062 c = pst_ff_getIDblock_dec(&pstfile, ptr->id, &buf);
00063 } else {
00064 c = pst_ff_getIDblock(&pstfile, ptr->id, &buf);
00065 }
00066
00067 if (c > 0) {
00068 snprintf(outname, OUT_BUF, "%#"PRIx64, ptr->id);
00069 if ((fp = fopen(outname, "wb")) == NULL) {
00070 printf("Failed to open file %s\n", outname);
00071 continue;
00072 }
00073 pst_fwrite(buf, 1, c, fp);
00074 fclose(fp);
00075 } else {
00076 printf("Failed to read block id %#"PRIx64"\n", ptr->id);
00077 }
00078 ptr = ptr->next;
00079 }
00080 pst_close(&pstfile);
00081 DEBUG_RET();
00082 return 0;
00083 }