Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

224 rader
6.4 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]... FILE...\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. dprintf("cannot load %s\n", input);
  113. printf("\n");
  114. continue;
  115. }
  116. count = filter_count(img);
  117. dprintf("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, "linuxfr"))
  126. result = decode_linuxfr(img);
  127. else if(!strcmp(mode, "phpbb"))
  128. result = decode_phpbb(img);
  129. else if(!strcmp(mode, "scode"))
  130. result = decode_scode(img);
  131. else if(!strcmp(mode, "slashdot"))
  132. result = decode_slashdot(img);
  133. else if(!strcmp(mode, "vbulletin"))
  134. result = decode_vbulletin(img);
  135. else
  136. {
  137. if(img->width == 155 && img->height == 50)
  138. {
  139. dprintf("autodetected authimage captcha\n");
  140. result = decode_authimage(img);
  141. }
  142. else if(img->width == 100 && img->height == 40 && count < 6)
  143. {
  144. dprintf("autodetected linuxfr captcha\n");
  145. result = decode_linuxfr(img);
  146. }
  147. else if(img->width == 320 && img->height == 50)
  148. {
  149. dprintf("autodetected phpBB captcha\n");
  150. result = decode_phpbb(img);
  151. }
  152. else if(img->height <= 40 && count < 10)
  153. {
  154. dprintf("autodetected scode/trencaspammers captcha\n");
  155. result = decode_scode(img);
  156. }
  157. else if(img->height <= 30 && count < 100)
  158. {
  159. dprintf("autodetected clubic captcha\n");
  160. result = decode_clubic(img);
  161. }
  162. else if(img->height == 69)
  163. {
  164. dprintf("autodetected slashdot captcha\n");
  165. result = decode_slashdot(img);
  166. }
  167. else if(img->height == 61)
  168. {
  169. dprintf("autodetected vbulletin captcha\n");
  170. result = decode_vbulletin(img);
  171. }
  172. else
  173. {
  174. dprintf("could not guess captcha type\n");
  175. printf("\n");
  176. image_free(img);
  177. continue;
  178. }
  179. }
  180. image_free(img);
  181. if(!result)
  182. {
  183. dprintf("sorry, decoding failed\n");
  184. printf("\n");
  185. continue;
  186. }
  187. printf("%s\n", result);
  188. free(result);
  189. }
  190. return 0;
  191. }
  192. void dprintf(const char *fmt, ...)
  193. {
  194. va_list args;
  195. if(!debug)
  196. return;
  197. va_start(args, fmt);
  198. fprintf(stderr, "%s: ", argv0);
  199. vfprintf(stderr, fmt, args);
  200. va_end(args);
  201. }