diff --git a/src/authimage.c b/src/authimage.c index e5d2250..5a73a92 100644 --- a/src/authimage.c +++ b/src/authimage.c @@ -18,7 +18,7 @@ #include "config.h" #include "common.h" -#define FONTNAME "share/font_authimage.png" +#define FONTNAME "font_authimage.png" static struct image *font = NULL; /* Main function */ @@ -31,10 +31,12 @@ char *decode_authimage(struct image *img) if(!font) { - font = image_load(FONTNAME); + char fontname[BUFSIZ]; + sprintf(fontname, "%s/%s", share, FONTNAME); + font = image_load(fontname); if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); + fprintf(stderr, "cannot load font %s\n", fontname); exit(-1); } } diff --git a/src/clubic.c b/src/clubic.c index 12a852f..5db7e75 100644 --- a/src/clubic.c +++ b/src/clubic.c @@ -20,7 +20,7 @@ static struct image *find_glyphs(struct image *img); /* Our macros */ -#define FONTNAME "share/font_clubic.png" +#define FONTNAME "font_clubic.png" static struct image *font = NULL; char *result; @@ -31,10 +31,12 @@ char *decode_clubic(struct image *img) if(!font) { - font = image_load(FONTNAME); + char fontname[BUFSIZ]; + sprintf(fontname, "%s/%s", share, FONTNAME); + font = image_load(fontname); if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); + fprintf(stderr, "cannot load font %s\n", fontname); exit(-1); } } diff --git a/src/common.h b/src/common.h index 5d1ab24..10349bc 100644 --- a/src/common.h +++ b/src/common.h @@ -17,6 +17,9 @@ struct image void *priv; }; +/* global variables */ +extern char *share; + /* debug function */ void dprintf(const char *fmt, ...); diff --git a/src/filters.c b/src/filters.c index cd3a39e..b884d7d 100644 --- a/src/filters.c +++ b/src/filters.c @@ -17,12 +17,6 @@ #include "config.h" #include "common.h" -/* Our macros */ -#define FACTOR 1 -//#define FONTNAME "share/font.png" // use with FACTOR = 2 -//#define FONTNAME "share/font_dilated.png" // use with FACTOR = 2 -#define FONTNAME "share/font_dilated_half.png" // use with FACTOR = 1 - /* Functions */ void filter_flood_fill(struct image *img, int x, int y, int r, int g, int b) { diff --git a/src/linuxfr.c b/src/linuxfr.c index b087726..ee416ca 100644 --- a/src/linuxfr.c +++ b/src/linuxfr.c @@ -17,7 +17,7 @@ #include "config.h" #include "common.h" -#define FONTNAME "share/font_linuxfr.png" +#define FONTNAME "font_linuxfr.png" static struct image *font = NULL; /* Main function */ @@ -33,10 +33,12 @@ char *decode_linuxfr(struct image *img) if(!font) { - font = image_load(FONTNAME); + char fontname[BUFSIZ]; + sprintf(fontname, "%s/%s", share, FONTNAME); + font = image_load(fontname); if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); + fprintf(stderr, "cannot load font %s\n", fontname); exit(-1); } } diff --git a/src/main.c b/src/main.c index ef75200..e626197 100644 --- a/src/main.c +++ b/src/main.c @@ -26,6 +26,7 @@ /* Used for the debug messages */ char *argv0 = NULL; +char *share = NULL; int debug = 1; int main(int argc, char *argv[]) @@ -35,6 +36,7 @@ int main(int argc, char *argv[]) int digit_optind = 0; argv0 = argv[0]; + share = "share"; for(;;) { @@ -43,16 +45,17 @@ int main(int argc, char *argv[]) int option_index = 0; static struct option long_options[] = { - { "mode", 1, 0, 'm' }, { "help", 0, 0, 'h' }, + { "mode", 1, 0, 'm' }, + { "share", 1, 0, 's' }, { "quiet", 0, 0, 'q' }, { "version", 0, 0, 'v' }, { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "hm:qv", long_options, &option_index); + c = getopt_long(argc, argv, "hm:s:qv", long_options, &option_index); #else - c = getopt(argc, argv, "hm:qv"); + c = getopt(argc, argv, "hm:s:qv"); #endif if(c == -1) break; @@ -62,15 +65,17 @@ int main(int argc, char *argv[]) case 'h': /* --help */ 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"); + printf(" -m, --mode force operating mode\n"); + printf(" -s, --share specify shared dir\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"); + printf(" -m force operating mode\n"); + printf(" -s specify shared dir\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 return 0; case 'm': /* --mode */ @@ -79,6 +84,9 @@ int main(int argc, char *argv[]) case 'q': /* --quiet */ debug = 0; break; + case 's': /* --quiet */ + share = optarg; + break; case 'v': /* --version */ printf("pwntcha (captcha decoder) %s\n", VERSION); printf("Written by Sam Hocevar.\n"); diff --git a/src/phpbb.c b/src/phpbb.c index 9ad829b..2ca7db2 100644 --- a/src/phpbb.c +++ b/src/phpbb.c @@ -18,7 +18,7 @@ #include "common.h" /* Our macros */ -#define FONTNAME "share/font_phpbb.png" +#define FONTNAME "font_phpbb.png" static struct image *font = NULL; /* Main function */ @@ -34,10 +34,12 @@ char *decode_phpbb(struct image *img) if(!font) { - font = image_load(FONTNAME); + char fontname[BUFSIZ]; + sprintf(fontname, "%s/%s", share, FONTNAME); + font = image_load(fontname); if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); + fprintf(stderr, "cannot load font %s\n", fontname); exit(-1); } } diff --git a/src/slashdot.c b/src/slashdot.c index 7029880..877a326 100644 --- a/src/slashdot.c +++ b/src/slashdot.c @@ -25,9 +25,9 @@ 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 +#define FONTNAME "font_slashdot.png" // use with FACTOR = 1 +//#define FONTNAME "font.png" // use with FACTOR = 2 +//#define FONTNAME "font_dilated.png" // use with FACTOR = 2 static struct image *font = NULL; /* Global stuff */ @@ -245,10 +245,12 @@ static struct image *find_glyphs(struct image *img) if(!font) { - font = image_load(FONTNAME); + char fontname[BUFSIZ]; + sprintf(fontname, "%s/%s", share, FONTNAME); + font = image_load(fontname); if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); + fprintf(stderr, "cannot load font %s\n", fontname); exit(-1); } } diff --git a/src/test.c b/src/test.c index 0b1f92f..25932cb 100644 --- a/src/test.c +++ b/src/test.c @@ -19,7 +19,7 @@ #include "common.h" /* Our macros */ -#define FONTNAME "share/font_phpbb.png" +#define FONTNAME "font_phpbb.png" static struct image *find_glyphs(struct image *img); @@ -61,8 +61,7 @@ char *decode_test(struct image *img) static struct image *find_glyphs(struct image *img) { char all[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"; - struct image *dst; - struct image *font = image_load(FONTNAME); + struct image *dst, *font; int x, y, i = 0; int r, g, b; int xmin, xmax, ymin, ymax, incell = 0, count = 0, cur = 0, offset = -1; @@ -70,8 +69,14 @@ static struct image *find_glyphs(struct image *img) if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); - exit(-1); + char fontname[BUFSIZ]; + sprintf(fontname, "%s/%s", share, FONTNAME); + 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 520d24a..7feb4e5 100644 --- a/src/vbulletin.c +++ b/src/vbulletin.c @@ -17,7 +17,7 @@ #include "config.h" #include "common.h" -#define FONTNAME "share/font_vbulletin.png" +#define FONTNAME "font_vbulletin.png" static struct image *font = NULL; /* Main function */ @@ -31,10 +31,12 @@ char *decode_vbulletin(struct image *img) if(!font) { - font = image_load(FONTNAME); + char fontname[BUFSIZ]; + sprintf(fontname, "%s/%s", share, FONTNAME); + font = image_load(fontname); if(!font) { - fprintf(stderr, "cannot load font %s\n", FONTNAME); + fprintf(stderr, "cannot load font %s\n", fontname); exit(-1); } }