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