Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

270 строки
8.1 KiB

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