mspack.h

Go to the documentation of this file.
00001 /* libmspack -- a library for working with Microsoft compression formats.
00002  * (C) 2003-2010 Stuart Caie <kyzer@4u.net>
00003  *
00004  * libmspack is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License (LGPL) version 2.1
00006  *
00007  * This program is distributed in the hope that it will be useful,
00008  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  * GNU Lesser General Public License for more details.
00011  *
00012  * You should have received a copy of the GNU Lesser General Public License
00013  * along with this program; if not, write to the Free Software
00014  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00015  */
00016 
00118 #ifndef LIB_MSPACK_H
00119 #define LIB_MSPACK_H 1
00120 
00121 #ifdef __cplusplus
00122 extern "C" {
00123 #endif
00124 
00125 #include <sys/types.h>
00126 #include <stdlib.h>
00127 
00151 #define MSPACK_SYS_SELFTEST(result)  do { \
00152   (result) = mspack_sys_selftest_internal(sizeof(off_t)); \
00153 } while (0)
00154 
00156 extern int mspack_sys_selftest_internal(int);
00157 
00187 extern int mspack_version(int entity);
00188 
00190 #define MSPACK_VER_LIBRARY   (0)
00191 
00192 #define MSPACK_VER_SYSTEM    (1)
00193 
00194 #define MSPACK_VER_MSCABD    (2)
00195 
00196 #define MSPACK_VER_MSCABC    (3)
00197 
00198 #define MSPACK_VER_MSCHMD    (4)
00199 
00200 #define MSPACK_VER_MSCHMC    (5)
00201 
00202 #define MSPACK_VER_MSLITD    (6)
00203 
00204 #define MSPACK_VER_MSLITC    (7)
00205 
00206 #define MSPACK_VER_MSHLPD    (8)
00207 
00208 #define MSPACK_VER_MSHLPC    (9)
00209 
00210 #define MSPACK_VER_MSSZDDD   (10)
00211 
00212 #define MSPACK_VER_MSSZDDC   (11)
00213 
00214 #define MSPACK_VER_MSKWAJD   (12)
00215 
00216 #define MSPACK_VER_MSKWAJC   (13)
00217 
00218 /* --- file I/O abstraction ------------------------------------------------ */
00219 
00239 struct mspack_system {
00264   struct mspack_file * (*open)(struct mspack_system *self,
00265                                char *filename,
00266                                int mode);
00267 
00275   void (*close)(struct mspack_file *file);
00276 
00288   int (*read)(struct mspack_file *file,
00289               void *buffer,
00290               int bytes);
00291 
00305   int (*write)(struct mspack_file *file,
00306                void *buffer,
00307                int bytes);
00308 
00332   int (*seek)(struct mspack_file *file,
00333               off_t offset,
00334               int mode);
00335 
00343   off_t (*tell)(struct mspack_file *file);
00344   
00359   void (*message)(struct mspack_file *file,
00360                   char *format,
00361                   ...);
00362 
00373   void * (*alloc)(struct mspack_system *self,
00374                   size_t bytes);
00375   
00382   void (*free)(void *ptr);
00383 
00396   void (*copy)(void *src,
00397                void *dest,
00398                size_t bytes);
00399 
00406   void *null_ptr;
00407 };
00408 
00410 #define MSPACK_SYS_OPEN_READ   (0)
00411 
00412 #define MSPACK_SYS_OPEN_WRITE  (1)
00413 
00414 #define MSPACK_SYS_OPEN_UPDATE (2)
00415 
00416 #define MSPACK_SYS_OPEN_APPEND (3)
00417 
00419 #define MSPACK_SYS_SEEK_START  (0)
00420 
00421 #define MSPACK_SYS_SEEK_CUR    (1)
00422 
00423 #define MSPACK_SYS_SEEK_END    (2)
00424 
00430 struct mspack_file {
00431   int dummy;
00432 };
00433 
00434 /* --- error codes --------------------------------------------------------- */
00435 
00437 #define MSPACK_ERR_OK          (0)
00438 
00439 #define MSPACK_ERR_ARGS        (1)
00440 
00441 #define MSPACK_ERR_OPEN        (2)
00442 
00443 #define MSPACK_ERR_READ        (3)
00444 
00445 #define MSPACK_ERR_WRITE       (4)
00446 
00447 #define MSPACK_ERR_SEEK        (5)
00448 
00449 #define MSPACK_ERR_NOMEMORY    (6)
00450 
00451 #define MSPACK_ERR_SIGNATURE   (7)
00452 
00453 #define MSPACK_ERR_DATAFORMAT  (8)
00454 
00455 #define MSPACK_ERR_CHECKSUM    (9)
00456 
00457 #define MSPACK_ERR_CRUNCH      (10)
00458 
00459 #define MSPACK_ERR_DECRUNCH    (11)
00460 
00461 /* --- functions available in library -------------------------------------- */
00462 
00467 extern struct mscab_compressor *
00468   mspack_create_cab_compressor(struct mspack_system *sys);
00469 
00474 extern struct mscab_decompressor *
00475   mspack_create_cab_decompressor(struct mspack_system *sys);
00476 
00480 extern void mspack_destroy_cab_compressor(struct mscab_compressor *self);
00481 
00485 extern void mspack_destroy_cab_decompressor(struct mscab_decompressor *self);
00486 
00487 
00492 extern struct mschm_compressor *
00493   mspack_create_chm_compressor(struct mspack_system *sys);
00494 
00499 extern struct mschm_decompressor *
00500   mspack_create_chm_decompressor(struct mspack_system *sys);
00501 
00505 extern void mspack_destroy_chm_compressor(struct mschm_compressor *self);
00506 
00510 extern void mspack_destroy_chm_decompressor(struct mschm_decompressor *self);
00511 
00512 
00517 extern struct mslit_compressor *
00518   mspack_create_lit_compressor(struct mspack_system *sys);
00519 
00524 extern struct mslit_decompressor *
00525   mspack_create_lit_decompressor(struct mspack_system *sys);
00526 
00530 extern void mspack_destroy_lit_compressor(struct mslit_compressor *self);
00531 
00535 extern void mspack_destroy_lit_decompressor(struct mslit_decompressor *self);
00536 
00537 
00542 extern struct mshlp_compressor *
00543   mspack_create_hlp_compressor(struct mspack_system *sys);
00544 
00549 extern struct mshlp_decompressor *
00550   mspack_create_hlp_decompressor(struct mspack_system *sys);
00551 
00555 extern void mspack_destroy_hlp_compressor(struct mshlp_compressor *self);
00556 
00560 extern void mspack_destroy_hlp_decompressor(struct mshlp_decompressor *self);
00561 
00562 
00567 extern struct msszdd_compressor *
00568   mspack_create_szdd_compressor(struct mspack_system *sys);
00569 
00574 extern struct msszdd_decompressor *
00575   mspack_create_szdd_decompressor(struct mspack_system *sys);
00576 
00580 extern void mspack_destroy_szdd_compressor(struct msszdd_compressor *self);
00581 
00585 extern void mspack_destroy_szdd_decompressor(struct msszdd_decompressor *self);
00586 
00587 
00592 extern struct mskwaj_compressor *
00593   mspack_create_kwaj_compressor(struct mspack_system *sys);
00594 
00599 extern struct mskwaj_decompressor *
00600   mspack_create_kwaj_decompressor(struct mspack_system *sys);
00601 
00605 extern void mspack_destroy_kwaj_compressor(struct mskwaj_compressor *self);
00606 
00610 extern void mspack_destroy_kwaj_decompressor(struct mskwaj_decompressor *self);
00611 
00612 
00613 /* --- support for .CAB (MS Cabinet) file format --------------------------- */
00614 
00626 struct mscabd_cabinet {
00632   struct mscabd_cabinet *next;
00633 
00639   char *filename;
00640   
00642   off_t base_offset;
00643 
00645   unsigned int length;
00646 
00648   struct mscabd_cabinet *prevcab;
00649 
00651   struct mscabd_cabinet *nextcab;
00652 
00654   char *prevname;
00655 
00657   char *nextname;
00658 
00662   char *previnfo;
00663 
00667   char *nextinfo;
00668 
00670   struct mscabd_file *files;
00671 
00673   struct mscabd_folder *folders;
00674 
00679   unsigned short set_id;
00680 
00686   unsigned short set_index;
00687 
00698   unsigned short header_resv;
00699 
00711   int flags;
00712 };
00713 
00715 #define MSCAB_HDR_RESV_OFFSET (0x28)
00716 
00718 #define MSCAB_HDR_PREVCAB (0x01)
00719 
00720 #define MSCAB_HDR_NEXTCAB (0x02)
00721 
00722 #define MSCAB_HDR_RESV    (0x04)
00723 
00733 struct mscabd_folder {
00738   struct mscabd_folder *next;
00739 
00749   int comp_type;
00750 
00756   unsigned int num_blocks;
00757 };
00758 
00766 #define MSCABD_COMP_METHOD(comp_type) ((comp_type) & 0x0F)
00767 
00774 #define MSCABD_COMP_LEVEL(comp_type) (((comp_type) >> 8) & 0x1F)
00775 
00777 #define MSCAB_COMP_NONE       (0)
00778 
00779 #define MSCAB_COMP_MSZIP      (1)
00780 
00781 #define MSCAB_COMP_QUANTUM    (2)
00782 
00783 #define MSCAB_COMP_LZX        (3)
00784 
00790 struct mscabd_file {
00795   struct mscabd_file *next;
00796 
00805   char *filename;
00806 
00808   unsigned int length;
00809 
00822   int attribs;
00823 
00825   char time_h;
00827   char time_m;
00829   char time_s;
00830 
00832   char date_d;
00834   char date_m;
00836   int date_y;
00837 
00839   struct mscabd_folder *folder;
00840 
00842   unsigned int offset;
00843 };
00844 
00846 #define MSCAB_ATTRIB_RDONLY   (0x01)
00847 
00848 #define MSCAB_ATTRIB_HIDDEN   (0x02)
00849 
00850 #define MSCAB_ATTRIB_SYSTEM   (0x04)
00851 
00852 #define MSCAB_ATTRIB_ARCH     (0x20)
00853 
00854 #define MSCAB_ATTRIB_EXEC     (0x40)
00855 
00856 #define MSCAB_ATTRIB_UTF_NAME (0x80)
00857 
00859 #define MSCABD_PARAM_SEARCHBUF (0)
00860 
00861 #define MSCABD_PARAM_FIXMSZIP  (1)
00862 
00863 #define MSCABD_PARAM_DECOMPBUF (2)
00864 
00866 struct mscab_compressor {
00867   int dummy; 
00868 };
00869 
00877 struct mscab_decompressor {
00898   struct mscabd_cabinet * (*open) (struct mscab_decompressor *self,
00899                                    char *filename);
00900 
00930   void (*close)(struct mscab_decompressor *self,
00931                 struct mscabd_cabinet *cab);
00932 
00967   struct mscabd_cabinet * (*search) (struct mscab_decompressor *self,
00968                                      char *filename);
00969 
01010   int (*append) (struct mscab_decompressor *self,
01011                  struct mscabd_cabinet *cab,
01012                  struct mscabd_cabinet *nextcab);
01013 
01032   int (*prepend) (struct mscab_decompressor *self,
01033                   struct mscabd_cabinet *cab,
01034                   struct mscabd_cabinet *prevcab);
01035 
01058   int (*extract)(struct mscab_decompressor *self,
01059                  struct mscabd_file *file,
01060                  char *filename);
01061 
01084   int (*set_param)(struct mscab_decompressor *self,
01085                    int param,
01086                    int value);
01087 
01099   int (*last_error)(struct mscab_decompressor *self);
01100 };
01101 
01102 /* --- support for .CHM (HTMLHelp) file format ----------------------------- */
01103 
01112 struct mschmc_file {
01114   int section;
01115 
01118   char *filename;
01119 
01122   char *chm_filename;
01123 
01127   off_t length;
01128 };
01129 
01138 struct mschmd_section {
01140   struct mschmd_header *chm;
01141 
01147   unsigned int id;
01148 };
01149 
01155 struct mschmd_sec_uncompressed {
01157   struct mschmd_section base;
01158 
01160   off_t offset;
01161 };
01162 
01168 struct mschmd_sec_mscompressed {
01170   struct mschmd_section base;
01171 
01173   struct mschmd_file *content;
01174 
01176   struct mschmd_file *control;
01177 
01179   struct mschmd_file *rtable;
01180 };
01181 
01187 struct mschmd_header {
01189   unsigned int version;
01190 
01198   unsigned int timestamp;
01199       
01204   unsigned int language;
01205 
01210   char *filename;
01211 
01213   off_t length;
01214 
01216   struct mschmd_file *files;
01217 
01224   struct mschmd_file *sysfiles;
01225 
01227   struct mschmd_sec_uncompressed sec0;
01228 
01230   struct mschmd_sec_mscompressed sec1;
01231 
01233   off_t dir_offset;
01234 
01236   unsigned int num_chunks;
01237 
01239   unsigned int chunk_size;
01240 
01242   unsigned int density;
01243 
01252   unsigned int depth;
01253 
01259   unsigned int index_root;
01260 };
01261 
01267 struct mschmd_file {
01272   struct mschmd_file *next;
01273 
01278   struct mschmd_section *section;
01279 
01281   off_t offset;
01282 
01284   off_t length;
01285 
01287   char *filename;
01288 };
01289 
01291 #define MSCHMC_ENDLIST   (0)
01292 
01293 #define MSCHMC_UNCOMP    (1)
01294 
01295 #define MSCHMC_MSCOMP    (2)
01296  
01298 #define MSCHMC_PARAM_TIMESTAMP  (0)
01299 
01300 #define MSCHMC_PARAM_LANGUAGE   (1)
01301 
01302 #define MSCHMC_PARAM_LZXWINDOW  (2)
01303 
01304 #define MSCHMC_PARAM_DENSITY    (3)
01305 
01306 #define MSCHMC_PARAM_INDEX      (4)
01307 
01315 struct mschm_compressor {
01347   int (*generate)(struct mschm_compressor *self,
01348                   struct mschmc_file file_list[],
01349                   char *output_file);
01350 
01404   int (*use_temporary_file)(struct mschm_compressor *self,
01405                             int use_temp_file,
01406                             char *temp_file);
01452   int (*set_param)(struct mschm_compressor *self,
01453                    int param,
01454                    unsigned int value);
01455 
01464   int (*last_error)(struct mschm_compressor *self);
01465 };
01466 
01474 struct mschm_decompressor {
01495   struct mschmd_header *(*open)(struct mschm_decompressor *self,
01496                                 char *filename);
01497 
01515   void (*close)(struct mschm_decompressor *self,
01516                 struct mschmd_header *chm);
01517 
01536   int (*extract)(struct mschm_decompressor *self,
01537                  struct mschmd_file *file,
01538                  char *filename);
01539 
01551   int (*last_error)(struct mschm_decompressor *self);
01552 
01575   struct mschmd_header *(*fast_open)(struct mschm_decompressor *self,
01576                                      char *filename);
01577 
01616   int (*fast_find)(struct mschm_decompressor *self,
01617                    struct mschmd_header *chm,
01618                    char *filename,
01619                    struct mschmd_file *f_ptr,
01620                    int f_size);
01621 };
01622 
01623 /* --- support for .LIT (EBook) file format -------------------------------- */
01624 
01626 struct mslit_compressor {
01627   int dummy; 
01628 };
01629 
01631 struct mslit_decompressor {
01632   int dummy; 
01633 };
01634 
01635 
01636 /* --- support for .HLP (MS Help) file format ------------------------------ */
01637 
01639 struct mshlp_compressor {
01640   int dummy; 
01641 };
01642 
01644 struct mshlp_decompressor {
01645   int dummy; 
01646 };
01647 
01648 
01649 /* --- support for SZDD file format ---------------------------------------- */
01650 
01652 #define MSSZDDC_PARAM_MISSINGCHAR (0)
01653 
01655 #define MSSZDD_FMT_NORMAL (0)
01656 
01658 #define MSSZDD_FMT_QBASIC (1)
01659 
01665 struct msszddd_header {
01667   int format;
01668 
01670   off_t length;
01671 
01679   char missing_char;
01680 };
01681 
01689 struct msszdd_compressor {
01725   int (*compress)(struct msszdd_compressor *self,
01726                   char *input,
01727                   char *output,
01728                   off_t length);
01729 
01751   int (*set_param)(struct msszdd_compressor *self,
01752                    int param,
01753                    unsigned int value);
01754 
01763   int (*last_error)(struct mschm_decompressor *self);
01764 };
01765 
01773 struct msszdd_decompressor {
01793   struct msszddd_header *(*open)(struct msszdd_decompressor *self,
01794                                  char *filename);
01795 
01809   void (*close)(struct msszdd_decompressor *self,
01810                 struct msszddd_header *szdd);
01811 
01825   int (*extract)(struct msszdd_decompressor *self,
01826                  struct msszddd_header *szdd,
01827                  char *filename);
01828 
01846   int (*decompress)(struct msszdd_decompressor *self,
01847                     char *input,
01848                     char *output);
01849 
01861   int (*last_error)(struct msszdd_decompressor *self);
01862 };
01863 
01864 /* --- support for KWAJ file format ---------------------------------------- */
01865 
01867 #define MSKWAJC_PARAM_COMP_TYPE  (0)
01868 
01872 #define MSKWAJC_PARAM_INCLUDE_LENGTH (1)
01873 
01875 #define MSKWAJ_COMP_NONE (0)
01876 
01877 #define MSKWAJ_COMP_XOR (1)
01878 
01879 #define MSKWAJ_COMP_SZDD (2)
01880 
01881 #define MSKWAJ_COMP_LZH (3)
01882 
01884 #define MSKWAJ_HDR_HASLENGTH (0x01)
01885 
01887 #define MSKWAJ_HDR_HASUNKNOWN1 (0x02)
01888 
01890 #define MSKWAJ_HDR_HASUNKNOWN2 (0x04)
01891 
01893 #define MSKWAJ_HDR_HASFILENAME (0x08)
01894 
01896 #define MSKWAJ_HDR_HASFILEEXT (0x10)
01897 
01899 #define MSKWAJ_HDR_HASEXTRATEXT (0x20)
01900 
01906 struct mskwajd_header {
01910   unsigned short comp_type;
01911 
01913   off_t data_offset;
01914 
01916   int headers;
01917 
01919   off_t length;
01920 
01922   char *filename;
01923 
01927   char *extra;
01928 
01930   unsigned short extra_length;
01931 };
01932 
01940 struct mskwaj_compressor {
01959   int (*compress)(struct mskwaj_compressor *self,
01960                   char *input,
01961                   char *output,
01962                   off_t length);
01963 
01987   int (*set_param)(struct mskwaj_compressor *self,
01988                    int param,
01989                    unsigned int value);
01990 
01991 
02009   int (*set_filename)(struct mskwaj_compressor *self,
02010                       char *filename);
02011 
02029   int (*set_extra_data)(struct mskwaj_compressor *self,
02030                         void *data,
02031                         size_t bytes);
02032 
02041   int (*last_error)(struct mschm_decompressor *self);
02042 };
02043 
02051 struct mskwaj_decompressor {
02071   struct mskwajd_header *(*open)(struct mskwaj_decompressor *self,
02072                                  char *filename);
02073 
02086   void (*close)(struct mskwaj_decompressor *self,
02087                 struct mskwajd_header *kwaj);
02088 
02102   int (*extract)(struct mskwaj_decompressor *self,
02103                  struct mskwajd_header *kwaj,
02104                  char *filename);
02105 
02123   int (*decompress)(struct mskwaj_decompressor *self,
02124                     char *input,
02125                     char *output);
02126 
02138   int (*last_error)(struct mskwaj_decompressor *self);
02139 };
02140 
02141 #ifdef __cplusplus
02142 }
02143 #endif
02144 
02145 #endif

Generated on Tue Oct 19 14:51:36 2010 for libmspack by  doxygen 1.4.7