-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCAB.bt
122 lines (93 loc) · 3.9 KB
/
CAB.bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//------------------------------------------------
//--- 010 Editor v3.2.2 Binary Template
//
// File: CAB.bt
// Authors: Alex McDonnell
// Version: 0.3
// Purpose: Template for Microsoft cabinet format files.
// Category: Archive
// File Mask: *.cab
// ID Bytes: 4D 53 43 46 //MSCF
// History:
// 0.3 2016-01-27 SweetScape: Updated header for repository submission, added coloring for header, removed some warnings.
// 0.2 SweetScape: Allow for multiple flags to be set at the same time.
// 0.1 AM: Initial release.
//
// Format is described at:
// http://msdn.microsoft.com/en-us/library/bb417343.aspx.
//------------------------------------------------
typedef struct {
//header
char signature[4]; /* 'MSCF' */
uint reserved1; /* 0x00000000 */
uint cbCabinet; /* size of this cabinet file in bytes */
uint reserved2; /* 0x00000000 */
uint coffFiles; /* offset of the first CFFILE entry */
uint reserved3; /* 0x00000000 */
ubyte versionMinor; /* cabinet file format version, minor 0x03 */
ubyte versionMajor; /* cabinet file format version, major 0x01 */
ushort cFolders; /* number of CFFOLDER entries in this cabinet */
ushort cFiles; /* number of CFFILE entries in this cabinet */
ushort flags; /* cabinet file option indicators 0x0001 0x0002 0x0004 only*/
ushort setID; /* must be the same for all cabinets in a set */
ushort iCabinet; /* number of this cabinet file in a set */
if(flags & 4){
ushort cbCFHeader; /* (optional) size of per-cabinet reserved area */
ubyte cbCFFolder; /* (optional) size of per-folder reserved area */
ubyte cbCFData; /* (optional) size of per-datablock reserved area */
if(cbCFHeader > 0)
char abReserve[cbCFHeader]; /* (optional) per-cabinet reserved area */
}
if(flags & 1){
char szCabinetPrev[];/* (optional) name of previous cabinet file */
char szDiskPrev[]; /* (optional) name of previous disk */
}
if(flags & 2){
char szCabinetNext[]; /* (optional) name of next cabinet file */
char szDiskNext[]; /* (optional) name of next disk */
}
} CFHEADER;
LittleEndian();
CFHEADER header <bgcolor=cLtGray>;
local uint counter = 0;
typedef struct {
//folder
uint coffCabStart; /* offset of the first CFDATA block in this folder */
ushort cCFData; /* number of CFDATA blocks in this folder */
ushort typeCompress; /* compression type indicator */
if( exists(header.cbCFFolder) && (header.cbCFFolder > 0) )
char abReserve[header.cbCFFolder]; /* (optional) per-folder reserved area */
} CFFOLDER;
typedef struct {
//file
uint cbFile; /* uncompressed size of this file in bytes */
uint uoffFolderStart; /* uncompressed offset of this file in the folder */
ushort iFolder; /* index into the CFFOLDER area */
DOSDATE date; /* date stamp for this file */
DOSTIME time; /* time stamp for this file */
ushort attribs; /* attribute flags for this file */
char szName[]; /* name of this file */
} CFFILE;
typedef struct {
//data
uint csum; /* checksum of this CFDATA entry */
ushort cbData; /* number of compressed bytes in this block */
ushort cbUncomp; /* number of uncompressed bytes in this block */
if( exists(header.cbCFData) && (header.cbCFData > 0) )
char abReserve[header.cbCFData]; /* (optional) per-datablock reserved area */
char ab[cbData]; /* compressed data bytes */
} CFDATA;
while(header.cFolders > counter){
counter++;
CFFOLDER folder;
}
counter = 0;
while(header.cFiles > counter){
counter++;
CFFILE file;
}
counter = 0;
while(folder.cCFData > counter){
counter++;
CFDATA data;
}