1 /* useful byte arrays for rolling a ZIP archive */
2 /* see http://www.pkware.com/documents/casestudies/APPNOTE.TXT */
3 /* also http://www.unix-ag.uni-kl.de/~conrad/krypto/pkcrack/doc/appnote.iz.txt */
4 
5 /* byte-align structs to conform to ZIP format */
6 #pragma pack(push, 1)
7 
8 #define zip_version_default 10
9 #define zip_version_zip64 45
10 #define zip_utf8_flag 0x0800
11 #define zip_missing_crc32_flag 0x08
12 
13 typedef struct {
14     uint16_t   tag; //0x5455
15     uint16_t   size;
16     uint8_t    info;
17     uint32_t   mtime;
18     uint32_t   atime;
19 } ngx_zip_extra_field_local_t; // extended timestamp
20 
21 typedef struct {
22     uint16_t   tag; //0x5455
23     uint16_t   size;
24     uint8_t    info;
25     uint32_t   mtime;
26 } ngx_zip_extra_field_central_t;
27 
28 typedef struct {
29     uint16_t   tag; //0x7075
30     uint16_t   size;
31     uint8_t   version; //1
32     uint32_t   crc32;
33 } ngx_zip_extra_field_unicode_path_t;
34 
35 typedef struct { // not entirely writen...
36     uint16_t   tag; //0x0001
37     uint16_t   size; // size of this record (32)
38     uint64_t   uncompressed_size; //!! in all other places in spec uncompressed follow compressed!
39     uint64_t   compressed_size;
40     //these for CD:
41     uint64_t   relative_header_offset; //offset of local header record (cd)
42     uint32_t   disc_start; // no of disc where file starts (cd)
43 } ngx_zip_extra_field_zip64_full_t;
44 
45 typedef struct {
46     uint16_t   tag; //0x0001
47     uint16_t   size; //0x14
48     uint64_t   uncompressed_size;
49     uint64_t   compressed_size;
50 } ngx_zip_extra_field_zip64_sizes_only_t;
51 
52 typedef struct {
53     uint16_t   tag; //0x0001
54     uint16_t   size; //0x0C
55     uint64_t   relative_header_offset;
56 } ngx_zip_extra_field_zip64_offset_only_t;
57 
58 typedef struct {
59     uint16_t   tag; //0x0001
60     uint16_t   size; //0x1C
61     uint64_t   uncompressed_size;
62     uint64_t   compressed_size;
63     uint64_t   relative_header_offset;
64 } ngx_zip_extra_field_zip64_sizes_offset_t;
65 
66 
67 typedef struct {
68     uint32_t   signature; //0x08074b50
69     uint32_t   crc32;
70     uint32_t   compressed_size;
71     uint32_t   uncompressed_size;
72 } ngx_zip_data_descriptor_t;
73 
74 typedef struct {
75     uint32_t   signature;
76     uint32_t   crc32;
77     uint64_t   compressed_size;
78     uint64_t   uncompressed_size;
79 } ngx_zip_data_descriptor_zip64_t;
80 
81 
82 typedef struct {
83     uint32_t   signature; //0x04034b50
84     uint16_t   version;
85     uint16_t   flags;
86     uint16_t   compression_method;
87     uint32_t   mtime;
88     uint32_t   crc32;
89     uint32_t   compressed_size;
90     uint32_t   uncompressed_size;
91     uint16_t   filename_len;
92     uint16_t   extra_field_len;
93 } ngx_zip_local_file_header_t;
94 
95 
96 typedef struct {
97     uint32_t   signature; //0x02014b50
98     uint16_t   version_made_by;
99     uint16_t   version_needed;
100     uint16_t   flags;
101     uint16_t   compression_method;
102     uint32_t   mtime;
103     uint32_t   crc32;
104     uint32_t   compressed_size;
105     uint32_t   uncompressed_size;
106     uint16_t   filename_len;
107     uint16_t   extra_field_len;
108     uint16_t   comment_len;
109     uint16_t   disk_n;
110     uint16_t   attr_internal;
111     uint32_t   attr_external;
112     uint32_t   offset;
113 } ngx_zip_central_directory_file_header_t;
114 
115 typedef struct {
116     uint32_t   signature; //0x06054b50
117     uint16_t   disk_n;
118     uint16_t   cd_disk_n;
119     uint16_t   disk_entries_n;
120     uint16_t   entries_n;
121     uint32_t   size;
122     uint32_t   offset;
123     uint16_t   comment_len;
124 } ngx_zip_end_of_central_directory_record_t;
125 
126 typedef struct {
127     uint32_t   signature; // 0x06064b50
128     uint64_t   size; //of this record (+variable fields, but minus signature and this size field), Size = SizeOfFixedFields + SizeOfVariableData - 12
129     uint16_t   version_made_by;
130     uint16_t   version_needed;
131     uint32_t   disk_n;
132     uint32_t   cd_disk_n; // num of disk with start of CD
133     uint64_t   cd_n_entries_on_this_disk;
134     uint64_t   cd_n_entries_total;
135     uint64_t   cd_size;
136     uint64_t   cd_offset; // cd offset with respect to starting disk number
137     //variable fields go here
138 } ngx_zip_zip64_end_of_central_directory_record_t;
139 
140 typedef struct {
141     uint32_t signature; //0x07064b50
142     uint32_t z64_cd_disk_n; // number of disk with start of zip64 end of central directory
143     uint64_t cd_relative_offset;
144     uint32_t disks_total_n;
145 } ngx_zip_zip64_end_of_central_directory_locator_t;
146 #pragma pack(pop)
147