1 |
#ifdef HAVE_CONFIG_H |
2 |
#include "config.h" |
3 |
#endif |
4 |
|
5 |
#include <stdio.h> |
6 |
#include <errno.h> |
7 |
#include <string.h> |
8 |
#include "crack.h" |
9 |
|
10 |
u8 pw[MAX_PW + 1] = "aaaaaa"; |
11 |
u8 *pw_end; /* must point to the trailing zero byte. */ |
12 |
|
13 |
u8 files[MAX_FILES * HEADER_SIZE]; |
14 |
const char *file_path[MAX_FILES]; |
15 |
int file_count; |
16 |
|
17 |
u8 bf_next[256]; |
18 |
u8 bf_last; |
19 |
|
20 |
int verbosity; |
21 |
|
22 |
static u8 mult_tab[16384]; |
23 |
|
24 |
static u32 |
25 |
fgetu32 (FILE * f) |
26 |
{ |
27 |
register u32 r; |
28 |
|
29 |
r = fgetc(f) << 0; |
30 |
r |= fgetc(f) << 8; |
31 |
r |= fgetc(f) << 16; |
32 |
r |= fgetc(f) << 24; |
33 |
|
34 |
return r; |
35 |
} |
36 |
|
37 |
static u32 |
38 |
fgetu16 (FILE * f) |
39 |
{ |
40 |
register u32 r; |
41 |
|
42 |
r = fgetc(f) << 0; |
43 |
r |= fgetc(f) << 8; |
44 |
|
45 |
return r; |
46 |
} |
47 |
|
48 |
static void |
49 |
load_zip (const char *path) |
50 |
{ |
51 |
FILE *f = fopen (path, "rb"); |
52 |
|
53 |
if (!f) |
54 |
{ |
55 |
fprintf (stderr, "skipping '%s': %s\n", path, strerror (errno)); |
56 |
return; |
57 |
} |
58 |
|
59 |
while (!feof (f)) |
60 |
{ |
61 |
u32 id = fgetu32 (f); |
62 |
|
63 |
if (id == 0x04034b50UL) |
64 |
{ |
65 |
u16 version = fgetu16 (f); |
66 |
u16 flags = fgetu16 (f); |
67 |
u16 compression_method = fgetu16 (f); |
68 |
u16 lastmodtime = fgetu16 (f); |
69 |
u16 lastmoddate = fgetu16 (f); |
70 |
u32 crc32 = fgetu32 (f); |
71 |
u32 compr_size = fgetu32 (f); |
72 |
u32 uncompr_size = fgetu32 (f); |
73 |
u16 name_len = fgetu16 (f); |
74 |
u16 extra_field_len = fgetu16 (f); |
75 |
|
76 |
char zip_path[1024]; |
77 |
|
78 |
/* these are unused. */ |
79 |
(void) lastmoddate; |
80 |
(void) lastmodtime; |
81 |
(void) compression_method; |
82 |
(void) version; |
83 |
|
84 |
if (name_len < 1024) |
85 |
{ |
86 |
fread (zip_path, name_len, 1, f); |
87 |
zip_path[name_len] = 0; |
88 |
} |
89 |
else |
90 |
{ |
91 |
fprintf (stderr, "filename too long (>1023 bytes), skipping zipfile\n"); |
92 |
goto out; |
93 |
} |
94 |
|
95 |
fseek (f, extra_field_len, SEEK_CUR); |
96 |
|
97 |
if (flags & 1) |
98 |
{ |
99 |
if (compr_size >= 12) |
100 |
{ |
101 |
u8 *file = files + HEADER_SIZE * file_count; |
102 |
fread (file, FILE_SIZE, 1, f); |
103 |
|
104 |
if (flags & 8) |
105 |
{ |
106 |
/* extended header format? */ |
107 |
file[FILE_SIZE] = lastmodtime >> 8; |
108 |
file[FILE_SIZE + 1] = lastmodtime; |
109 |
} |
110 |
else |
111 |
{ |
112 |
file[FILE_SIZE] = crc32 >> 24; |
113 |
file[FILE_SIZE + 1] = crc32 >> 16; |
114 |
} |
115 |
|
116 |
file_path[file_count] = strdup (path); |
117 |
|
118 |
if (verbosity) |
119 |
printf ("found file '%s', (size cp/uc %6lu/%6lu, flags %lx, chk %02x%02x)\n", |
120 |
zip_path, (unsigned long) compr_size, (unsigned long) uncompr_size, (unsigned long) flags, |
121 |
file[FILE_SIZE], file[FILE_SIZE+1]); |
122 |
|
123 |
if (++file_count >= MAX_FILES) |
124 |
{ |
125 |
if (verbosity) |
126 |
printf ("%d file maximum reached, skipping further files\n", MAX_FILES); |
127 |
|
128 |
goto out; |
129 |
} |
130 |
|
131 |
compr_size -= 12; |
132 |
} |
133 |
else |
134 |
{ |
135 |
fprintf (stderr, "'%s' is corrupted, skipping zipfile\n", zip_path); |
136 |
goto out; |
137 |
} |
138 |
} |
139 |
else if (verbosity) |
140 |
printf ("'%s' is not encrypted, skipping\n", zip_path); |
141 |
|
142 |
fseek (f, compr_size, SEEK_CUR); |
143 |
} |
144 |
else if (id == 0x08074b50UL) /* extended local sig (?) */ |
145 |
{ |
146 |
fseek (f, 12, SEEK_CUR); |
147 |
} |
148 |
else if (id == 0x30304b50UL) |
149 |
{ |
150 |
/* ignore */ |
151 |
} |
152 |
else if (id == 0x02014b50UL || id == 0x06054b50UL) |
153 |
{ |
154 |
goto out; |
155 |
} |
156 |
else |
157 |
{ |
158 |
fprintf (stderr, "found id %08lx, '%s' is not a zipfile ver 2.xx, skipping\n", |
159 |
(unsigned long) id, path); |
160 |
goto out; |
161 |
} |
162 |
} |
163 |
|
164 |
out: |
165 |
fclose (f); |
166 |
} |
167 |
|
168 |
#include "cpmask.c" |
169 |
#include "crackdef.c" |