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 20 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;
};

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

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


+ 37
- 5
src/main.c View File

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

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

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

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

argv0 = argv[0];

int c;
int digit_optind = 0;

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

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