Mercurial > libpst
comparison src/libpst.c @ 188:d588dafd03e8 stable-0-6-36
prep for fedora build
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 14 Apr 2009 07:53:13 -0700 |
parents | 0a4f7ecd7452 |
children | e3a63888cdd4 |
comparison
equal
deleted
inserted
replaced
187:cf8bbbb746e7 | 188:d588dafd03e8 |
---|---|
170 | 170 |
171 static int pst_build_desc_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val); | 171 static int pst_build_desc_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val); |
172 static pst_id2_tree* pst_build_id2(pst_file *pf, pst_index_ll* list); | 172 static pst_id2_tree* pst_build_id2(pst_file *pf, pst_index_ll* list); |
173 static int pst_build_id_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val); | 173 static int pst_build_id_ptr(pst_file *pf, int64_t offset, int32_t depth, uint64_t linku1, uint64_t start_val, uint64_t end_val); |
174 static int pst_chr_count(char *str, char x); | 174 static int pst_chr_count(char *str, char x); |
175 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size); | 175 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t i_id, pst_holder *h, size_t size); |
176 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_tree *id2_head, char** buf); | 176 static size_t pst_ff_getID2block(pst_file *pf, uint64_t id2, pst_id2_tree *id2_head, char** buf); |
177 static size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h); | 177 static size_t pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, pst_holder *h); |
178 static void pst_free_attach(pst_item_attach *attach); | 178 static void pst_free_attach(pst_item_attach *attach); |
179 static void pst_free_desc (pst_desc_tree *head); | 179 static void pst_free_desc (pst_desc_tree *head); |
180 static void pst_free_id2(pst_id2_tree * head); | 180 static void pst_free_id2(pst_id2_tree * head); |
3597 DEBUG_RET(); | 3597 DEBUG_RET(); |
3598 return rsize; | 3598 return rsize; |
3599 } | 3599 } |
3600 | 3600 |
3601 | 3601 |
3602 int pst_decrypt(uint64_t id, char *buf, size_t size, unsigned char type) { | 3602 int pst_decrypt(uint64_t i_id, char *buf, size_t size, unsigned char type) { |
3603 size_t x = 0; | 3603 size_t x = 0; |
3604 unsigned char y; | 3604 unsigned char y; |
3605 DEBUG_ENT("pst_decrypt"); | 3605 DEBUG_ENT("pst_decrypt"); |
3606 if (!buf) { | 3606 if (!buf) { |
3607 DEBUG_RET(); | 3607 DEBUG_RET(); |
3617 } | 3617 } |
3618 | 3618 |
3619 } else if (type == PST_ENCRYPT) { | 3619 } else if (type == PST_ENCRYPT) { |
3620 // The following code was based on the information at | 3620 // The following code was based on the information at |
3621 // http://www.passcape.com/outlook_passwords.htm | 3621 // http://www.passcape.com/outlook_passwords.htm |
3622 uint16_t salt = (uint16_t) (((id & 0x00000000ffff0000) >> 16) ^ (id & 0x000000000000ffff)); | 3622 uint16_t salt = (uint16_t) (((i_id & 0x00000000ffff0000) >> 16) ^ (i_id & 0x000000000000ffff)); |
3623 x = 0; | 3623 x = 0; |
3624 while (x < size) { | 3624 while (x < size) { |
3625 uint8_t losalt = (salt & 0x00ff); | 3625 uint8_t losalt = (salt & 0x00ff); |
3626 uint8_t hisalt = (salt & 0xff00) >> 8; | 3626 uint8_t hisalt = (salt & 0xff00) >> 8; |
3627 y = (unsigned char)buf[x]; | 3627 y = (unsigned char)buf[x]; |
3724 | 3724 |
3725 /** | 3725 /** |
3726 * Get an ID block from file using _pst_ff_getIDblock and decrypt if necessary | 3726 * Get an ID block from file using _pst_ff_getIDblock and decrypt if necessary |
3727 * | 3727 * |
3728 * @param pf PST file structure | 3728 * @param pf PST file structure |
3729 * @param id ID of block to retrieve | 3729 * @param i_id ID of block to retrieve |
3730 * @param buf Reference to pointer that will be set to new block. Any memory | 3730 * @param buf reference to pointer to buffer that will contain the data block. |
3731 pointed to by buffer will be free()d beforehand | 3731 * If this pointer is non-NULL, it will first be free()d. |
3732 * @return Size of block pointed to by *b | 3732 * @return Size of block read into memory |
3733 */ | 3733 */ |
3734 size_t pst_ff_getIDblock_dec(pst_file *pf, uint64_t id, char **buf) { | 3734 size_t pst_ff_getIDblock_dec(pst_file *pf, uint64_t i_id, char **buf) { |
3735 size_t r; | 3735 size_t r; |
3736 int noenc = (int)(id & 2); // disable encryption | 3736 int noenc = (int)(i_id & 2); // disable encryption |
3737 DEBUG_ENT("pst_ff_getIDblock_dec"); | 3737 DEBUG_ENT("pst_ff_getIDblock_dec"); |
3738 DEBUG_INDEX(("for id %#"PRIi64"\n", id)); | 3738 DEBUG_INDEX(("for id %#"PRIi64"\n", i_id)); |
3739 r = pst_ff_getIDblock(pf, id, buf); | 3739 r = pst_ff_getIDblock(pf, i_id, buf); |
3740 if ((pf->encryption) && !(noenc)) { | 3740 if ((pf->encryption) && !(noenc)) { |
3741 (void)pst_decrypt(id, *buf, r, pf->encryption); | 3741 (void)pst_decrypt(i_id, *buf, r, pf->encryption); |
3742 } | 3742 } |
3743 DEBUG_HEXDUMPC(*buf, r, 16); | 3743 DEBUG_HEXDUMPC(*buf, r, 16); |
3744 DEBUG_RET(); | 3744 DEBUG_RET(); |
3745 return r; | 3745 return r; |
3746 } | 3746 } |
3747 | 3747 |
3748 | 3748 |
3749 /** | 3749 /** |
3750 * Read a block of data from file into memory | 3750 * Read a block of data from file into memory |
3751 * @param pf PST file | 3751 * @param pf PST file structure |
3752 * @param id identifier of block to read | 3752 * @param i_id ID of block to read |
3753 * @param buf reference to pointer to buffer. If this pointer | 3753 * @param buf reference to pointer to buffer that will contain the data block. |
3754 is non-NULL, it will first be free()d | 3754 * If this pointer is non-NULL, it will first be free()d. |
3755 * @return size of block read into memory | 3755 * @return size of block read into memory |
3756 */ | 3756 */ |
3757 size_t pst_ff_getIDblock(pst_file *pf, uint64_t id, char** buf) { | 3757 size_t pst_ff_getIDblock(pst_file *pf, uint64_t i_id, char** buf) { |
3758 pst_index_ll *rec; | 3758 pst_index_ll *rec; |
3759 size_t rsize; | 3759 size_t rsize; |
3760 DEBUG_ENT("pst_ff_getIDblock"); | 3760 DEBUG_ENT("pst_ff_getIDblock"); |
3761 rec = pst_getID(pf, id); | 3761 rec = pst_getID(pf, i_id); |
3762 if (!rec) { | 3762 if (!rec) { |
3763 DEBUG_INDEX(("Cannot find ID %#"PRIx64"\n", id)); | 3763 DEBUG_INDEX(("Cannot find ID %#"PRIx64"\n", i_id)); |
3764 DEBUG_RET(); | 3764 DEBUG_RET(); |
3765 return 0; | 3765 return 0; |
3766 } | 3766 } |
3767 DEBUG_INDEX(("id = %#"PRIx64", record size = %#x, offset = %#x\n", id, rec->size, rec->offset)); | 3767 DEBUG_INDEX(("id = %#"PRIx64", record size = %#x, offset = %#x\n", i_id, rec->size, rec->offset)); |
3768 rsize = pst_read_block_size(pf, rec->offset, rec->size, buf); | 3768 rsize = pst_read_block_size(pf, rec->offset, rec->size, buf); |
3769 DEBUG_RET(); | 3769 DEBUG_RET(); |
3770 return rsize; | 3770 return rsize; |
3771 } | 3771 } |
3772 | 3772 |
3819 DEBUG_RET(); | 3819 DEBUG_RET(); |
3820 return ret; | 3820 return ret; |
3821 } | 3821 } |
3822 | 3822 |
3823 | 3823 |
3824 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t id, pst_holder *h, size_t size) { | 3824 static size_t pst_ff_compile_ID(pst_file *pf, uint64_t i_id, pst_holder *h, size_t size) { |
3825 size_t z, a; | 3825 size_t z, a; |
3826 uint16_t count, y; | 3826 uint16_t count, y; |
3827 char *buf3 = NULL, *buf2 = NULL, *t; | 3827 char *buf3 = NULL, *buf2 = NULL, *t; |
3828 char *b_ptr; | 3828 char *b_ptr; |
3829 int line_count = 0; | 3829 int line_count = 0; |
3831 uint32_t base64_extra = 0; | 3831 uint32_t base64_extra = 0; |
3832 pst_block_hdr block_hdr; | 3832 pst_block_hdr block_hdr; |
3833 pst_table3_rec table3_rec; //for type 3 (0x0101) blocks | 3833 pst_table3_rec table3_rec; //for type 3 (0x0101) blocks |
3834 | 3834 |
3835 DEBUG_ENT("pst_ff_compile_ID"); | 3835 DEBUG_ENT("pst_ff_compile_ID"); |
3836 a = pst_ff_getIDblock(pf, id, &buf3); | 3836 a = pst_ff_getIDblock(pf, i_id, &buf3); |
3837 if (!a) { | 3837 if (!a) { |
3838 if (buf3) free(buf3); | 3838 if (buf3) free(buf3); |
3839 DEBUG_RET(); | 3839 DEBUG_RET(); |
3840 return 0; | 3840 return 0; |
3841 } | 3841 } |
3846 LE32_CPU(block_hdr.offset); | 3846 LE32_CPU(block_hdr.offset); |
3847 DEBUG_EMAIL(("block header (index_offset=%#hx, type=%#hx, offset=%#x)\n", block_hdr.index_offset, block_hdr.type, block_hdr.offset)); | 3847 DEBUG_EMAIL(("block header (index_offset=%#hx, type=%#hx, offset=%#x)\n", block_hdr.index_offset, block_hdr.type, block_hdr.offset)); |
3848 | 3848 |
3849 if (block_hdr.index_offset != (uint16_t)0x0101) { //type 3 | 3849 if (block_hdr.index_offset != (uint16_t)0x0101) { //type 3 |
3850 DEBUG_WARN(("WARNING: not a type 0x0101 buffer, Treating as normal buffer\n")); | 3850 DEBUG_WARN(("WARNING: not a type 0x0101 buffer, Treating as normal buffer\n")); |
3851 if (pf->encryption) (void)pst_decrypt(id, buf3, a, pf->encryption); | 3851 if (pf->encryption) (void)pst_decrypt(i_id, buf3, a, pf->encryption); |
3852 if (h->buf) | 3852 if (h->buf) |
3853 *(h->buf) = buf3; | 3853 *(h->buf) = buf3; |
3854 else if (h->base64 == 1 && h->fp) { | 3854 else if (h->base64 == 1 && h->fp) { |
3855 t = pst_base64_encode(buf3, a); | 3855 t = pst_base64_encode(buf3, a); |
3856 if (t) { | 3856 if (t) { |