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
|
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
|
+
-
-
+
+
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
-
+
|
#import "OFDate.h"
#import "OFNumber.h"
#import "OFSeekableStream.h"
#import "OFStream.h"
#import "OFString.h"
#import "OFInvalidFormatException.h"
#import "OFUnsupportedVersionException.h"
@implementation OFZooArchiveEntry
@synthesize compressionMethod = _compressionMethod, CRC16 = _CRC16;
@synthesize uncompressedSize = _uncompressedSize;
@synthesize headerType = _headerType, compressionMethod = _compressionMethod;
@synthesize CRC16 = _CRC16, uncompressedSize = _uncompressedSize;
@synthesize compressedSize = _compressedSize;
@synthesize minVersionNeeded = _minVersionNeeded, deleted = _deleted;
@synthesize fileComment = _fileComment, POSIXPermissions = _POSIXPermissions;
@synthesize fileComment = _fileComment;
@synthesize operatingSystemIdentifier = _operatingSystemIdentifier;
@synthesize POSIXPermissions = _POSIXPermissions;
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (instancetype)of_initWithStream: (OF_KINDOF(OFStream *))stream
encoding: (OFStringEncoding)encoding
{
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
char fileNameBuffer[13];
uint32_t commentOffset;
uint16_t commentLength;
if ([stream readLittleEndianInt32] != 0xFDC4A7DC)
@throw [OFInvalidFormatException exception];
/* Type seems to be always 2 */
if ([stream readInt8] != 2)
@throw [OFInvalidFormatException exception];
if ((_headerType = [stream readInt8]) > 2)
@throw [OFUnsupportedVersionException
exceptionWithVersion: [OFString
stringWithFormat: @"%u", _headerType]];
_compressionMethod = [stream readInt8];
_nextHeaderOffset = [stream readLittleEndianInt32];
if (_nextHeaderOffset == 0) {
[self release];
return nil;
}
_dataOffset = [stream readLittleEndianInt32];
_lastModifiedFileDate = [stream readLittleEndianInt16];
_lastModifiedFileTime = [stream readLittleEndianInt16];
_CRC16 = [stream readLittleEndianInt16];
_uncompressedSize = [stream readLittleEndianInt32];
_compressedSize = [stream readLittleEndianInt32];
_minVersionNeeded = [stream readBigEndianInt16];
_deleted = [stream readInt8];
/* Unknown. Most likely padding to get to 2 byte alignment? */
/*
* File structure, whatever that is meant to be. Seems to
* always be 0.
*/
[stream readInt8];
commentOffset = [stream readLittleEndianInt32];
commentLength = [stream readLittleEndianInt16];
[stream readIntoBuffer: fileNameBuffer exactLength: 13];
if (fileNameBuffer[12] != '\0')
fileNameBuffer[12] = '\0';
if ((_minVersionNeeded >> 8) == 2) {
if (_headerType >= 2) {
uint16_t extraLength = [stream readLittleEndianInt16];
uint8_t fileNameLength, directoryNameLength;
if (extraLength < 10)
@throw [OFInvalidFormatException exception];
_timeZone = [stream readInt8];
|
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
-
-
+
+
|
_directoryName = [[stream
readStringWithLength: directoryNameLength
encoding: encoding] copy];
extraLength -= directoryNameLength;
}
if (extraLength >= 2) {
/* System ID */
[stream readLittleEndianInt16];
_operatingSystemIdentifier =
[stream readLittleEndianInt16];
extraLength -= 2;
}
if (extraLength >= 3) {
uint8_t attributes[3];
[stream readIntoBuffer: attributes
|