libmspack
 All Data Structures Files Functions Variables Macros
mspack.h
Go to the documentation of this file.
1 /* libmspack -- a library for working with Microsoft compression formats.
2  * (C) 2003-2011 Stuart Caie <kyzer@4u.net>
3  *
4  * libmspack is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License (LGPL) version 2.1
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15  */
16 
153 #ifndef LIB_MSPACK_H
154 #define LIB_MSPACK_H 1
155 
156 #ifdef __cplusplus
157 extern "C" {
158 #endif
159 
160 #include <sys/types.h>
161 #include <stdlib.h>
162 
186 #define MSPACK_SYS_SELFTEST(result) do { \
187  (result) = mspack_sys_selftest_internal(sizeof(off_t)); \
188 } while (0)
189 
191 extern int mspack_sys_selftest_internal(int);
192 
222 extern int mspack_version(int entity);
223 
225 #define MSPACK_VER_LIBRARY (0)
226 
227 #define MSPACK_VER_SYSTEM (1)
228 
229 #define MSPACK_VER_MSCABD (2)
230 
231 #define MSPACK_VER_MSCABC (3)
232 
233 #define MSPACK_VER_MSCHMD (4)
234 
235 #define MSPACK_VER_MSCHMC (5)
236 
237 #define MSPACK_VER_MSLITD (6)
238 
239 #define MSPACK_VER_MSLITC (7)
240 
241 #define MSPACK_VER_MSHLPD (8)
242 
243 #define MSPACK_VER_MSHLPC (9)
244 
245 #define MSPACK_VER_MSSZDDD (10)
246 
247 #define MSPACK_VER_MSSZDDC (11)
248 
249 #define MSPACK_VER_MSKWAJD (12)
250 
251 #define MSPACK_VER_MSKWAJC (13)
252 
253 /* --- file I/O abstraction ------------------------------------------------ */
254 
299  struct mspack_file * (*open)(struct mspack_system *self,
300  const char *filename,
301  int mode);
302 
310  void (*close)(struct mspack_file *file);
311 
323  int (*read)(struct mspack_file *file,
324  void *buffer,
325  int bytes);
326 
340  int (*write)(struct mspack_file *file,
341  void *buffer,
342  int bytes);
343 
367  int (*seek)(struct mspack_file *file,
368  off_t offset,
369  int mode);
370 
378  off_t (*tell)(struct mspack_file *file);
379 
394  void (*message)(struct mspack_file *file,
395  const char *format,
396  ...);
397 
408  void * (*alloc)(struct mspack_system *self,
409  size_t bytes);
410 
417  void (*free)(void *ptr);
418 
431  void (*copy)(void *src,
432  void *dest,
433  size_t bytes);
434 
441  void *null_ptr;
442 };
443 
445 #define MSPACK_SYS_OPEN_READ (0)
446 
447 #define MSPACK_SYS_OPEN_WRITE (1)
448 
449 #define MSPACK_SYS_OPEN_UPDATE (2)
450 
451 #define MSPACK_SYS_OPEN_APPEND (3)
452 
454 #define MSPACK_SYS_SEEK_START (0)
455 
456 #define MSPACK_SYS_SEEK_CUR (1)
457 
458 #define MSPACK_SYS_SEEK_END (2)
459 
465 struct mspack_file {
466  int dummy;
467 };
468 
469 /* --- error codes --------------------------------------------------------- */
470 
472 #define MSPACK_ERR_OK (0)
473 
474 #define MSPACK_ERR_ARGS (1)
475 
476 #define MSPACK_ERR_OPEN (2)
477 
478 #define MSPACK_ERR_READ (3)
479 
480 #define MSPACK_ERR_WRITE (4)
481 
482 #define MSPACK_ERR_SEEK (5)
483 
484 #define MSPACK_ERR_NOMEMORY (6)
485 
486 #define MSPACK_ERR_SIGNATURE (7)
487 
488 #define MSPACK_ERR_DATAFORMAT (8)
489 
490 #define MSPACK_ERR_CHECKSUM (9)
491 
492 #define MSPACK_ERR_CRUNCH (10)
493 
494 #define MSPACK_ERR_DECRUNCH (11)
495 
496 /* --- functions available in library -------------------------------------- */
497 
502 extern struct mscab_compressor *
504 
509 extern struct mscab_decompressor *
511 
515 extern void mspack_destroy_cab_compressor(struct mscab_compressor *self);
516 
520 extern void mspack_destroy_cab_decompressor(struct mscab_decompressor *self);
521 
522 
527 extern struct mschm_compressor *
529 
534 extern struct mschm_decompressor *
536 
540 extern void mspack_destroy_chm_compressor(struct mschm_compressor *self);
541 
545 extern void mspack_destroy_chm_decompressor(struct mschm_decompressor *self);
546 
547 
552 extern struct mslit_compressor *
554 
559 extern struct mslit_decompressor *
561 
565 extern void mspack_destroy_lit_compressor(struct mslit_compressor *self);
566 
570 extern void mspack_destroy_lit_decompressor(struct mslit_decompressor *self);
571 
572 
577 extern struct mshlp_compressor *
579 
584 extern struct mshlp_decompressor *
586 
590 extern void mspack_destroy_hlp_compressor(struct mshlp_compressor *self);
591 
595 extern void mspack_destroy_hlp_decompressor(struct mshlp_decompressor *self);
596 
597 
602 extern struct msszdd_compressor *
604 
609 extern struct msszdd_decompressor *
611 
615 extern void mspack_destroy_szdd_compressor(struct msszdd_compressor *self);
616 
620 extern void mspack_destroy_szdd_decompressor(struct msszdd_decompressor *self);
621 
622 
627 extern struct mskwaj_compressor *
629 
634 extern struct mskwaj_decompressor *
636 
640 extern void mspack_destroy_kwaj_compressor(struct mskwaj_compressor *self);
641 
645 extern void mspack_destroy_kwaj_decompressor(struct mskwaj_decompressor *self);
646 
647 
648 /* --- support for .CAB (MS Cabinet) file format --------------------------- */
649 
668 
674  const char *filename;
675 
677  off_t base_offset;
678 
680  unsigned int length;
681 
684 
687 
689  char *prevname;
690 
692  char *nextname;
693 
697  char *previnfo;
698 
702  char *nextinfo;
703 
706 
709 
714  unsigned short set_id;
715 
721  unsigned short set_index;
722 
733  unsigned short header_resv;
734 
746  int flags;
747 };
748 
750 #define MSCAB_HDR_RESV_OFFSET (0x28)
751 
753 #define MSCAB_HDR_PREVCAB (0x01)
754 
755 #define MSCAB_HDR_NEXTCAB (0x02)
756 
757 #define MSCAB_HDR_RESV (0x04)
758 
774 
785 
791  unsigned int num_blocks;
792 };
793 
801 #define MSCABD_COMP_METHOD(comp_type) ((comp_type) & 0x0F)
802 
809 #define MSCABD_COMP_LEVEL(comp_type) (((comp_type) >> 8) & 0x1F)
810 
812 #define MSCAB_COMP_NONE (0)
813 
814 #define MSCAB_COMP_MSZIP (1)
815 
816 #define MSCAB_COMP_QUANTUM (2)
817 
818 #define MSCAB_COMP_LZX (3)
819 
825 struct mscabd_file {
830  struct mscabd_file *next;
831 
840  char *filename;
841 
843  unsigned int length;
844 
857  int attribs;
858 
860  char time_h;
862  char time_m;
864  char time_s;
865 
867  char date_d;
869  char date_m;
871  int date_y;
872 
875 
877  unsigned int offset;
878 };
879 
881 #define MSCAB_ATTRIB_RDONLY (0x01)
882 
883 #define MSCAB_ATTRIB_HIDDEN (0x02)
884 
885 #define MSCAB_ATTRIB_SYSTEM (0x04)
886 
887 #define MSCAB_ATTRIB_ARCH (0x20)
888 
889 #define MSCAB_ATTRIB_EXEC (0x40)
890 
891 #define MSCAB_ATTRIB_UTF_NAME (0x80)
892 
894 #define MSCABD_PARAM_SEARCHBUF (0)
895 
896 #define MSCABD_PARAM_FIXMSZIP (1)
897 
898 #define MSCABD_PARAM_DECOMPBUF (2)
899 
902  int dummy;
903 };
904 
933  struct mscabd_cabinet * (*open) (struct mscab_decompressor *self,
934  const char *filename);
935 
965  void (*close)(struct mscab_decompressor *self,
966  struct mscabd_cabinet *cab);
967 
1002  struct mscabd_cabinet * (*search) (struct mscab_decompressor *self,
1003  const char *filename);
1004 
1045  int (*append) (struct mscab_decompressor *self,
1046  struct mscabd_cabinet *cab,
1047  struct mscabd_cabinet *nextcab);
1048 
1067  int (*prepend) (struct mscab_decompressor *self,
1068  struct mscabd_cabinet *cab,
1069  struct mscabd_cabinet *prevcab);
1070 
1093  int (*extract)(struct mscab_decompressor *self,
1094  struct mscabd_file *file,
1095  const char *filename);
1096 
1119  int (*set_param)(struct mscab_decompressor *self,
1120  int param,
1121  int value);
1122 
1134  int (*last_error)(struct mscab_decompressor *self);
1135 };
1136 
1137 /* --- support for .CHM (HTMLHelp) file format ----------------------------- */
1138 
1147 struct mschmc_file {
1149  int section;
1150 
1153  const char *filename;
1154 
1158 
1162  off_t length;
1163 };
1164 
1176 
1182  unsigned int id;
1183 };
1184 
1193 
1195  off_t offset;
1196 };
1197 
1206 
1209 
1212 
1215 
1220 };
1221 
1229  unsigned int version;
1230 
1238  unsigned int timestamp;
1239 
1244  unsigned int language;
1245 
1250  const char *filename;
1251 
1253  off_t length;
1254 
1257 
1265 
1268 
1271 
1273  off_t dir_offset;
1274 
1276  unsigned int num_chunks;
1277 
1279  unsigned int chunk_size;
1280 
1282  unsigned int density;
1283 
1292  unsigned int depth;
1293 
1299  unsigned int index_root;
1300 
1305  unsigned int first_pmgl;
1306 
1311  unsigned int last_pmgl;
1312 
1317  unsigned char **chunk_cache;
1318 };
1319 
1325 struct mschmd_file {
1331 
1337 
1339  off_t offset;
1340 
1342  off_t length;
1343 
1345  char *filename;
1346 };
1347 
1349 #define MSCHMC_ENDLIST (0)
1350 
1351 #define MSCHMC_UNCOMP (1)
1352 
1353 #define MSCHMC_MSCOMP (2)
1354 
1356 #define MSCHMC_PARAM_TIMESTAMP (0)
1357 
1358 #define MSCHMC_PARAM_LANGUAGE (1)
1359 
1360 #define MSCHMC_PARAM_LZXWINDOW (2)
1361 
1362 #define MSCHMC_PARAM_DENSITY (3)
1363 
1364 #define MSCHMC_PARAM_INDEX (4)
1365 
1405  int (*generate)(struct mschm_compressor *self,
1406  struct mschmc_file file_list[],
1407  const char *output_file);
1408 
1463  int use_temp_file,
1464  const char *temp_file);
1510  int (*set_param)(struct mschm_compressor *self,
1511  int param,
1512  unsigned int value);
1513 
1522  int (*last_error)(struct mschm_compressor *self);
1523 };
1524 
1553  struct mschmd_header *(*open)(struct mschm_decompressor *self,
1554  const char *filename);
1555 
1573  void (*close)(struct mschm_decompressor *self,
1574  struct mschmd_header *chm);
1575 
1594  int (*extract)(struct mschm_decompressor *self,
1595  struct mschmd_file *file,
1596  const char *filename);
1597 
1609  int (*last_error)(struct mschm_decompressor *self);
1610 
1633  struct mschmd_header *(*fast_open)(struct mschm_decompressor *self,
1634  const char *filename);
1635 
1674  int (*fast_find)(struct mschm_decompressor *self,
1675  struct mschmd_header *chm,
1676  const char *filename,
1677  struct mschmd_file *f_ptr,
1678  int f_size);
1679 };
1680 
1681 /* --- support for .LIT (EBook) file format -------------------------------- */
1682 
1685  int dummy;
1686 };
1687 
1690  int dummy;
1691 };
1692 
1693 
1694 /* --- support for .HLP (MS Help) file format ------------------------------ */
1695 
1698  int dummy;
1699 };
1700 
1703  int dummy;
1704 };
1705 
1706 
1707 /* --- support for SZDD file format ---------------------------------------- */
1708 
1710 #define MSSZDDC_PARAM_MISSINGCHAR (0)
1711 
1713 #define MSSZDD_FMT_NORMAL (0)
1714 
1716 #define MSSZDD_FMT_QBASIC (1)
1717 
1725  int format;
1726 
1728  off_t length;
1729 
1738 };
1739 
1783  int (*compress)(struct msszdd_compressor *self,
1784  const char *input,
1785  const char *output,
1786  off_t length);
1787 
1809  int (*set_param)(struct msszdd_compressor *self,
1810  int param,
1811  unsigned int value);
1812 
1821  int (*last_error)(struct mschm_decompressor *self);
1822 };
1823 
1851  struct msszddd_header *(*open)(struct msszdd_decompressor *self,
1852  const char *filename);
1853 
1867  void (*close)(struct msszdd_decompressor *self,
1868  struct msszddd_header *szdd);
1869 
1883  int (*extract)(struct msszdd_decompressor *self,
1884  struct msszddd_header *szdd,
1885  const char *filename);
1886 
1904  int (*decompress)(struct msszdd_decompressor *self,
1905  const char *input,
1906  const char *output);
1907 
1919  int (*last_error)(struct msszdd_decompressor *self);
1920 };
1921 
1922 /* --- support for KWAJ file format ---------------------------------------- */
1923 
1925 #define MSKWAJC_PARAM_COMP_TYPE (0)
1926 
1930 #define MSKWAJC_PARAM_INCLUDE_LENGTH (1)
1931 
1933 #define MSKWAJ_COMP_NONE (0)
1934 
1935 #define MSKWAJ_COMP_XOR (1)
1936 
1937 #define MSKWAJ_COMP_SZDD (2)
1938 
1939 #define MSKWAJ_COMP_LZH (3)
1940 
1942 #define MSKWAJ_HDR_HASLENGTH (0x01)
1943 
1945 #define MSKWAJ_HDR_HASUNKNOWN1 (0x02)
1946 
1948 #define MSKWAJ_HDR_HASUNKNOWN2 (0x04)
1949 
1951 #define MSKWAJ_HDR_HASFILENAME (0x08)
1952 
1954 #define MSKWAJ_HDR_HASFILEEXT (0x10)
1955 
1957 #define MSKWAJ_HDR_HASEXTRATEXT (0x20)
1958 
1968  unsigned short comp_type;
1969 
1972 
1974  int headers;
1975 
1977  off_t length;
1978 
1980  char *filename;
1981 
1985  char *extra;
1986 
1988  unsigned short extra_length;
1989 };
1990 
2017  int (*compress)(struct mskwaj_compressor *self,
2018  const char *input,
2019  const char *output,
2020  off_t length);
2021 
2045  int (*set_param)(struct mskwaj_compressor *self,
2046  int param,
2047  unsigned int value);
2048 
2049 
2067  int (*set_filename)(struct mskwaj_compressor *self,
2068  const char *filename);
2069 
2087  int (*set_extra_data)(struct mskwaj_compressor *self,
2088  void *data,
2089  size_t bytes);
2090 
2099  int (*last_error)(struct mschm_decompressor *self);
2100 };
2101 
2129  struct mskwajd_header *(*open)(struct mskwaj_decompressor *self,
2130  const char *filename);
2131 
2144  void (*close)(struct mskwaj_decompressor *self,
2145  struct mskwajd_header *kwaj);
2146 
2160  int (*extract)(struct mskwaj_decompressor *self,
2161  struct mskwajd_header *kwaj,
2162  const char *filename);
2163 
2181  int (*decompress)(struct mskwaj_decompressor *self,
2182  const char *input,
2183  const char *output);
2184 
2196  int (*last_error)(struct mskwaj_decompressor *self);
2197 };
2198 
2199 #ifdef __cplusplus
2200 }
2201 #endif
2202 
2203 #endif