1 | /* |
---|
2 | * main.c: main function |
---|
3 | * $Id: main.c 2315 2008-04-26 07:25:03Z sam $ |
---|
4 | * |
---|
5 | * Copyright: (c) 2004 Sam Hocevar <sam@zoy.org> |
---|
6 | * This program is free software. It comes without any warranty, to |
---|
7 | * the extent permitted by applicable law. You can redistribute it |
---|
8 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
9 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
10 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
11 | */ |
---|
12 | |
---|
13 | #include <stdio.h> |
---|
14 | #include <stdlib.h> |
---|
15 | #include <string.h> |
---|
16 | #include <getopt.h> |
---|
17 | #include <stdarg.h> |
---|
18 | |
---|
19 | #include "config.h" |
---|
20 | #include "common.h" |
---|
21 | |
---|
22 | #ifdef HAVE_GETOPT_LONG |
---|
23 | # define MOREINFO "Try `%s --help' for more information.\n" |
---|
24 | #else |
---|
25 | # define MOREINFO "Try `%s -h' for more information.\n" |
---|
26 | #endif |
---|
27 | |
---|
28 | /* Used for the debug messages */ |
---|
29 | char *argv0 = NULL; |
---|
30 | char *share = NULL; |
---|
31 | int debug = 1; |
---|
32 | |
---|
33 | int main(int argc, char *argv[]) |
---|
34 | { |
---|
35 | char *mode = "auto"; |
---|
36 | int c; |
---|
37 | int digit_optind = 0; |
---|
38 | |
---|
39 | argv0 = argv[0]; |
---|
40 | share = "share"; |
---|
41 | |
---|
42 | for(;;) |
---|
43 | { |
---|
44 | int this_option_optind = optind ? optind : 1; |
---|
45 | #ifdef HAVE_GETOPT_LONG |
---|
46 | int option_index = 0; |
---|
47 | static struct option long_options[] = |
---|
48 | { |
---|
49 | { "help", 0, 0, 'h' }, |
---|
50 | { "mode", 1, 0, 'm' }, |
---|
51 | { "share", 1, 0, 's' }, |
---|
52 | { "quiet", 0, 0, 'q' }, |
---|
53 | { "version", 0, 0, 'v' }, |
---|
54 | { 0, 0, 0, 0 } |
---|
55 | }; |
---|
56 | |
---|
57 | c = getopt_long(argc, argv, "hm:s:qv", long_options, &option_index); |
---|
58 | #else |
---|
59 | c = getopt(argc, argv, "hm:s:qv"); |
---|
60 | #endif |
---|
61 | if(c == -1) |
---|
62 | break; |
---|
63 | |
---|
64 | switch(c) |
---|
65 | { |
---|
66 | case 'h': /* --help */ |
---|
67 | printf("Usage: %s [OPTION]... IMAGE...\n", argv[0]); |
---|
68 | #ifdef HAVE_GETOPT_LONG |
---|
69 | printf(" -m, --mode <mode> force operating mode\n"); |
---|
70 | printf(" -s, --share <dir> specify shared dir\n"); |
---|
71 | printf(" -q, --quiet do not print information messages\n"); |
---|
72 | printf(" -h, --help display this help and exit\n"); |
---|
73 | printf(" -v, --version output version information and exit\n"); |
---|
74 | #else |
---|
75 | printf(" -m <mode> force operating mode\n"); |
---|
76 | printf(" -s <dir> specify shared dir\n"); |
---|
77 | printf(" -q do not print information messages\n"); |
---|
78 | printf(" -h display this help and exit\n"); |
---|
79 | printf(" -v output version information and exit\n"); |
---|
80 | #endif |
---|
81 | return 0; |
---|
82 | case 'm': /* --mode */ |
---|
83 | mode = optarg; |
---|
84 | break; |
---|
85 | case 'q': /* --quiet */ |
---|
86 | debug = 0; |
---|
87 | break; |
---|
88 | case 's': /* --quiet */ |
---|
89 | share = optarg; |
---|
90 | break; |
---|
91 | case 'v': /* --version */ |
---|
92 | printf("pwntcha (captcha decoder) %s\n", PACKAGE_VERSION); |
---|
93 | printf("Written by Sam Hocevar.\n"); |
---|
94 | printf("\n"); |
---|
95 | printf("Copyright (C) 2004-2005 Sam Hocevar <sam@zoy.org>\n"); |
---|
96 | printf("This is free software; see the source for copying conditions. There is NO\n"); |
---|
97 | printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); |
---|
98 | return 0; |
---|
99 | case '?': |
---|
100 | printf(MOREINFO, argv[0]); |
---|
101 | return 1; |
---|
102 | default: |
---|
103 | printf("%s: invalid option -- %i\n", argv[0], c); |
---|
104 | printf(MOREINFO, argv[0]); |
---|
105 | return 1; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | if(optind >= argc) |
---|
110 | { |
---|
111 | printf("%s: too few arguments\n", argv[0]); |
---|
112 | printf(MOREINFO, argv[0]); |
---|
113 | return 1; |
---|
114 | } |
---|
115 | |
---|
116 | for(; optind < argc; optind++) |
---|
117 | { |
---|
118 | char *input = argv[optind], *result; |
---|
119 | struct image *img; |
---|
120 | int count; |
---|
121 | |
---|
122 | img = image_load(argv[optind]); |
---|
123 | if(!img) |
---|
124 | { |
---|
125 | pwnprint("cannot load %s\n", input); |
---|
126 | printf("\n"); |
---|
127 | continue; |
---|
128 | } |
---|
129 | |
---|
130 | count = filter_count(img); |
---|
131 | pwnprint("image size %ix%i, %i colours\n", |
---|
132 | img->width, img->height, count); |
---|
133 | |
---|
134 | if(!strcmp(mode, "test")) |
---|
135 | result = decode_test(img); |
---|
136 | else if(!strcmp(mode, "authimage")) |
---|
137 | result = decode_authimage(img); |
---|
138 | else if(!strcmp(mode, "clubic")) |
---|
139 | result = decode_clubic(img); |
---|
140 | else if(!strcmp(mode, "java")) |
---|
141 | result = decode_java(img); |
---|
142 | else if(!strcmp(mode, "linuxfr")) |
---|
143 | result = decode_linuxfr(img); |
---|
144 | else if(!strcmp(mode, "livejournal")) |
---|
145 | result = decode_livejournal(img); |
---|
146 | else if(!strcmp(mode, "lmt")) |
---|
147 | result = decode_lmt(img); |
---|
148 | else if(!strcmp(mode, "paypal")) |
---|
149 | result = decode_paypal(img); |
---|
150 | else if(!strcmp(mode, "phpbb")) |
---|
151 | result = decode_phpbb(img); |
---|
152 | else if(!strcmp(mode, "scode")) |
---|
153 | result = decode_scode(img); |
---|
154 | else if(!strcmp(mode, "slashdot")) |
---|
155 | result = decode_slashdot(img); |
---|
156 | else if(!strcmp(mode, "vbulletin")) |
---|
157 | result = decode_vbulletin(img); |
---|
158 | else if(!strcmp(mode, "xanga")) |
---|
159 | result = decode_xanga(img); |
---|
160 | else |
---|
161 | { |
---|
162 | if(img->width == 155 && img->height == 50) |
---|
163 | { |
---|
164 | pwnprint("probably an authimage captcha\n"); |
---|
165 | result = decode_authimage(img); |
---|
166 | } |
---|
167 | else if(img->width == 175 && img->height == 35) |
---|
168 | { |
---|
169 | pwnprint("probably a livejournal captcha\n"); |
---|
170 | result = decode_livejournal(img); |
---|
171 | } |
---|
172 | else if(img->width == 100 && img->height == 40 && count < 6) |
---|
173 | { |
---|
174 | pwnprint("probably a linuxfr captcha\n"); |
---|
175 | result = decode_linuxfr(img); |
---|
176 | } |
---|
177 | else if(img->width == 69 && img->height == 35) |
---|
178 | { |
---|
179 | pwnprint("probably a lmt.lv captcha\n"); |
---|
180 | result = decode_lmt(img); |
---|
181 | } |
---|
182 | else if(img->width == 208 && img->height == 26) |
---|
183 | { |
---|
184 | pwnprint("probably a Paypal captcha\n"); |
---|
185 | result = decode_paypal(img); |
---|
186 | } |
---|
187 | else if(img->width == 320 && img->height == 50) |
---|
188 | { |
---|
189 | pwnprint("probably a phpBB captcha\n"); |
---|
190 | result = decode_phpbb(img); |
---|
191 | } |
---|
192 | else if(img->width == 170 && img->height == 50) |
---|
193 | { |
---|
194 | pwnprint("probably a Xanga captcha\n"); |
---|
195 | result = decode_xanga(img); |
---|
196 | } |
---|
197 | else if(img->height <= 40 && count < 10) |
---|
198 | { |
---|
199 | pwnprint("probably a scode/trencaspammers captcha\n"); |
---|
200 | result = decode_scode(img); |
---|
201 | } |
---|
202 | else if(img->height <= 30 && count < 100) |
---|
203 | { |
---|
204 | pwnprint("probably a clubic captcha\n"); |
---|
205 | result = decode_clubic(img); |
---|
206 | } |
---|
207 | else if(img->height == 69) |
---|
208 | { |
---|
209 | pwnprint("probably a slashdot captcha\n"); |
---|
210 | result = decode_slashdot(img); |
---|
211 | } |
---|
212 | else if(img->width == 200 && img->height == 100) |
---|
213 | { |
---|
214 | pwnprint("probably a java captcha\n"); |
---|
215 | result = decode_java(img); |
---|
216 | } |
---|
217 | else if(img->width == 290 && img->height == 80) |
---|
218 | { |
---|
219 | pwnprint("probably a ticketmaster captcha\n"); |
---|
220 | result = decode_ticketmaster(img); |
---|
221 | } |
---|
222 | else if(img->width == 200 && img->height == 40) |
---|
223 | { |
---|
224 | pwnprint("probably a tickets.com captcha\n"); |
---|
225 | result = decode_tickets(img); |
---|
226 | } |
---|
227 | else if(img->height == 61) |
---|
228 | { |
---|
229 | pwnprint("probably a vbulletin captcha\n"); |
---|
230 | result = decode_vbulletin(img); |
---|
231 | } |
---|
232 | else if(img->width == 480 && img->height == 360 && count == 253) |
---|
233 | { |
---|
234 | pwnprint("probably not a captcha\n"); |
---|
235 | result = decode_easter_eggs(img); |
---|
236 | } |
---|
237 | else |
---|
238 | { |
---|
239 | pwnprint("could not guess captcha type\n"); |
---|
240 | printf("\n"); |
---|
241 | image_free(img); |
---|
242 | continue; |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | image_free(img); |
---|
247 | |
---|
248 | if(!result) |
---|
249 | { |
---|
250 | pwnprint("sorry, decoding failed\n"); |
---|
251 | printf("\n"); |
---|
252 | continue; |
---|
253 | } |
---|
254 | |
---|
255 | printf("%s\n", result); |
---|
256 | fflush(stdout); |
---|
257 | free(result); |
---|
258 | } |
---|
259 | |
---|
260 | return 0; |
---|
261 | } |
---|
262 | |
---|
263 | void pwnprint(const char *fmt, ...) |
---|
264 | { |
---|
265 | va_list args; |
---|
266 | |
---|
267 | if(!debug) |
---|
268 | return; |
---|
269 | |
---|
270 | va_start(args, fmt); |
---|
271 | fprintf(stderr, "%s: ", argv0); |
---|
272 | vfprintf(stderr, fmt, args); |
---|
273 | va_end(args); |
---|
274 | } |
---|
275 | |
---|