source: pwntcha/trunk/src/main.c @ 389

Last change on this file since 389 was 389, checked in by Sam Hocevar, 15 years ago
  • use OpenCV rather than Imlib2 if both are available.
  • cleaned up the slashdot code.
  • decode phpBB captchas.
  • added filter_contrast.
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1/*
2 * main.c: main function
3 * $Id: main.c 389 2005-01-03 21:48:54Z sam $
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
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <getopt.h>
16
17#include "config.h"
18#include "common.h"
19
20int main(int argc, char *argv[])
21{
22    char *mode = "auto";
23
24    int c;
25    int digit_optind = 0;
26
27    for(;;)
28    {
29        int this_option_optind = optind ? optind : 1;
30        int option_index = 0;
31        static struct option long_options[] =
32        {
33            { "mode", 1, 0, 'm' },
34            { "help", 0, 0, 'h' },
35            { "version", 0, 0, 'v' },
36            { 0, 0, 0, 0 }
37        };
38
39        c = getopt_long(argc, argv, "hm:v", long_options, &option_index);
40        if(c == -1)
41            break;
42
43        switch(c)
44        {
45        case 'h': /* --help */
46            printf("Usage: %s [OPTION]... FILE...\n", argv[0]);
47            printf("  -m, --mode      force operating mode\n");
48            printf("  -h, --help      display this help and exit\n");
49            printf("  -v, --version   output version information and exit\n");
50            return 0;
51        case 'm': /* --mode */
52            mode = optarg;
53            break;
54        case 'v': /* --version */
55            printf("pwntcha (CAPTCHA decoder) %s\n", VERSION);
56            printf("Written by Sam Hocevar.\n");
57            printf("\n");
58            printf("Copyright (C) 2004-2005 Sam Hocevar <sam@zoy.org>\n");
59            printf("This is free software; see the source for copying conditions.  There is NO\n");
60            printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
61            return 0;
62        case '?':
63            break;
64        default:
65            printf("%s: invalid option -- %i\n", argv[0], c);
66            printf("Try `%s --help' for more information.\n", argv[0]);
67            return 1;
68        }
69    }
70
71    if(optind >= argc)
72    {
73        printf("%s: too few arguments\n", argv[0]);
74        printf("Try `%s --help' for more information.\n", argv[0]);
75        return 1;
76    }
77
78    for(; optind < argc; optind++)
79    {
80        char *input = argv[optind], *result;
81        struct image *img;
82
83        img = image_load(argv[optind]);
84        if(!img)
85        {
86            fprintf(stderr, "%s: cannot load %s\n", argv[0], input);
87            printf("\n");
88            continue;
89        }
90
91        if(!strcmp(mode, "test"))
92            result = decode_test(img);
93        else if(!strcmp(mode, "phpbb"))
94            result = decode_phpbb(img);
95        else if(!strcmp(mode, "slashdot"))
96            result = decode_slashdot(img);
97        else
98        {
99            if(img->width == 320 && img->height == 50)
100                result = decode_phpbb(img);
101            else if(img->height == 69)
102                result = decode_slashdot(img);
103            else
104            {
105                fprintf(stderr, "%s: could not guess CAPTCHA type\n", argv[0]);
106                printf("\n");
107                image_free(img);
108                continue;
109            }
110        }
111
112        image_free(img);
113
114        if(!result)
115        {
116            fprintf(stderr, "%s: sorry, decoding failed\n", argv[0]);
117            printf("\n");
118            continue;
119        }
120
121        printf("%s\n", result);
122        free(result);
123    }
124
125    return 0;
126}
127
Note: See TracBrowser for help on using the repository browser.