Browse Source

* debug message system

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/pwntcha/trunk@392 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 21 years ago
parent
commit
2968baf95c
2 changed files with 40 additions and 5 deletions
  1. +3
    -0
      src/common.h
  2. +37
    -5
      src/main.c

+ 3
- 0
src/common.h View File

@@ -17,6 +17,9 @@ struct image
void *priv; void *priv;
}; };


/* debug function */
void dprintf(const char *fmt, ...);

/* available CAPTCHA decoders */ /* available CAPTCHA decoders */
char *decode_phpbb(struct image *img); char *decode_phpbb(struct image *img);
char *decode_slashdot(struct image *img); char *decode_slashdot(struct image *img);


+ 37
- 5
src/main.c View File

@@ -13,6 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include <stdarg.h>


#include "config.h" #include "config.h"
#include "common.h" #include "common.h"
@@ -23,10 +24,16 @@
# define MOREINFO "Try `%s -h' for more information.\n" # define MOREINFO "Try `%s -h' for more information.\n"
#endif #endif


/* Used for the debug messages */
char *argv0 = NULL;
int debug = 1;

int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *mode = "auto"; char *mode = "auto";


argv0 = argv[0];

int c; int c;
int digit_optind = 0; int digit_optind = 0;


@@ -39,13 +46,14 @@ int main(int argc, char *argv[])
{ {
{ "mode", 1, 0, 'm' }, { "mode", 1, 0, 'm' },
{ "help", 0, 0, 'h' }, { "help", 0, 0, 'h' },
{ "quiet", 0, 0, 'q' },
{ "version", 0, 0, 'v' }, { "version", 0, 0, 'v' },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };


c = getopt_long(argc, argv, "hm:v", long_options, &option_index);
c = getopt_long(argc, argv, "hm:qv", long_options, &option_index);
#else #else
c = getopt(argc, argv, "hm:v");
c = getopt(argc, argv, "hm:qv");
#endif #endif
if(c == -1) if(c == -1)
break; break;
@@ -56,10 +64,12 @@ int main(int argc, char *argv[])
printf("Usage: %s [OPTION]... FILE...\n", argv[0]); printf("Usage: %s [OPTION]... FILE...\n", argv[0]);
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
printf(" -m, --mode force operating mode\n"); printf(" -m, --mode force operating mode\n");
printf(" -q, --quiet do not print information messages\n");
printf(" -h, --help display this help and exit\n"); printf(" -h, --help display this help and exit\n");
printf(" -v, --version output version information and exit\n"); printf(" -v, --version output version information and exit\n");
#else #else
printf(" -m force operating mode\n"); printf(" -m force operating mode\n");
printf(" -q do not print information messages\n");
printf(" -h display this help and exit\n"); printf(" -h display this help and exit\n");
printf(" -v output version information and exit\n"); printf(" -v output version information and exit\n");
#endif #endif
@@ -67,6 +77,9 @@ int main(int argc, char *argv[])
case 'm': /* --mode */ case 'm': /* --mode */
mode = optarg; mode = optarg;
break; break;
case 'q': /* --quiet */
debug = 0;
break;
case 'v': /* --version */ case 'v': /* --version */
printf("pwntcha (captcha decoder) %s\n", VERSION); printf("pwntcha (captcha decoder) %s\n", VERSION);
printf("Written by Sam Hocevar.\n"); printf("Written by Sam Hocevar.\n");
@@ -100,7 +113,7 @@ int main(int argc, char *argv[])
img = image_load(argv[optind]); img = image_load(argv[optind]);
if(!img) if(!img)
{ {
fprintf(stderr, "%s: cannot load %s\n", argv[0], input);
dprintf("cannot load %s\n", input);
printf("\n"); printf("\n");
continue; continue;
} }
@@ -114,12 +127,18 @@ int main(int argc, char *argv[])
else else
{ {
if(img->width == 320 && img->height == 50) if(img->width == 320 && img->height == 50)
{
dprintf("autodetecting phpBB captcha\n");
result = decode_phpbb(img); result = decode_phpbb(img);
}
else if(img->height == 69) else if(img->height == 69)
{
dprintf("autodetecting slashdot captcha\n");
result = decode_slashdot(img); result = decode_slashdot(img);
}
else else
{ {
fprintf(stderr, "%s: could not guess captcha type\n", argv[0]);
dprintf("could not guess captcha type\n");
printf("\n"); printf("\n");
image_free(img); image_free(img);
continue; continue;
@@ -130,7 +149,7 @@ int main(int argc, char *argv[])


if(!result) if(!result)
{ {
fprintf(stderr, "%s: sorry, decoding failed\n", argv[0]);
dprintf("sorry, decoding failed\n");
printf("\n"); printf("\n");
continue; continue;
} }
@@ -142,3 +161,16 @@ int main(int argc, char *argv[])
return 0; return 0;
} }


void dprintf(const char *fmt, ...)
{
va_list args;

if(!debug)
return;

va_start(args, fmt);
fprintf(stderr, "%s: ", argv0);
vfprintf(stderr, fmt, args);
va_end(args);
}


Loading…
Cancel
Save