libmspack
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Macros
mspack
mspack.h
Go to the documentation of this file.
1
/* libmspack -- a library for working with Microsoft compression formats.
2
* (C) 2003-2013 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
158
#ifndef LIB_MSPACK_H
159
#define LIB_MSPACK_H 1
160
161
#ifdef __cplusplus
162
extern
"C"
{
163
#endif
164
165
#include <sys/types.h>
166
#include <stdlib.h>
167
191
#define MSPACK_SYS_SELFTEST(result) do { \
192
(result) = mspack_sys_selftest_internal(sizeof(off_t)); \
193
} while (0)
194
196
extern
int
mspack_sys_selftest_internal
(
int
);
197
229
extern
int
mspack_version
(
int
entity);
230
232
#define MSPACK_VER_LIBRARY (0)
233
234
#define MSPACK_VER_SYSTEM (1)
235
236
#define MSPACK_VER_MSCABD (2)
237
238
#define MSPACK_VER_MSCABC (3)
239
240
#define MSPACK_VER_MSCHMD (4)
241
242
#define MSPACK_VER_MSCHMC (5)
243
244
#define MSPACK_VER_MSLITD (6)
245
246
#define MSPACK_VER_MSLITC (7)
247
248
#define MSPACK_VER_MSHLPD (8)
249
250
#define MSPACK_VER_MSHLPC (9)
251
252
#define MSPACK_VER_MSSZDDD (10)
253
254
#define MSPACK_VER_MSSZDDC (11)
255
256
#define MSPACK_VER_MSKWAJD (12)
257
258
#define MSPACK_VER_MSKWAJC (13)
259
260
#define MSPACK_VER_MSOABD (14)
261
262
#define MSPACK_VER_MSOABC (15)
263
264
/* --- file I/O abstraction ------------------------------------------------ */
265
285
struct
mspack_system
{
310
struct
mspack_file
* (*open)(
struct
mspack_system
*
self
,
311
const
char
*filename,
312
int
mode);
313
321
void (*
close
)(
struct
mspack_file
*file);
322
334
int (*
read
)(
struct
mspack_file
*file,
335
void
*buffer,
336
int
bytes);
337
351
int (*
write
)(
struct
mspack_file
*file,
352
void
*buffer,
353
int
bytes);
354
378
int (*
seek
)(
struct
mspack_file
*file,
379
off_t offset,
380
int
mode);
381
389
off_t (*
tell
)(
struct
mspack_file
*file);
390
405
void (*
message
)(
struct
mspack_file
*file,
406
const
char
*format,
407
...);
408
419
void
* (*alloc)(
struct
mspack_system
*
self
,
420
size_t
bytes);
421
428
void (*
free
)(
void
*ptr);
429
442
void (*
copy
)(
void
*src,
443
void
*dest,
444
size_t
bytes);
445
452
void
*
null_ptr
;
453
};
454
456
#define MSPACK_SYS_OPEN_READ (0)
457
458
#define MSPACK_SYS_OPEN_WRITE (1)
459
460
#define MSPACK_SYS_OPEN_UPDATE (2)
461
462
#define MSPACK_SYS_OPEN_APPEND (3)
463
465
#define MSPACK_SYS_SEEK_START (0)
466
467
#define MSPACK_SYS_SEEK_CUR (1)
468
469
#define MSPACK_SYS_SEEK_END (2)
470
476
struct
mspack_file
{
477
int
dummy
;
478
};
479
480
/* --- error codes --------------------------------------------------------- */
481
483
#define MSPACK_ERR_OK (0)
484
485
#define MSPACK_ERR_ARGS (1)
486
487
#define MSPACK_ERR_OPEN (2)
488
489
#define MSPACK_ERR_READ (3)
490
491
#define MSPACK_ERR_WRITE (4)
492
493
#define MSPACK_ERR_SEEK (5)
494
495
#define MSPACK_ERR_NOMEMORY (6)
496
497
#define MSPACK_ERR_SIGNATURE (7)
498
499
#define MSPACK_ERR_DATAFORMAT (8)
500
501
#define MSPACK_ERR_CHECKSUM (9)
502
503
#define MSPACK_ERR_CRUNCH (10)
504
505
#define MSPACK_ERR_DECRUNCH (11)
506
507
/* --- functions available in library -------------------------------------- */
508
513
extern
struct
mscab_compressor
*
514
mspack_create_cab_compressor
(
struct
mspack_system
*sys);
515
520
extern
struct
mscab_decompressor
*
521
mspack_create_cab_decompressor
(
struct
mspack_system
*sys);
522
526
extern
void
mspack_destroy_cab_compressor
(
struct
mscab_compressor
*
self
);
527
531
extern
void
mspack_destroy_cab_decompressor
(
struct
mscab_decompressor
*
self
);
532
533
538
extern
struct
mschm_compressor
*
539
mspack_create_chm_compressor
(
struct
mspack_system
*sys);
540
545
extern
struct
mschm_decompressor
*
546
mspack_create_chm_decompressor
(
struct
mspack_system
*sys);
547
551
extern
void
mspack_destroy_chm_compressor
(
struct
mschm_compressor
*
self
);
552
556
extern
void
mspack_destroy_chm_decompressor
(
struct
mschm_decompressor
*
self
);
557
558
563
extern
struct
mslit_compressor
*
564
mspack_create_lit_compressor
(
struct
mspack_system
*sys);
565
570
extern
struct
mslit_decompressor
*
571
mspack_create_lit_decompressor
(
struct
mspack_system
*sys);
572
576
extern
void
mspack_destroy_lit_compressor
(
struct
mslit_compressor
*
self
);
577
581
extern
void
mspack_destroy_lit_decompressor
(
struct
mslit_decompressor
*
self
);
582
583
588
extern
struct
mshlp_compressor
*
589
mspack_create_hlp_compressor
(
struct
mspack_system
*sys);
590
595
extern
struct
mshlp_decompressor
*
596
mspack_create_hlp_decompressor
(
struct
mspack_system
*sys);
597
601
extern
void
mspack_destroy_hlp_compressor
(
struct
mshlp_compressor
*
self
);
602
606
extern
void
mspack_destroy_hlp_decompressor
(
struct
mshlp_decompressor
*
self
);
607
608
613
extern
struct
msszdd_compressor
*
614
mspack_create_szdd_compressor
(
struct
mspack_system
*sys);
615
620
extern
struct
msszdd_decompressor
*
621
mspack_create_szdd_decompressor
(
struct
mspack_system
*sys);
622
626
extern
void
mspack_destroy_szdd_compressor
(
struct
msszdd_compressor
*
self
);
627
631
extern
void
mspack_destroy_szdd_decompressor
(
struct
msszdd_decompressor
*
self
);
632
633
638
extern
struct
mskwaj_compressor
*
639
mspack_create_kwaj_compressor
(
struct
mspack_system
*sys);
640
645
extern
struct
mskwaj_decompressor
*
646
mspack_create_kwaj_decompressor
(
struct
mspack_system
*sys);
647
651
extern
void
mspack_destroy_kwaj_compressor
(
struct
mskwaj_compressor
*
self
);
652
656
extern
void
mspack_destroy_kwaj_decompressor
(
struct
mskwaj_decompressor
*
self
);
657
658
663
extern
struct
msoab_compressor
*
664
mspack_create_oab_compressor
(
struct
mspack_system
*sys);
665
670
extern
struct
msoab_decompressor
*
671
mspack_create_oab_decompressor
(
struct
mspack_system
*sys);
672
676
extern
void
mspack_destroy_oab_compressor
(
struct
msoab_compressor
*
self
);
677
681
extern
void
mspack_destroy_oab_decompressor
(
struct
msoab_decompressor
*
self
);
682
683
684
/* --- support for .CAB (MS Cabinet) file format --------------------------- */
685
697
struct
mscabd_cabinet
{
703
struct
mscabd_cabinet
*
next
;
704
710
const
char
*
filename
;
711
713
off_t
base_offset
;
714
716
unsigned
int
length
;
717
719
struct
mscabd_cabinet
*
prevcab
;
720
722
struct
mscabd_cabinet
*
nextcab
;
723
725
char
*
prevname
;
726
728
char
*
nextname
;
729
733
char
*
previnfo
;
734
738
char
*
nextinfo
;
739
741
struct
mscabd_file
*
files
;
742
744
struct
mscabd_folder
*
folders
;
745
750
unsigned
short
set_id
;
751
757
unsigned
short
set_index
;
758
769
unsigned
short
header_resv
;
770
782
int
flags
;
783
};
784
786
#define MSCAB_HDR_RESV_OFFSET (0x28)
787
789
#define MSCAB_HDR_PREVCAB (0x01)
790
791
#define MSCAB_HDR_NEXTCAB (0x02)
792
793
#define MSCAB_HDR_RESV (0x04)
794
804
struct
mscabd_folder
{
809
struct
mscabd_folder
*
next
;
810
820
int
comp_type
;
821
827
unsigned
int
num_blocks
;
828
};
829
837
#define MSCABD_COMP_METHOD(comp_type) ((comp_type) & 0x0F)
838
845
#define MSCABD_COMP_LEVEL(comp_type) (((comp_type) >> 8) & 0x1F)
846
848
#define MSCAB_COMP_NONE (0)
849
850
#define MSCAB_COMP_MSZIP (1)
851
852
#define MSCAB_COMP_QUANTUM (2)
853
854
#define MSCAB_COMP_LZX (3)
855
861
struct
mscabd_file
{
866
struct
mscabd_file
*
next
;
867
876
char
*
filename
;
877
879
unsigned
int
length
;
880
893
int
attribs
;
894
896
char
time_h
;
898
char
time_m
;
900
char
time_s
;
901
903
char
date_d
;
905
char
date_m
;
907
int
date_y
;
908
910
struct
mscabd_folder
*
folder
;
911
913
unsigned
int
offset
;
914
};
915
917
#define MSCAB_ATTRIB_RDONLY (0x01)
918
919
#define MSCAB_ATTRIB_HIDDEN (0x02)
920
921
#define MSCAB_ATTRIB_SYSTEM (0x04)
922
923
#define MSCAB_ATTRIB_ARCH (0x20)
924
925
#define MSCAB_ATTRIB_EXEC (0x40)
926
927
#define MSCAB_ATTRIB_UTF_NAME (0x80)
928
930
#define MSCABD_PARAM_SEARCHBUF (0)
931
932
#define MSCABD_PARAM_FIXMSZIP (1)
933
934
#define MSCABD_PARAM_DECOMPBUF (2)
935
937
struct
mscab_compressor
{
938
int
dummy
;
939
};
940
948
struct
mscab_decompressor
{
969
struct
mscabd_cabinet
* (*open) (
struct
mscab_decompressor
*
self
,
970
const
char
*filename);
971
1001
void (*
close
)(
struct
mscab_decompressor
*
self
,
1002
struct
mscabd_cabinet
*cab);
1003
1038
struct
mscabd_cabinet
* (*search) (
struct
mscab_decompressor
*
self
,
1039
const
char
*filename);
1040
1081
int (*
append
) (
struct
mscab_decompressor
*
self
,
1082
struct
mscabd_cabinet
*cab,
1083
struct
mscabd_cabinet
*
nextcab
);
1084
1103
int (*
prepend
) (
struct
mscab_decompressor
*
self
,
1104
struct
mscabd_cabinet
*cab,
1105
struct
mscabd_cabinet
*
prevcab
);
1106
1129
int (*
extract
)(
struct
mscab_decompressor
*
self
,
1130
struct
mscabd_file
*file,
1131
const
char
*
filename
);
1132
1155
int (*
set_param
)(
struct
mscab_decompressor
*
self
,
1156
int
param,
1157
int
value);
1158
1170
int (*
last_error
)(
struct
mscab_decompressor
*
self
);
1171
};
1172
1173
/* --- support for .CHM (HTMLHelp) file format ----------------------------- */
1174
1183
struct
mschmc_file
{
1185
int
section
;
1186
1189
const
char
*
filename
;
1190
1193
char
*
chm_filename
;
1194
1198
off_t
length
;
1199
};
1200
1209
struct
mschmd_section
{
1211
struct
mschmd_header
*
chm
;
1212
1218
unsigned
int
id
;
1219
};
1220
1226
struct
mschmd_sec_uncompressed
{
1228
struct
mschmd_section
base
;
1229
1231
off_t
offset
;
1232
};
1233
1239
struct
mschmd_sec_mscompressed
{
1241
struct
mschmd_section
base
;
1242
1244
struct
mschmd_file
*
content
;
1245
1247
struct
mschmd_file
*
control
;
1248
1250
struct
mschmd_file
*
rtable
;
1251
1255
struct
mschmd_file
*
spaninfo
;
1256
};
1257
1263
struct
mschmd_header
{
1265
unsigned
int
version
;
1266
1274
unsigned
int
timestamp
;
1275
1280
unsigned
int
language
;
1281
1286
const
char
*
filename
;
1287
1289
off_t
length
;
1290
1292
struct
mschmd_file
*
files
;
1293
1300
struct
mschmd_file
*
sysfiles
;
1301
1303
struct
mschmd_sec_uncompressed
sec0
;
1304
1306
struct
mschmd_sec_mscompressed
sec1
;
1307
1309
off_t
dir_offset
;
1310
1312
unsigned
int
num_chunks
;
1313
1315
unsigned
int
chunk_size
;
1316
1318
unsigned
int
density
;
1319
1328
unsigned
int
depth
;
1329
1335
unsigned
int
index_root
;
1336
1341
unsigned
int
first_pmgl
;
1342
1347
unsigned
int
last_pmgl
;
1348
1353
unsigned
char
**
chunk_cache
;
1354
};
1355
1361
struct
mschmd_file
{
1366
struct
mschmd_file
*
next
;
1367
1372
struct
mschmd_section
*
section
;
1373
1375
off_t
offset
;
1376
1378
off_t
length
;
1379
1381
char
*
filename
;
1382
};
1383
1385
#define MSCHMC_ENDLIST (0)
1386
1387
#define MSCHMC_UNCOMP (1)
1388
1389
#define MSCHMC_MSCOMP (2)
1390
1392
#define MSCHMC_PARAM_TIMESTAMP (0)
1393
1394
#define MSCHMC_PARAM_LANGUAGE (1)
1395
1396
#define MSCHMC_PARAM_LZXWINDOW (2)
1397
1398
#define MSCHMC_PARAM_DENSITY (3)
1399
1400
#define MSCHMC_PARAM_INDEX (4)
1401
1409
struct
mschm_compressor
{
1441
int (*
generate
)(
struct
mschm_compressor
*
self
,
1442
struct
mschmc_file
file_list[],
1443
const char *output_file);
1444
1498
int (*
use_temporary_file
)(
struct
mschm_compressor
*
self
,
1499
int
use_temp_file,
1500
const
char
*temp_file);
1546
int (*
set_param
)(
struct
mschm_compressor
*
self
,
1547
int
param,
1548
unsigned
int
value);
1549
1558
int (*
last_error
)(
struct
mschm_compressor
*
self
);
1559
};
1560
1568
struct
mschm_decompressor
{
1589
struct
mschmd_header
*(*open)(
struct
mschm_decompressor
*
self
,
1590
const
char
*filename);
1591
1609
void (*
close
)(
struct
mschm_decompressor
*
self
,
1610
struct
mschmd_header
*chm);
1611
1630
int (*
extract
)(
struct
mschm_decompressor
*
self
,
1631
struct
mschmd_file
*file,
1632
const
char
*
filename
);
1633
1645
int (*
last_error
)(
struct
mschm_decompressor
*
self
);
1646
1669
struct
mschmd_header
*(*fast_open)(
struct
mschm_decompressor
*
self
,
1670
const
char
*filename);
1671
1710
int (*
fast_find
)(
struct
mschm_decompressor
*
self
,
1711
struct
mschmd_header
*chm,
1712
const
char
*
filename
,
1713
struct
mschmd_file
*f_ptr,
1714
int
f_size);
1715
};
1716
1717
/* --- support for .LIT (EBook) file format -------------------------------- */
1718
1720
struct
mslit_compressor
{
1721
int
dummy
;
1722
};
1723
1725
struct
mslit_decompressor
{
1726
int
dummy
;
1727
};
1728
1729
1730
/* --- support for .HLP (MS Help) file format ------------------------------ */
1731
1733
struct
mshlp_compressor
{
1734
int
dummy
;
1735
};
1736
1738
struct
mshlp_decompressor
{
1739
int
dummy
;
1740
};
1741
1742
1743
/* --- support for SZDD file format ---------------------------------------- */
1744
1746
#define MSSZDDC_PARAM_MISSINGCHAR (0)
1747
1749
#define MSSZDD_FMT_NORMAL (0)
1750
1752
#define MSSZDD_FMT_QBASIC (1)
1753
1759
struct
msszddd_header
{
1761
int
format
;
1762
1764
off_t
length
;
1765
1773
char
missing_char
;
1774
};
1775
1783
struct
msszdd_compressor
{
1819
int (*
compress
)(
struct
msszdd_compressor
*
self
,
1820
const
char
*input,
1821
const
char
*output,
1822
off_t length);
1823
1845
int (*
set_param
)(
struct
msszdd_compressor
*
self
,
1846
int
param,
1847
unsigned
int
value);
1848
1857
int (*
last_error
)(
struct
mschm_decompressor
*
self
);
1858
};
1859
1867
struct
msszdd_decompressor
{
1887
struct
msszddd_header
*(*open)(
struct
msszdd_decompressor
*
self
,
1888
const
char
*filename);
1889
1903
void (*
close
)(
struct
msszdd_decompressor
*
self
,
1904
struct
msszddd_header
*szdd);
1905
1919
int (*
extract
)(
struct
msszdd_decompressor
*
self
,
1920
struct
msszddd_header
*szdd,
1921
const
char
*filename);
1922
1940
int (*
decompress
)(
struct
msszdd_decompressor
*
self
,
1941
const
char
*input,
1942
const
char
*output);
1943
1955
int (*
last_error
)(
struct
msszdd_decompressor
*
self
);
1956
};
1957
1958
/* --- support for KWAJ file format ---------------------------------------- */
1959
1961
#define MSKWAJC_PARAM_COMP_TYPE (0)
1962
1966
#define MSKWAJC_PARAM_INCLUDE_LENGTH (1)
1967
1969
#define MSKWAJ_COMP_NONE (0)
1970
1971
#define MSKWAJ_COMP_XOR (1)
1972
1973
#define MSKWAJ_COMP_SZDD (2)
1974
1975
#define MSKWAJ_COMP_LZH (3)
1976
1977
#define MSKWAJ_COMP_MSZIP (4)
1978
1980
#define MSKWAJ_HDR_HASLENGTH (0x01)
1981
1983
#define MSKWAJ_HDR_HASUNKNOWN1 (0x02)
1984
1986
#define MSKWAJ_HDR_HASUNKNOWN2 (0x04)
1987
1989
#define MSKWAJ_HDR_HASFILENAME (0x08)
1990
1992
#define MSKWAJ_HDR_HASFILEEXT (0x10)
1993
1995
#define MSKWAJ_HDR_HASEXTRATEXT (0x20)
1996
2002
struct
mskwajd_header
{
2006
unsigned
short
comp_type
;
2007
2009
off_t
data_offset
;
2010
2012
int
headers
;
2013
2015
off_t
length
;
2016
2018
char
*
filename
;
2019
2023
char
*
extra
;
2024
2026
unsigned
short
extra_length
;
2027
};
2028
2036
struct
mskwaj_compressor
{
2055
int (*
compress
)(
struct
mskwaj_compressor
*
self
,
2056
const
char
*input,
2057
const
char
*output,
2058
off_t length);
2059
2083
int (*
set_param
)(
struct
mskwaj_compressor
*
self
,
2084
int
param,
2085
unsigned
int
value);
2086
2087
2105
int (*
set_filename
)(
struct
mskwaj_compressor
*
self
,
2106
const
char
*filename);
2107
2125
int (*
set_extra_data
)(
struct
mskwaj_compressor
*
self
,
2126
void
*data,
2127
size_t
bytes);
2128
2137
int (*
last_error
)(
struct
mschm_decompressor
*
self
);
2138
};
2139
2147
struct
mskwaj_decompressor
{
2167
struct
mskwajd_header
*(*open)(
struct
mskwaj_decompressor
*
self
,
2168
const
char
*filename);
2169
2182
void (*
close
)(
struct
mskwaj_decompressor
*
self
,
2183
struct
mskwajd_header
*kwaj);
2184
2198
int (*
extract
)(
struct
mskwaj_decompressor
*
self
,
2199
struct
mskwajd_header
*kwaj,
2200
const
char
*
filename
);
2201
2219
int (*
decompress
)(
struct
mskwaj_decompressor
*
self
,
2220
const
char
*input,
2221
const
char
*output);
2222
2234
int (*
last_error
)(
struct
mskwaj_decompressor
*
self
);
2235
};
2236
2237
/* --- support for .LZX (Offline Address Book) file format ----------------- */
2238
2246
struct
msoab_compressor
{
2261
int (*
compress
) (
struct
msoab_compressor
*
self
,
2262
const
char
*input,
2263
const
char
*output);
2264
2285
int (*
compress_incremental
) (
struct
msoab_compressor
*
self
,
2286
const
char
*input,
2287
const
char
*base,
2288
const
char
*output);
2289
};
2290
2298
struct
msoab_decompressor
{
2314
int (*
decompress
) (
struct
msoab_decompressor
*
self
,
2315
const
char
*input,
2316
const
char
*output);
2317
2343
int (*
decompress_incremental
) (
struct
msoab_decompressor
*
self
,
2344
const
char
*input,
2345
const
char
*base,
2346
const
char
*output);
2347
};
2348
2349
#ifdef __cplusplus
2350
}
2351
#endif
2352
2353
#endif
Generated by
1.8.4