comparison src/libpst.h @ 43:f6db1f060a95

start on outlook 2003 64 bit format
author carl
date Sun, 06 Jan 2008 14:47:06 -0800
parents 183ae993b9ad
children d4606d460daf
comparison
equal deleted inserted replaced
42:7a97f50c39c5 43:f6db1f060a95
8 // Dave Smith - davesmith@users.sourceforge.net 8 // Dave Smith - davesmith@users.sourceforge.net
9 9
10 #ifndef LIBPST_H 10 #ifndef LIBPST_H
11 #define LIBPST_H 11 #define LIBPST_H
12 12
13 #include <stdint.h>
14
13 #ifndef _MSC_VER 15 #ifndef _MSC_VER
14 16
15 #ifndef FILETIME_DEFINED 17 #ifndef FILETIME_DEFINED
16 #define FILETIME_DEFINED 18 #define FILETIME_DEFINED
17 //Win32 Filetime struct - copied from WINE 19 //Win32 Filetime struct - copied from WINE
18 typedef struct { 20 typedef struct {
19 u_int32_t dwLowDateTime; 21 uint32_t dwLowDateTime;
20 u_int32_t dwHighDateTime; 22 uint32_t dwHighDateTime;
21 } FILETIME; 23 } FILETIME;
22 #endif //ifndef FILETIME_DEFINED 24 #endif //ifndef FILETIME_DEFINED
23 #endif //ifndef _MSC_VER 25 #endif //ifndef _MSC_VER
24
25 // define the INT32_MAX here cause it isn't normally defined
26 #ifndef INT32_MAX
27 # define INT32_MAX INT_MAX
28 #endif
29 26
30 // According to Jan Wolter, sys/param.h is the most portable source of endian 27 // According to Jan Wolter, sys/param.h is the most portable source of endian
31 // information on UNIX systems. see http://www.unixpapa.com/incnote/byteorder.html 28 // information on UNIX systems. see http://www.unixpapa.com/incnote/byteorder.html
32 #ifdef _MSC_VER 29 #ifdef _MSC_VER
33 #define BYTE_ORDER LITTLE_ENDIAN 30 #define BYTE_ORDER LITTLE_ENDIAN
63 60
64 61
65 #ifdef _MSC_VER 62 #ifdef _MSC_VER
66 #include "windows.h" 63 #include "windows.h"
67 #define int32_t int 64 #define int32_t int
68 #define u_int32_t unsigned int 65 #define uint32_t unsigned int
69 #define int16_t short int 66 #define int16_t short int
70 #define u_int16_t unsigned short int 67 #define uint16_t unsigned short int
71 #endif // _MSC_VER 68 #endif // _MSC_VER
72 69
73 #define PST_TYPE_NOTE 1 70 #define PST_TYPE_NOTE 1
74 #define PST_TYPE_APPOINTMENT 8 71 #define PST_TYPE_APPOINTMENT 8
75 #define PST_TYPE_CONTACT 9 72 #define PST_TYPE_CONTACT 9
112 #define PST_APP_LABEL_NEEDS_PREP 7 // Needs Preparation 109 #define PST_APP_LABEL_NEEDS_PREP 7 // Needs Preparation
113 #define PST_APP_LABEL_BIRTHDAY 8 // Birthday 110 #define PST_APP_LABEL_BIRTHDAY 8 // Birthday
114 #define PST_APP_LABEL_ANNIVERSARY 9 // Anniversary 111 #define PST_APP_LABEL_ANNIVERSARY 9 // Anniversary
115 #define PST_APP_LABEL_PHONE_CALL 10// Phone Call 112 #define PST_APP_LABEL_PHONE_CALL 10// Phone Call
116 113
114 extern int do_read64;
115
117 typedef struct _pst_misc_6_struct { 116 typedef struct _pst_misc_6_struct {
118 int32_t i1; 117 int32_t i1;
119 int32_t i2; 118 int32_t i2;
120 int32_t i3; 119 int32_t i3;
121 int32_t i4; 120 int32_t i4;
124 } pst_misc_6; 123 } pst_misc_6;
125 124
126 typedef struct _pst_entryid_struct { 125 typedef struct _pst_entryid_struct {
127 int32_t u1; 126 int32_t u1;
128 char entryid[16]; 127 char entryid[16];
129 u_int32_t id; 128 uint32_t id;
130 } pst_entryid; 129 } pst_entryid;
131 130
132 typedef struct _pst_desc_struct { 131 typedef struct _pst_desc_struct32 {
133 u_int32_t d_id; 132 uint32_t d_id;
134 u_int32_t desc_id; 133 uint32_t desc_id;
135 u_int32_t list_id; 134 uint32_t list_id;
136 u_int32_t parent_id; 135 uint32_t parent_id;
137 } pst_desc; 136 } pst_desc32;
138 137
139 typedef struct _pst_index_struct{ 138 typedef struct _pst_desc_structn {
140 u_int32_t id; 139 uint64_t d_id;
141 int32_t offset; 140 uint64_t desc_id;
142 u_int16_t size; 141 uint64_t list_id;
143 int16_t u1; 142 uint32_t parent_id; // not 64 bit ??
143 uint32_t u1; // padding
144 } pst_descn;
145
146 typedef struct _pst_index_struct32 {
147 uint32_t id;
148 int32_t offset;
149 uint16_t size;
150 int16_t u1;
151 } pst_index32;
152
153 typedef struct _pst_index_struct {
154 uint64_t id;
155 int64_t offset;
156 uint16_t size;
157 int16_t u0;
158 int32_t u1;
144 } pst_index; 159 } pst_index;
145 160
161 typedef struct _pst_index_tree32 {
162 uint32_t id;
163 int32_t offset;
164 int32_t size;
165 int32_t u1;
166 struct _pst_index_tree * next;
167 } pst_index_ll32;
168
146 typedef struct _pst_index_tree { 169 typedef struct _pst_index_tree {
147 u_int32_t id; 170 uint64_t id;
148 int32_t offset; 171 int64_t offset;
149 size_t size; 172 int64_t size;
150 int32_t u1; 173 int64_t u1;
151 struct _pst_index_tree * next; 174 struct _pst_index_tree * next;
152 } pst_index_ll; 175 } pst_index_ll;
153 176
154 typedef struct _pst_index2_tree { 177 typedef struct _pst_index2_tree {
155 u_int32_t id2; 178 uint32_t id2;
156 pst_index_ll *id; 179 pst_index_ll *id;
157 struct _pst_index2_tree * next; 180 struct _pst_index2_tree * next;
158 } pst_index2_ll; 181 } pst_index2_ll;
159 182
160 typedef struct _pst_desc_tree { 183 typedef struct _pst_desc_tree {
161 u_int32_t id; 184 uint32_t id;
162 pst_index_ll * list_index; 185 pst_index_ll * list_index;
163 pst_index_ll * desc; 186 pst_index_ll * desc;
164 int32_t no_child; 187 int32_t no_child;
165 struct _pst_desc_tree * prev; 188 struct _pst_desc_tree * prev;
166 struct _pst_desc_tree * next; 189 struct _pst_desc_tree * next;
170 } pst_desc_ll; 193 } pst_desc_ll;
171 194
172 typedef struct _pst_item_email_subject { 195 typedef struct _pst_item_email_subject {
173 int32_t off1; 196 int32_t off1;
174 int32_t off2; 197 int32_t off2;
175 char *subj; 198 char *subj;
176 } pst_item_email_subject; 199 } pst_item_email_subject;
177 200
178 typedef struct _pst_item_email { 201 typedef struct _pst_item_email {
179 FILETIME *arrival_date; 202 FILETIME *arrival_date;
180 int32_t autoforward; // 1 = true, 0 = not set, -1 = false 203 int32_t autoforward; // 1 = true, 0 = not set, -1 = false
216 char *return_path_address; 239 char *return_path_address;
217 int32_t rtf_body_char_count; 240 int32_t rtf_body_char_count;
218 int32_t rtf_body_crc; 241 int32_t rtf_body_crc;
219 char *rtf_body_tag; 242 char *rtf_body_tag;
220 char *rtf_compressed; 243 char *rtf_compressed;
221 u_int32_t rtf_compressed_size; 244 uint32_t rtf_compressed_size;
222 int32_t rtf_in_sync; // 1 = true, 0 = doesn't exist, -1 = false 245 int32_t rtf_in_sync; // 1 = true, 0 = doesn't exist, -1 = false
223 int32_t rtf_ws_prefix_count; 246 int32_t rtf_ws_prefix_count;
224 int32_t rtf_ws_trailing_count; 247 int32_t rtf_ws_trailing_count;
225 char *sender_access; 248 char *sender_access;
226 char *sender_address; 249 char *sender_address;
381 int32_t label; 404 int32_t label;
382 int32_t all_day; 405 int32_t all_day;
383 } pst_item_appointment; 406 } pst_item_appointment;
384 407
385 typedef struct _pst_item { 408 typedef struct _pst_item {
386 struct _pst_item_email *email; // data reffering to email 409 struct _pst_item_email *email; // data reffering to email
387 struct _pst_item_folder *folder; // data reffering to folder 410 struct _pst_item_folder *folder; // data reffering to folder
388 struct _pst_item_contact *contact; // data reffering to contact 411 struct _pst_item_contact *contact; // data reffering to contact
389 struct _pst_item_attach *attach; // linked list of attachments 412 struct _pst_item_attach *attach; // linked list of attachments
390 struct _pst_item_message_store * message_store; // data referring to the message store 413 struct _pst_item_message_store *message_store; // data referring to the message store
391 struct _pst_item_extra_field *extra_fields; // linked list of extra headers and such 414 struct _pst_item_extra_field *extra_fields; // linked list of extra headers and such
392 struct _pst_item_journal *journal; // data reffering to a journal entry 415 struct _pst_item_journal *journal; // data reffering to a journal entry
393 struct _pst_item_appointment *appointment; // data reffering to a calendar entry 416 struct _pst_item_appointment *appointment; // data reffering to a calendar entry
394 int32_t type; 417 int32_t type;
395 char *ascii_type; 418 char *ascii_type;
396 char *file_as; 419 char *file_as;
397 char *comment; 420 char *comment;
398 int32_t message_size; 421 int32_t message_size;
399 char *outlook_version; 422 char *outlook_version;
400 char *record_key; // probably 16 bytes long. 423 char *record_key; // probably 16 bytes long.
401 size_t record_key_size; 424 size_t record_key_size;
402 int32_t response_requested; 425 int32_t response_requested;
403 FILETIME *create_date; 426 FILETIME *create_date;
404 FILETIME *modify_date; 427 FILETIME *modify_date;
405 int32_t private_member; 428 int32_t private_member;
406 } pst_item; 429 } pst_item;
407 430
408 typedef struct _pst_x_attrib_ll { 431 typedef struct _pst_x_attrib_ll {
409 int32_t type; 432 int32_t type;
410 int32_t mytype; 433 int32_t mytype;
420 pst_x_attrib_ll *x_head; 443 pst_x_attrib_ll *x_head;
421 int32_t index1; 444 int32_t index1;
422 int32_t index1_count; 445 int32_t index1_count;
423 int32_t index2; 446 int32_t index2;
424 int32_t index2_count; 447 int32_t index2_count;
448 int64_t index1_64;
449 int64_t index1_count_64;
450 int64_t index2_64;
451 int64_t index2_count_64;
425 FILE * fp; // file pointer to opened PST file 452 FILE * fp; // file pointer to opened PST file
426 size_t size; // pst file size 453 size_t size; // pst file size
427 unsigned char encryption; // pst encryption setting 454 unsigned char encryption; // pst encryption setting
428 unsigned char ind_type; // pst index type 455 unsigned char ind_type; // pst index type
429 } pst_file; 456 } pst_file;
438 unsigned char *to; 465 unsigned char *to;
439 int needfree; 466 int needfree;
440 } pst_block_offset_pointer; 467 } pst_block_offset_pointer;
441 468
442 struct _pst_num_item { 469 struct _pst_num_item {
443 u_int32_t id; 470 uint32_t id;
444 unsigned char *data; 471 unsigned char *data;
445 int32_t type; 472 int32_t type;
446 size_t size; 473 size_t size;
447 char *extra; 474 char *extra;
448 }; 475 };
462 char base64_extra_chars[3]; 489 char base64_extra_chars[3];
463 int32_t base64_extra; 490 int32_t base64_extra;
464 }; 491 };
465 492
466 // prototypes 493 // prototypes
494 void set_read64();
467 int32_t pst_open(pst_file *pf, char *name, char *mode); 495 int32_t pst_open(pst_file *pf, char *name, char *mode);
468 int32_t pst_close(pst_file *pf); 496 int32_t pst_close(pst_file *pf);
469 pst_desc_ll * pst_getTopOfFolders(pst_file *pf, pst_item *root); 497 pst_desc_ll * pst_getTopOfFolders(pst_file *pf, pst_item *root);
470 int32_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b); 498 int32_t pst_attach_to_mem(pst_file *pf, pst_item_attach *attach, unsigned char **b);
471 int32_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp); 499 int32_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE* fp);
472 int32_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp); 500 int32_t pst_attach_to_file_base64(pst_file *pf, pst_item_attach *attach, FILE* fp);
473 int32_t pst_load_index (pst_file *pf); 501 int32_t pst_load_index (pst_file *pf);
474 pst_desc_ll* pst_getNextDptr(pst_desc_ll* d); 502 pst_desc_ll* pst_getNextDptr(pst_desc_ll* d);
475 int32_t pst_load_extended_attributes(pst_file *pf); 503 int32_t pst_load_extended_attributes(pst_file *pf);
476 504
477 int32_t _pst_build_id_ptr(pst_file *pf, int32_t offset, int32_t depth, int32_t linku1, u_int32_t start_val, u_int32_t end_val); 505 int32_t _pst_build_id_ptr(pst_file *pf, off_t offset, int32_t depth, int64_t linku1, uint64_t start_val, uint64_t end_val);
478 int32_t _pst_build_desc_ptr (pst_file *pf, int32_t offset, int32_t depth, int32_t linku1, u_int32_t *high_id, u_int32_t start_id, u_int32_t end_val); 506 int32_t _pst_build_desc_ptr (pst_file *pf, off_t offset, int32_t depth, int64_t linku1, uint64_t *high_id, uint64_t start_id, uint64_t end_val);
479 pst_item* _pst_getItem(pst_file *pf, pst_desc_ll *d_ptr); 507 pst_item* _pst_getItem(pst_file *pf, pst_desc_ll *d_ptr);
480 void * _pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr); 508 void * _pst_parse_item (pst_file *pf, pst_desc_ll *d_ptr);
481 pst_num_array * _pst_parse_block(pst_file *pf, u_int32_t block_id, pst_index2_ll *i2_head); 509 pst_num_array * _pst_parse_block(pst_file *pf, uint32_t block_id, pst_index2_ll *i2_head);
482 int32_t _pst_process(pst_num_array *list, pst_item *item, pst_item_attach *attach); 510 int32_t _pst_process(pst_num_array *list, pst_item *item, pst_item_attach *attach);
483 int32_t _pst_free_list(pst_num_array *list); 511 int32_t _pst_free_list(pst_num_array *list);
484 void _pst_freeItem(pst_item *item); 512 void _pst_freeItem(pst_item *item);
485 int32_t _pst_free_id2(pst_index2_ll * head); 513 int32_t _pst_free_id2(pst_index2_ll * head);
486 int32_t _pst_free_id (pst_index_ll *head); 514 int32_t _pst_free_id (pst_index_ll *head);
487 int32_t _pst_free_desc (pst_desc_ll *head); 515 int32_t _pst_free_desc (pst_desc_ll *head);
488 int32_t _pst_free_xattrib(pst_x_attrib_ll *x); 516 int32_t _pst_free_xattrib(pst_x_attrib_ll *x);
489 int32_t _pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset_pointer *p); 517 int32_t _pst_getBlockOffsetPointer(pst_file *pf, pst_index2_ll *i2_head, unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset_pointer *p);
490 int32_t _pst_getBlockOffset(unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset *p); 518 int32_t _pst_getBlockOffset(unsigned char *buf, int32_t read_size, int32_t i_offset, int32_t offset, pst_block_offset *p);
491 pst_index2_ll * _pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr); 519 pst_index2_ll * _pst_build_id2(pst_file *pf, pst_index_ll* list, pst_index2_ll* head_ptr);
492 pst_index_ll * _pst_getID(pst_file* pf, u_int32_t id); 520 pst_index_ll * _pst_getID(pst_file* pf, uint64_t id);
493 pst_index_ll * _pst_getID2(pst_index2_ll * ptr, u_int32_t id); 521 pst_index_ll * _pst_getID2(pst_index2_ll * ptr, uint32_t id);
494 pst_desc_ll * _pst_getDptr(pst_file *pf, u_int32_t id); 522 pst_desc_ll * _pst_getDptr(pst_file *pf, uint32_t id);
495 size_t _pst_read_block_size(pst_file *pf, int32_t offset, size_t size, char ** buf, int32_t do_enc, 523 size_t _pst_read_block_size(pst_file *pf, off_t offset, size_t size, char **buf, int32_t do_enc, unsigned char is_index);
496 unsigned char is_index);
497 int32_t _pst_decrypt(unsigned char *buf, size_t size, int32_t type); 524 int32_t _pst_decrypt(unsigned char *buf, size_t size, int32_t type);
498 int32_t _pst_getAtPos(FILE *fp, int32_t pos, void* buf, u_int32_t size); 525 int64_t _getIntAt(char *buf);
499 int32_t _pst_get (FILE *fp, void *buf, u_int32_t size); 526 int64_t _pst_getIntAtPos(FILE *fp, off_t pos);
500 size_t _pst_ff_getIDblock_dec(pst_file *pf, u_int32_t id, unsigned char **b); 527 int32_t _pst_getAtPos(FILE *fp, off_t pos, void* buf, uint32_t size);
501 size_t _pst_ff_getIDblock(pst_file *pf, u_int32_t id, unsigned char** b); 528 int32_t _pst_get (FILE *fp, void *buf, uint32_t size);
502 size_t _pst_ff_getID2block(pst_file *pf, u_int32_t id2, pst_index2_ll *id2_head, unsigned char** buf); 529 size_t _pst_ff_getIDblock_dec(pst_file *pf, uint32_t id, unsigned char **b);
530 size_t _pst_ff_getIDblock(pst_file *pf, uint32_t id, unsigned char** b);
531 size_t _pst_ff_getID2block(pst_file *pf, uint32_t id2, pst_index2_ll *id2_head, unsigned char** buf);
503 size_t _pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h); 532 size_t _pst_ff_getID2data(pst_file *pf, pst_index_ll *ptr, struct holder *h);
504 size_t _pst_ff_compile_ID(pst_file *pf, u_int32_t id, struct holder *h, int32_t size); 533 size_t _pst_ff_compile_ID(pst_file *pf, uint32_t id, struct holder *h, int32_t size);
505 534
506 int32_t pst_strincmp(char *a, char *b, int32_t x); 535 int32_t pst_strincmp(char *a, char *b, int32_t x);
507 int32_t pst_stricmp(char *a, char *b); 536 int32_t pst_stricmp(char *a, char *b);
508 size_t pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream); 537 size_t pst_fwrite(const void*ptr, size_t size, size_t nmemb, FILE*stream);
509 char * _pst_wide_to_single(char *wt, int32_t size); 538 char * _pst_wide_to_single(char *wt, int32_t size);
539
540 char *pst_rfc2426_escape(char *str);
541 int pst_chr_count(char *str, char x);
542 char *pst_rfc2425_datetime_format(FILETIME *ft);
543 char *pst_rfc2445_datetime_format(FILETIME *ft);
544
510 // DEBUG functions 545 // DEBUG functions
511 int32_t _pst_printDptr(pst_file *pf); 546 int32_t _pst_printDptr(pst_file *pf);
512 int32_t _pst_printIDptr(pst_file* pf); 547 int32_t _pst_printIDptr(pst_file* pf);
513 int32_t _pst_printID2ptr(pst_index2_ll *ptr); 548 int32_t _pst_printID2ptr(pst_index2_ll *ptr);
514 void * xmalloc(size_t size); 549 void * xmalloc(size_t size);