unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

headers.hpp
Go to the documentation of this file.
1#ifndef _RAR_HEADERS_
2#define _RAR_HEADERS_
3
4#define SIZEOF_MARKHEAD3 7 // Size of RAR 4.x archive mark header.
5#define SIZEOF_MAINHEAD14 7 // Size of RAR 1.4 main archive header.
6#define SIZEOF_MAINHEAD3 13 // Size of RAR 4.x main archive header.
7#define SIZEOF_FILEHEAD14 21 // Size of RAR 1.4 file header.
8#define SIZEOF_FILEHEAD3 32 // Size of RAR 3.0 file header.
9#define SIZEOF_SHORTBLOCKHEAD 7
10#define SIZEOF_LONGBLOCKHEAD 11
11#define SIZEOF_SUBBLOCKHEAD 14
12#define SIZEOF_COMMHEAD 13
13#define SIZEOF_PROTECTHEAD 26
14#define SIZEOF_UOHEAD 18
15#define SIZEOF_STREAMHEAD 26
16
17#define VER_PACK 29U
18#define VER_PACK5 50U // It is stored as 0, but we subtract 50 when saving an archive.
19#define VER_UNPACK 29U
20#define VER_UNPACK5 50U // It is stored as 0, but we add 50 when reading an archive.
21#define VER_UNKNOWN 9999U // Just some large value.
22
23#define MHD_VOLUME 0x0001U
24
25// Old style main archive comment embed into main archive header. Must not
26// be used in new archives anymore.
27#define MHD_COMMENT 0x0002U
28
29#define MHD_LOCK 0x0004U
30#define MHD_SOLID 0x0008U
31#define MHD_PACK_COMMENT 0x0010U
32#define MHD_NEWNUMBERING 0x0010U
33#define MHD_AV 0x0020U
34#define MHD_PROTECT 0x0040U
35#define MHD_PASSWORD 0x0080U
36#define MHD_FIRSTVOLUME 0x0100U
37
38#define LHD_SPLIT_BEFORE 0x0001U
39#define LHD_SPLIT_AFTER 0x0002U
40#define LHD_PASSWORD 0x0004U
41
42// Old style file comment embed into file header. Must not be used
43// in new archives anymore.
44#define LHD_COMMENT 0x0008U
45
46// For non-file subheaders it denotes 'subblock having a parent file' flag.
47#define LHD_SOLID 0x0010U
48
49
50#define LHD_WINDOWMASK 0x00e0U
51#define LHD_WINDOW64 0x0000U
52#define LHD_WINDOW128 0x0020U
53#define LHD_WINDOW256 0x0040U
54#define LHD_WINDOW512 0x0060U
55#define LHD_WINDOW1024 0x0080U
56#define LHD_WINDOW2048 0x00a0U
57#define LHD_WINDOW4096 0x00c0U
58#define LHD_DIRECTORY 0x00e0U
59
60#define LHD_LARGE 0x0100U
61#define LHD_UNICODE 0x0200U
62#define LHD_SALT 0x0400U
63#define LHD_VERSION 0x0800U
64#define LHD_EXTTIME 0x1000U
65
66#define SKIP_IF_UNKNOWN 0x4000U
67#define LONG_BLOCK 0x8000U
68
69#define EARC_NEXT_VOLUME 0x0001U // Not last volume.
70#define EARC_DATACRC 0x0002U // Store CRC32 of RAR archive (now is used only in volumes).
71#define EARC_REVSPACE 0x0004U // Reserve space for end of REV file 7 byte record.
72#define EARC_VOLNUMBER 0x0008U // Store a number of current volume.
73
75 // RAR 5.0 header types.
76 HEAD_MARK=0x00, HEAD_MAIN=0x01, HEAD_FILE=0x02, HEAD_SERVICE=0x03,
78
79 // RAR 1.5 - 4.x header types.
83};
84
85
86// RAR 2.9 and earlier.
87enum { EA_HEAD=0x100,UO_HEAD=0x101,MAC_HEAD=0x102,BEEA_HEAD=0x103,
88 NTACL_HEAD=0x104,STREAM_HEAD=0x105 };
89
90
91// Internal implementation, depends on archive format version.
93 // RAR 5.0 host OS
95
96 // RAR 3.0 host OS.
99};
100
101// Unified archive format independent implementation.
105
106
107// We also use these values in extra field, so do not modify them.
112
113
114#define SUBHEAD_TYPE_CMT L"CMT"
115#define SUBHEAD_TYPE_QOPEN L"QO"
116#define SUBHEAD_TYPE_ACL L"ACL"
117#define SUBHEAD_TYPE_STREAM L"STM"
118#define SUBHEAD_TYPE_UOWNER L"UOW"
119#define SUBHEAD_TYPE_AV L"AV"
120#define SUBHEAD_TYPE_RR L"RR"
121#define SUBHEAD_TYPE_OS2EA L"EA2"
122
123/* new file inherits a subblock when updating a host file */
124#define SUBHEAD_FLAGS_INHERITED 0x80000000
125
126#define SUBHEAD_FLAGS_CMT_UNICODE 0x00000001
127
128
130{
131 byte Mark[8];
132
133 // Following fields are virtual and not present in real blocks.
135};
136
137
139{
140 uint HeadCRC; // 'ushort' for RAR 1.5.
141 HEADER_TYPE HeaderType; // 1 byte for RAR 1.5.
142 uint Flags; // 'ushort' for RAR 1.5.
143 uint HeadSize; // 'ushort' for RAR 1.5, up to 2 MB for RAR 5.0.
144
146
147 void Reset()
148 {
149 SkipIfUnknown=false;
150 }
151};
152
153
155{
157};
158
159
161{
165 bool PackComment; // For RAR 1.4 archive format only.
167 uint64 QOpenOffset; // Offset of quick list record.
168 uint64 QOpenMaxSize; // Maximum size of QOpen offset in locator extra field.
169 uint64 RROffset; // Offset of recovery record.
170 uint64 RRMaxSize; // Maximum size of RR offset in locator extra field.
171 void Reset();
172};
173
174
176{
177 byte HostOS;
178 uint UnpVer; // It is 1 byte in RAR29 and bit field in RAR5.
179 byte Method;
180 union {
183 };
185
187
191
194 int64 MaxSize; // Reserve packed and unpacked size bytes for vint of this size.
195
197
199
202
204
212
213 // Use HMAC calculated from HashKey and checksum instead of plain checksum.
215
216 // Key to convert checksum to HMAC. Derived from password with PBKDF2
217 // using additional iterations.
219
220 uint Lg2Count; // Log2 of PBKDF2 repetition count.
221
222 bool Solid;
223 bool Dir;
224 bool CommentInHeader; // RAR 2.0 file comment.
225 bool Version; // name.ext;ver file name containing the version number.
226 size_t WinSize;
227 bool Inherited; // New file inherits a subblock when updating a host file (for subblocks only).
228
229 // 'true' if file sizes use 8 bytes instead of 4. Not used in RAR 5.0.
231
232 // 'true' for HEAD_SERVICE block, which is a child of preceding file block.
233 // RAR 4.x uses 'solid' flag to indicate child subheader blocks in archives.
235
237
241
244#ifdef _UNIX
245 uid_t UnixOwnerID;
246 gid_t UnixGroupID;
247#else // Need these Unix fields in Windows too for 'list' command.
250#endif
251
252 void Reset(size_t SubDataSize=0);
253
254 bool CmpName(const wchar *Name)
255 {
256 return(wcscmp(FileName,Name)==0);
257 }
258
260};
261
262
264{
265 // Optional CRC32 of entire archive up to start of EndArcHeader block.
266 // Present in RAR 4.x archives if EARC_DATACRC flag is set.
268
269 uint VolNumber; // Optional number of current volume.
270
271 // 7 additional zero bytes can be stored here if EARC_REVSPACE is set.
272
273 bool NextVolume; // Not last volume.
277 void Reset()
278 {
280 NextVolume=false;
281 DataCRC=false;
282 RevSpace=false;
283 StoreVolNumber=false;
284 }
285};
286
287
289{
291 uint Lg2Count; // Log2 of PBKDF2 repetition count.
294};
295
296
297// SubBlockHeader and its successors were used in RAR 2.x format.
298// RAR 4.x uses FileHeader with HEAD_SERVICE HeaderType for subblocks.
300{
302 byte Level;
303};
304
305
307{
309 byte UnpVer;
310 byte Method;
312};
313
314
316{
320 byte Mark[8];
321};
322
323
325{
328/* dummy */
329 char OwnerName[256];
330 char GroupName[256];
331};
332
333
335{
337 byte UnpVer;
338 byte Method;
340};
341
342
344{
346 byte UnpVer;
347 byte Method;
350 char StreamName[260];
351};
352
353
354#endif
CRYPT_METHOD
Definition: crypt.hpp:5
#define SIZE_PSWCHECK
Definition: crypt.hpp:12
#define SIZE_SALT50
Definition: crypt.hpp:9
#define SIZE_INITV
Definition: crypt.hpp:11
HOST_SYSTEM_TYPE
Definition: headers.hpp:102
@ HSYS_UNKNOWN
Definition: headers.hpp:103
@ HSYS_UNIX
Definition: headers.hpp:103
@ HSYS_WINDOWS
Definition: headers.hpp:103
@ BEEA_HEAD
Definition: headers.hpp:87
@ MAC_HEAD
Definition: headers.hpp:87
@ EA_HEAD
Definition: headers.hpp:87
@ STREAM_HEAD
Definition: headers.hpp:88
@ NTACL_HEAD
Definition: headers.hpp:88
@ UO_HEAD
Definition: headers.hpp:87
FILE_SYSTEM_REDIRECT
Definition: headers.hpp:108
@ FSREDIR_FILECOPY
Definition: headers.hpp:110
@ FSREDIR_HARDLINK
Definition: headers.hpp:110
@ FSREDIR_WINSYMLINK
Definition: headers.hpp:109
@ FSREDIR_NONE
Definition: headers.hpp:109
@ FSREDIR_UNIXSYMLINK
Definition: headers.hpp:109
@ FSREDIR_JUNCTION
Definition: headers.hpp:109
HEADER_TYPE
Definition: headers.hpp:74
@ HEAD3_FILE
Definition: headers.hpp:80
@ HEAD_FILE
Definition: headers.hpp:76
@ HEAD3_SERVICE
Definition: headers.hpp:82
@ HEAD_UNKNOWN
Definition: headers.hpp:77
@ HEAD_CRYPT
Definition: headers.hpp:77
@ HEAD3_OLDSERVICE
Definition: headers.hpp:81
@ HEAD_MARK
Definition: headers.hpp:76
@ HEAD3_MAIN
Definition: headers.hpp:80
@ HEAD3_MARK
Definition: headers.hpp:80
@ HEAD3_SIGN
Definition: headers.hpp:81
@ HEAD_SERVICE
Definition: headers.hpp:76
@ HEAD_MAIN
Definition: headers.hpp:76
@ HEAD3_ENDARC
Definition: headers.hpp:82
@ HEAD3_CMT
Definition: headers.hpp:80
@ HEAD3_AV
Definition: headers.hpp:81
@ HEAD3_PROTECT
Definition: headers.hpp:81
@ HEAD_ENDARC
Definition: headers.hpp:77
HOST_SYSTEM
Definition: headers.hpp:92
@ HOST_MSDOS
Definition: headers.hpp:97
@ HOST_BEOS
Definition: headers.hpp:98
@ HOST5_UNIX
Definition: headers.hpp:94
@ HOST_MACOS
Definition: headers.hpp:97
@ HOST_OS2
Definition: headers.hpp:97
@ HOST5_WINDOWS
Definition: headers.hpp:94
@ HOST_MAX
Definition: headers.hpp:98
@ HOST_UNIX
Definition: headers.hpp:97
@ HOST_WIN32
Definition: headers.hpp:97
wchar_t wchar
Definition: rartypes.hpp:13
int64_t int64
Definition: rartypes.hpp:12
unsigned int uint
Definition: rartypes.hpp:8
uint16_t ushort
Definition: rartypes.hpp:7
uint64_t uint64
Definition: rartypes.hpp:11
#define SHA256_DIGEST_SIZE
Definition: sha256.hpp:4
HEADER_TYPE HeaderType
Definition: headers.hpp:141
void Reset()
Definition: headers.hpp:147
uint HeadCRC
Definition: headers.hpp:140
uint HeadSize
Definition: headers.hpp:143
uint Flags
Definition: headers.hpp:142
bool SkipIfUnknown
Definition: headers.hpp:145
uint DataSize
Definition: headers.hpp:156
ushort UnpSize
Definition: headers.hpp:308
ushort CommCRC
Definition: headers.hpp:311
byte PswCheck[SIZE_PSWCHECK]
Definition: headers.hpp:293
byte Salt[SIZE_SALT50]
Definition: headers.hpp:292
uint Lg2Count
Definition: headers.hpp:291
bool UsePswCheck
Definition: headers.hpp:290
byte Method
Definition: headers.hpp:338
uint UnpSize
Definition: headers.hpp:336
uint EACRC
Definition: headers.hpp:339
byte UnpVer
Definition: headers.hpp:337
uint ArcDataCRC
Definition: headers.hpp:267
bool DataCRC
Definition: headers.hpp:274
bool NextVolume
Definition: headers.hpp:273
uint VolNumber
Definition: headers.hpp:269
bool RevSpace
Definition: headers.hpp:275
void Reset()
Definition: headers.hpp:277
bool StoreVolNumber
Definition: headers.hpp:276
RarTime atime
Definition: headers.hpp:190
HashValue FileHash
Definition: headers.hpp:196
char UnixOwnerName[256]
Definition: headers.hpp:243
char UnixGroupName[256]
Definition: headers.hpp:243
uint UnixOwnerID
Definition: headers.hpp:248
CRYPT_METHOD CryptMethod
Definition: headers.hpp:206
int64 UnpSize
Definition: headers.hpp:193
bool Solid
Definition: headers.hpp:222
bool UseHashKey
Definition: headers.hpp:214
wchar FileName[NM]
Definition: headers.hpp:184
uint Lg2Count
Definition: headers.hpp:220
size_t WinSize
Definition: headers.hpp:226
byte HashKey[SHA256_DIGEST_SIZE]
Definition: headers.hpp:218
byte PswCheck[SIZE_PSWCHECK]
Definition: headers.hpp:211
int64 PackSize
Definition: headers.hpp:192
RarTime ctime
Definition: headers.hpp:189
bool LargeFile
Definition: headers.hpp:230
bool UnixGroupNumeric
Definition: headers.hpp:242
bool UnixOwnerSet
Definition: headers.hpp:242
bool SubBlock
Definition: headers.hpp:234
uint FileFlags
Definition: headers.hpp:198
bool UnknownUnpSize
Definition: headers.hpp:203
byte Method
Definition: headers.hpp:179
bool Encrypted
Definition: headers.hpp:205
uint UnpVer
Definition: headers.hpp:178
uint UnixGroupID
Definition: headers.hpp:249
bool Inherited
Definition: headers.hpp:227
bool DirTarget
Definition: headers.hpp:240
bool CommentInHeader
Definition: headers.hpp:224
bool Dir
Definition: headers.hpp:223
bool CmpName(const wchar *Name)
Definition: headers.hpp:254
bool UnixOwnerNumeric
Definition: headers.hpp:242
byte Salt[SIZE_SALT50]
Definition: headers.hpp:208
uint SubFlags
Definition: headers.hpp:182
bool UsePswCheck
Definition: headers.hpp:210
bool SaltSet
Definition: headers.hpp:207
Array< byte > SubData
Definition: headers.hpp:186
wchar RedirName[NM]
Definition: headers.hpp:239
int64 MaxSize
Definition: headers.hpp:194
bool Version
Definition: headers.hpp:225
RarTime mtime
Definition: headers.hpp:188
HOST_SYSTEM_TYPE HSType
Definition: headers.hpp:236
byte HostOS
Definition: headers.hpp:177
FILE_SYSTEM_REDIRECT RedirType
Definition: headers.hpp:238
FileHeader & operator=(FileHeader &hd)
Definition: headers.cpp:40
byte InitV[SIZE_INITV]
Definition: headers.hpp:209
bool SplitBefore
Definition: headers.hpp:200
bool SplitAfter
Definition: headers.hpp:201
uint FileAttr
Definition: headers.hpp:181
void Reset()
Definition: headers.cpp:50
bool Locator
Definition: headers.hpp:166
ushort HighPosAV
Definition: headers.hpp:162
uint64 QOpenMaxSize
Definition: headers.hpp:168
bool PackComment
Definition: headers.hpp:165
uint PosAV
Definition: headers.hpp:163
uint64 RROffset
Definition: headers.hpp:169
uint64 QOpenOffset
Definition: headers.hpp:167
bool CommentInHeader
Definition: headers.hpp:164
uint64 RRMaxSize
Definition: headers.hpp:170
byte Mark[8]
Definition: headers.hpp:131
uint HeadSize
Definition: headers.hpp:134
uint TotalBlocks
Definition: headers.hpp:319
ushort RecSectors
Definition: headers.hpp:318
byte Mark[8]
Definition: headers.hpp:320
uint StreamCRC
Definition: headers.hpp:348
char StreamName[260]
Definition: headers.hpp:350
uint UnpSize
Definition: headers.hpp:345
ushort StreamNameSize
Definition: headers.hpp:349
ushort SubType
Definition: headers.hpp:301
ushort GroupNameSize
Definition: headers.hpp:327
char GroupName[256]
Definition: headers.hpp:330
ushort OwnerNameSize
Definition: headers.hpp:326
char OwnerName[256]
Definition: headers.hpp:329