Ignore:
Timestamp:
01/10/05 16:31:33 (8 years ago)
Author:
sam
Message:
  • Use font_load_* for all decoders.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pwntcha/trunk/src/authimage.c

    r445 r448  
    1919#include "common.h" 
    2020 
    21 #define FONTNAME "font_authimage.png" 
    22 static struct image *font = NULL; 
    23  
    2421/* Main function */ 
    2522char *decode_authimage(struct image *img) 
    2623{ 
    27     char *all = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
     24    static struct font *font = NULL; 
    2825    char *result; 
    2926    struct image *tmp; 
     
    3229    if(!font) 
    3330    { 
    34         char fontname[BUFSIZ]; 
    35         sprintf(fontname, "%s/%s", share, FONTNAME); 
    36         font = image_load(fontname); 
     31        font = font_load_fixed("font_authimage.png", 
     32                               "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); 
    3733        if(!font) 
    38         { 
    39             fprintf(stderr, "cannot load font %s\n", fontname); 
    4034            exit(-1); 
    41         } 
    4235    } 
    4336 
     
    4639    memset(result, '\0', 7); 
    4740 
    48     /* half the captchas are inverse video; we set them back to normal */ 
     41    /* double the captcha size for better accuracy in the rotation */ 
    4942    tmp = image_dup(img); 
    5043    filter_scale(tmp, 2.0); 
     
    5245    filter_equalize(tmp, r * 3 / 4); 
    5346    filter_smooth(tmp); 
     47    filter_equalize(tmp, 220); 
    5448 
    5549    for(i = 0; i < 6; i++) 
    5650    { 
    5751        int mindiff = INT_MAX, minch = -1, ch; 
    58         for(ch = 0; ch < 36; ch++) 
     52        for(ch = 0; ch < font->size; ch++) 
    5953        { 
    6054            int diff = 0; 
     
    6761                    newy = 33.0 - (x + 6 * i) * 18.0 / 34.0 + y * 42.0 / 6.0 + 0.5; 
    6862                    getpixel(tmp, newx, newy, &r, &g, &b); 
    69                     getpixel(font, x + 6 * ch, y, &r2, &g, &b); 
    70                     r = (r < 220) ? 0 : 255; 
     63                    getpixel(font->img, x + 6 * ch, y, &r2, &g, &b); 
    7164                    diff += (r - r2) * (r - r2); 
    7265                } 
     
    7871            } 
    7972        } 
    80         result[i] = all[minch]; 
     73        result[i] = font->glyphs[minch].c; 
    8174    } 
    8275 
Note: See TracChangeset for help on using the changeset viewer.