From 336bac428c9e29b87da46e99e512747b534724e1 Mon Sep 17 00:00:00 2001 From: sam Date: Wed, 5 Jan 2005 00:18:49 +0000 Subject: [PATCH] * keep the font loaded across decodings. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/pwntcha/trunk@421 92316355-f0b4-4df1-b90c-862c8a59935f --- src/linuxfr.c | 13 ++++++++----- src/phpbb.c | 11 +++++++---- src/slashdot.c | 20 ++++++++++++-------- src/vbulletin.c | 13 ++++++++----- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/linuxfr.c b/src/linuxfr.c index f92d1d8..4307c68 100644 --- a/src/linuxfr.c +++ b/src/linuxfr.c @@ -18,6 +18,7 @@ #include "common.h" #define FONTNAME "share/font_linuxfr.png" +static struct image *font = NULL; /* Main function */ char *decode_linuxfr(struct image *img) @@ -26,15 +27,18 @@ char *decode_linuxfr(struct image *img) "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"; char *result; - struct image *tmp, *font; + struct image *tmp; int x, y, r, g, b, i, j, c; int stats[40]; - font = image_load(FONTNAME); if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); - exit(-1); + font = image_load(FONTNAME); + if(!font) + { + fprintf(stderr, "cannot load font %s\n", FONTNAME); + exit(-1); + } } /* linuxfr captchas have 7 characters */ @@ -141,7 +145,6 @@ char *decode_linuxfr(struct image *img) } image_free(tmp); - image_free(font); if(strlen(result) != 7) { diff --git a/src/phpbb.c b/src/phpbb.c index 77f67b1..0c05954 100644 --- a/src/phpbb.c +++ b/src/phpbb.c @@ -19,6 +19,7 @@ /* Our macros */ #define FONTNAME "share/font_phpbb.png" +static struct image *font = NULL; /* Main function */ char *decode_phpbb(struct image *img) @@ -26,7 +27,6 @@ char *decode_phpbb(struct image *img) char all[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; char *result; struct image *tmp1, *tmp2, *tmp3; - struct image *font = image_load(FONTNAME); int x, y, i = 0; int r, g, b; int xmin, xmax, ymin, ymax, cur, offset = -1; @@ -34,8 +34,12 @@ char *decode_phpbb(struct image *img) if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); - exit(-1); + font = image_load(FONTNAME); + if(!font) + { + fprintf(stderr, "cannot load font %s\n", FONTNAME); + exit(-1); + } } /* phpBB captchas have 6 characters */ @@ -125,7 +129,6 @@ char *decode_phpbb(struct image *img) image_free(tmp1); image_free(tmp2); image_free(tmp3); - image_free(font); return result; } diff --git a/src/slashdot.c b/src/slashdot.c index b4ee5cf..7029880 100644 --- a/src/slashdot.c +++ b/src/slashdot.c @@ -18,16 +18,17 @@ #include "config.h" #include "common.h" +static struct image *count_objects(struct image *img); +static struct image *rotate(struct image *img); +static struct image *cut_cells(struct image *img); +static struct image *find_glyphs(struct image *img); + /* Our macros */ #define FACTOR 1 #define FONTNAME "share/font_slashdot.png" // use with FACTOR = 1 //#define FONTNAME "share/font.png" // use with FACTOR = 2 //#define FONTNAME "share/font_dilated.png" // use with FACTOR = 2 - -static struct image *count_objects(struct image *img); -static struct image *rotate(struct image *img); -static struct image *cut_cells(struct image *img); -static struct image *find_glyphs(struct image *img); +static struct image *font = NULL; /* Global stuff */ struct { int xmin, ymin, xmax, ymax; } objlist[100]; @@ -237,7 +238,6 @@ static struct image *find_glyphs(struct image *img) } glyphs[22]; struct image *dst; - struct image *font = image_load(FONTNAME); int x, y, i = 0; int r, g, b; int xmin, xmax, ymin, ymax, incell = 0, count = 0, startx = 0, cur = 0; @@ -245,8 +245,12 @@ static struct image *find_glyphs(struct image *img) if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); - exit(-1); + font = image_load(FONTNAME); + if(!font) + { + fprintf(stderr, "cannot load font %s\n", FONTNAME); + exit(-1); + } } dst = image_new(img->width, img->height); diff --git a/src/vbulletin.c b/src/vbulletin.c index e71f0dc..520d24a 100644 --- a/src/vbulletin.c +++ b/src/vbulletin.c @@ -18,21 +18,25 @@ #include "common.h" #define FONTNAME "share/font_vbulletin.png" +static struct image *font = NULL; /* Main function */ char *decode_vbulletin(struct image *img) { char all[] = "2346789ABCDEFGHJKLMNPRTWXYZ"; char *result; - struct image *tmp1, *tmp2, *tmp3, *font; + struct image *tmp1, *tmp2, *tmp3; int limits[6] = { 26, 53, 80, 107, 134, 160 }; int x, y, r, g, b, i, j; - font = image_load(FONTNAME); if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); - exit(-1); + font = image_load(FONTNAME); + if(!font) + { + fprintf(stderr, "cannot load font %s\n", FONTNAME); + exit(-1); + } } /* vBulletin captchas have 6 characters */ @@ -134,7 +138,6 @@ char *decode_vbulletin(struct image *img) image_free(tmp1); image_free(tmp2); image_free(tmp3); - image_free(font); return result; }