Changeset 448
- Timestamp:
- Jan 10, 2005, 4:31:33 PM (18 years ago)
- Location:
- pwntcha/trunk/src
- Files:
-
- 1 added
- 11 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/src/Makefile.am
r445 r448 4 4 pwntcha_SOURCES = \ 5 5 main.c \ 6 filter.c \ 7 font.c \ 6 8 image.c \ 7 filters.c \8 9 common.h \ 9 10 authimage.c \ -
pwntcha/trunk/src/authimage.c
r445 r448 19 19 #include "common.h" 20 20 21 #define FONTNAME "font_authimage.png"22 static struct image *font = NULL;23 24 21 /* Main function */ 25 22 char *decode_authimage(struct image *img) 26 23 { 27 char *all = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";24 static struct font *font = NULL; 28 25 char *result; 29 26 struct image *tmp; … … 32 29 if(!font) 33 30 { 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"); 37 33 if(!font) 38 {39 fprintf(stderr, "cannot load font %s\n", fontname);40 34 exit(-1); 41 }42 35 } 43 36 … … 46 39 memset(result, '\0', 7); 47 40 48 /* half the captchas are inverse video; we set them back to normal*/41 /* double the captcha size for better accuracy in the rotation */ 49 42 tmp = image_dup(img); 50 43 filter_scale(tmp, 2.0); … … 52 45 filter_equalize(tmp, r * 3 / 4); 53 46 filter_smooth(tmp); 47 filter_equalize(tmp, 220); 54 48 55 49 for(i = 0; i < 6; i++) 56 50 { 57 51 int mindiff = INT_MAX, minch = -1, ch; 58 for(ch = 0; ch < 36; ch++)52 for(ch = 0; ch < font->size; ch++) 59 53 { 60 54 int diff = 0; … … 67 61 newy = 33.0 - (x + 6 * i) * 18.0 / 34.0 + y * 42.0 / 6.0 + 0.5; 68 62 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); 71 64 diff += (r - r2) * (r - r2); 72 65 } … … 78 71 } 79 72 } 80 result[i] = all[minch];73 result[i] = font->glyphs[minch].c; 81 74 } 82 75 -
pwntcha/trunk/src/clubic.c
r445 r448 21 21 22 22 /* Our macros */ 23 #define FONTNAME "font_clubic.png"24 static struct image *font = NULL;25 23 char *result; 26 24 … … 29 27 { 30 28 struct image *tmp; 31 32 if(!font)33 {34 char fontname[BUFSIZ];35 sprintf(fontname, "%s/%s", share, FONTNAME);36 font = image_load(fontname);37 if(!font)38 {39 fprintf(stderr, "cannot load font %s\n", fontname);40 exit(-1);41 }42 }43 29 44 30 /* clubic captchas have 6 characters */ … … 57 43 static void find_glyphs(struct image *img) 58 44 { 59 char all[] = "0123456789"; 60 struct 61 { 62 int xmin, xmax, ymin, ymax; 63 int count; 64 } 65 glyphs[10]; 45 static struct font *font = NULL; 66 46 struct image *tmp; 67 47 int x, y, i = 0; 68 48 int r, g, b; 69 int xmin, xmax, ymin, ymax, incell = 0, count = 0,startx = 0, cur = 0;49 int xmin, xmax, ymin, ymax, startx = 0, cur = 0; 70 50 int distmin, distx, disty, distch; 51 52 if(!font) 53 { 54 font = font_load_variable("font_clubic.png", "0123456789"); 55 if(!font) 56 exit(1); 57 } 71 58 72 59 tmp = image_new(img->width, img->height); … … 79 66 } 80 67 81 for(x = 0; x < font->width; x++)82 {83 int found = 0;84 for(y = 0; y < font->height; y++)85 {86 getpixel(font, x, y, &r, &g, &b);87 if(r < 128)88 {89 found = 1;90 count += (255 - r);91 }92 }93 if(found && !incell)94 {95 incell = 1;96 xmin = x;97 }98 else if(!found && incell)99 {100 incell = 0;101 xmax = x;102 ymin = 0;103 ymax = font->height;104 glyphs[i].xmin = xmin;105 glyphs[i].xmax = xmax;106 glyphs[i].ymin = ymin;107 glyphs[i].ymax = ymax;108 glyphs[i].count = count;109 count = 0;110 i++;111 }112 }113 114 if(i != 10)115 {116 printf("error: could not find 10 glyphs in font\n");117 exit(-1);118 }119 120 68 while(cur < 6) 121 69 { 122 70 /* Try to find 1st letter */ 123 71 distmin = INT_MAX; 124 for(i = 0; i < 10; i++)72 for(i = 0; i < font->size; i++) 125 73 { 126 74 int localmin = INT_MAX, localx, localy; 127 xmin = glyphs[i].xmin;128 ymin = glyphs[i].ymin;129 xmax = glyphs[i].xmax;130 ymax = glyphs[i].ymax;75 xmin = font->glyphs[i].xmin; 76 ymin = font->glyphs[i].ymin; 77 xmax = font->glyphs[i].xmax; 78 ymax = font->glyphs[i].ymax; 131 79 for(y = -4; y < 4; y++) 132 80 for(x = startx; x < startx + 4; x++) … … 138 86 { 139 87 int r2; 140 getgray(font , xmin + z, ymin + t, &r);88 getgray(font->img, xmin + z, ymin + t, &r); 141 89 getgray(img, x + z, y + t, &r2); 142 90 dist += abs(r - r2); 143 91 } 144 dist = dist * 128 / glyphs[i].count;92 dist = dist * 128 / font->glyphs[i].count; 145 93 if(dist < localmin) 146 94 { … … 160 108 161 109 /* Print min glyph */ 162 xmin = glyphs[distch].xmin;163 ymin = glyphs[distch].ymin;164 xmax = glyphs[distch].xmax;165 ymax = glyphs[distch].ymax;110 xmin = font->glyphs[distch].xmin; 111 ymin = font->glyphs[distch].ymin; 112 xmax = font->glyphs[distch].xmax; 113 ymax = font->glyphs[distch].ymax; 166 114 for(y = 0; y < ymax - ymin; y++) 167 115 for(x = 0; x < xmax - xmin; x++) 168 116 { 169 getpixel(font, xmin + x, ymin + y, &r, &g, &b); 170 if(r > 128) continue; 117 getpixel(font->img, xmin + x, ymin + y, &r, &g, &b); 118 if(r > 128) 119 continue; 171 120 setpixel(tmp, distx + x, disty + y, r, g, b); 172 121 } 173 122 174 123 startx = distx + xmax - xmin; 175 result[cur++] = all[distch];124 result[cur++] = font->glyphs[distch].c; 176 125 } 177 126 -
pwntcha/trunk/src/common.h
r446 r448 26 26 int xmin, xmax, ymin, ymax; 27 27 int count; /* Black pixel count */ 28 char c; 28 29 } *glyphs; 30 int size; 29 31 }; 30 32 … … 58 60 int setpixel(struct image *img, int x, int y, int r, int g, int b); 59 61 62 /* font operations */ 63 struct font *font_load_fixed(char *file, char *chars); 64 struct font *font_load_variable(char *file, char *chars); 65 void font_free(struct font *font); 66 60 67 /* image filters */ 61 68 void filter_flood_fill(struct image *img, int x, int y, int r, int g, int b); -
pwntcha/trunk/src/linuxfr.c
r445 r448 18 18 #include "common.h" 19 19 20 #define FONTNAME "font_linuxfr.png"21 static struct image *font = NULL;22 23 20 /* Main function */ 24 21 char *decode_linuxfr(struct image *img) 25 22 { 26 char all[] = "abcdefghijklmnopqrstuvwxyz" 27 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 28 "0123456789"; 23 static struct font *font = NULL; 29 24 char *result; 30 25 struct image *tmp; 31 26 int x, y, r, g, b, i, j, c; 32 int *stats = malloc(img->height * sizeof(int));27 int *stats; 33 28 34 29 if(!font) 35 30 { 36 char fontname[BUFSIZ]; 37 sprintf(fontname, "%s/%s", share, FONTNAME); 38 font = image_load(fontname); 31 font = font_load_fixed("font_linuxfr.png", 32 "abcdefghijklmnopqrstuvwxyz" 33 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 34 "0123456789"); 39 35 if(!font) 40 {41 fprintf(stderr, "cannot load font %s\n", fontname);42 36 exit(-1); 43 }44 37 } 45 38 … … 47 40 result = malloc(8 * sizeof(char)); 48 41 memset(result, '\0', 8); 42 43 stats = malloc(img->height * sizeof(int)); 49 44 50 45 tmp = image_dup(img); … … 115 110 int r2, g2, b2, ch; 116 111 int minerror = INT_MAX; 117 for(ch = 0; ch < 62; ch++)112 for(ch = 0; ch < font->size; ch++) 118 113 { 119 114 int error = 0, goodch = 1; … … 122 117 { 123 118 getpixel(tmp, x + c * 9 + i, y + j, &r, &g, &b); 124 getpixel(font , ch * 9 + i, j, &r2, &g2, &b2);119 getpixel(font->img, ch * 9 + i, j, &r2, &g2, &b2); 125 120 /* Only die if font is black and image is white */ 126 121 if(r > r2) … … 135 130 { 136 131 minerror = error; 137 result[c] = all[ch];132 result[c] = font->glyphs[ch].c; 138 133 result[c+1] = '\0'; 139 134 } -
pwntcha/trunk/src/main.c
r444 r448 64 64 { 65 65 case 'h': /* --help */ 66 printf("Usage: %s [OPTION]... FILE...\n", argv[0]);66 printf("Usage: %s [OPTION]... IMAGE...\n", argv[0]); 67 67 #ifdef HAVE_GETOPT_LONG 68 68 printf(" -m, --mode <mode> force operating mode\n"); -
pwntcha/trunk/src/phpbb.c
r445 r448 18 18 #include "common.h" 19 19 20 /* Our macros */21 #define FONTNAME "font_phpbb.png"22 static struct image *font = NULL;23 24 20 /* Main function */ 25 21 char *decode_phpbb(struct image *img) 26 22 { 27 char all[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";23 static struct font *font = NULL; 28 24 char *result; 29 25 struct image *tmp1, *tmp2; … … 35 31 if(!font) 36 32 { 37 char fontname[BUFSIZ]; 38 sprintf(fontname, "%s/%s", share, FONTNAME); 39 font = image_load(fontname); 33 font = font_load_fixed("font_phpbb.png", 34 "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"); 40 35 if(!font) 41 {42 fprintf(stderr, "cannot load font %s\n", fontname);43 36 exit(-1); 44 }45 37 } 46 38 … … 69 61 /* Try to find 1st letter */ 70 62 distmin = INT_MAX; 71 for(i = 0; i < 35; i++)63 for(i = 0; i < font->size; i++) 72 64 { 73 65 int localmin = INT_MAX, localx, localy; 74 xmin = i * 40;75 ymin = 0;76 xmax = i * 40 + 40;77 ymax = 40;78 for(y = 0; y < img->height - 40; y++)66 xmin = font->glyphs[i].xmin; 67 ymin = font->glyphs[i].ymin; 68 xmax = font->glyphs[i].xmax; 69 ymax = font->glyphs[i].ymax; 70 for(y = 0; y < img->height - (ymax - ymin); y++) 79 71 { 80 72 x = offset - 3; … … 91 83 { 92 84 int r2; 93 getgray(font , xmin + z, ymin + t, &r);85 getgray(font->img, xmin + z, ymin + t, &r); 94 86 getgray(tmp1, x + z, y + t, &r2); 95 87 if(r > r2) … … 116 108 117 109 /* Print min glyph (debug) */ 118 xmin = distch * 40;119 ymin = 0;120 xmax = distch * 40 + 40;121 ymax = 40;110 xmin = font->glyphs[distch].xmin; 111 ymin = font->glyphs[distch].ymin; 112 xmax = font->glyphs[distch].xmax; 113 ymax = font->glyphs[distch].ymax; 122 114 for(y = 0; y < ymax - ymin; y++) 123 115 for(x = 0; x < xmax - xmin; x++) 124 116 { 125 117 int r2; 126 getpixel(font, xmin + x, ymin + y, &r2, &g, &b); 127 if(r2 > 128) continue; 118 getpixel(font->img, xmin + x, ymin + y, &r2, &g, &b); 119 if(r2 > 128) 120 continue; 128 121 getpixel(tmp2, distx + x, disty + y, &r, &g, &b); 129 122 setpixel(tmp2, distx + x, disty + y, r2, g, b); … … 131 124 132 125 offset = distx + xmax - xmin; 133 result[cur] = all[distch];126 result[cur] = font->glyphs[distch].c; 134 127 } 135 128 -
pwntcha/trunk/src/slashdot.c
r446 r448 21 21 static void count_objects(struct image *img); 22 22 static void rotate(struct image *img); 23 static void cut_cells(struct image *img);24 23 static void find_glyphs(struct image *img); 25 26 /* Our macros */27 #define FONTNAME "font_slashdot.png"28 29 struct font font;30 struct glyph glyphs[22];31 24 32 25 /* Global stuff */ … … 136 129 } 137 130 } 138 139 #if 0140 { CvPoint A, B;141 A.x = (objlist[first].xmin + objlist[first].xmax) / 2;142 A.y = (objlist[first].ymin + objlist[first].ymax) / 2;143 B.x = (objlist[last].xmin + objlist[last].xmax) / 2;144 B.y = (objlist[last].ymin + objlist[last].ymax) / 2;145 cvLine(tmp, A, B, 0, 2.0, 0);146 }147 #endif148 131 149 132 image_swap(img, tmp); … … 196 179 } 197 180 198 static void cut_cells(struct image *img)199 {200 struct image *tmp;201 int x, y;202 int r, g, b;203 204 tmp = image_new(img->width, img->height);205 206 for(y = 0; y < img->height; y++)207 for(x = 0; x < img->width; x++)208 {209 getpixel(img, x, y, &r, &g, &b);210 setpixel(tmp, x, y, r, g, b);211 }212 213 for(x = 0; x < img->width; x++)214 {215 setpixel(tmp, x, 0, 255, 255, 255);216 setpixel(tmp, x, img->height - 1, 255, 255, 255);217 }218 219 for(y = 0; y < img->height; y++)220 for(x = 0; x < 7; x++)221 {222 setpixel(tmp, x * img->width / 7, y, 255, 255, 255);223 setpixel(tmp, (x + 1) * img->width / 7 - 1, y, 255, 255, 255);224 }225 226 image_swap(img, tmp);227 image_free(tmp);228 }229 230 181 static void find_glyphs(struct image *img) 231 182 { 232 char all[] = "abcdefgijkmnpqrstvwxyz";183 static struct font *font = NULL; 233 184 struct image *tmp; 234 185 int x, y, i = 0; 235 186 int r, g, b; 236 int xmin, xmax, ymin, ymax, incell = 0, count = 0,startx = 0, cur = 0;187 int xmin, xmax, ymin, ymax, startx = 0, cur = 0; 237 188 int distmin, distx, disty, distch; 238 189 239 if(!font.img) 240 { 241 char fontname[BUFSIZ]; 242 sprintf(fontname, "%s/%s", share, FONTNAME); 243 font.img = image_load(fontname); 244 if(!font.img) 245 { 246 fprintf(stderr, "cannot load font %s\n", fontname); 247 exit(-1); 248 } 249 font.glyphs = glyphs; 190 if(!font) 191 { 192 font = font_load_variable("font_slashdot.png", "abcdefgijkmnpqrstvwxyz"); 193 if(!font) 194 exit(1); 250 195 } 251 196 … … 259 204 } 260 205 261 for(x = 0; x < font.img->width; x++)262 {263 int found = 0;264 for(y = 0; y < font.img->height; y++)265 {266 getpixel(font.img, x, y, &r, &g, &b);267 if(r < 128)268 {269 found = 1;270 count += (255 - r);271 }272 }273 if(found && !incell)274 {275 incell = 1;276 xmin = x;277 }278 else if(!found && incell)279 {280 incell = 0;281 xmax = x;282 #if 0283 ymin = font.img->height;284 ymax = 0;285 for(y = 0; y < font.img->height; y++)286 {287 int newx;288 int gotit = 0;289 for(newx = xmin; newx < xmax; newx++)290 {291 getpixel(font.img, newx, y, &r, &g, &b);292 if(r < 128)293 {294 gotit = 1;295 break;296 }297 }298 if(gotit)299 {300 if(ymin > y) ymin = y;301 if(ymax <= y) ymax = y + 1;302 }303 }304 #else305 ymin = 0;306 ymax = font.img->height;307 #endif308 font.glyphs[i].xmin = xmin;309 font.glyphs[i].xmax = xmax;310 font.glyphs[i].ymin = ymin;311 font.glyphs[i].ymax = ymax;312 font.glyphs[i].count = count;313 count = 0;314 i++;315 }316 }317 318 if(i != 22)319 {320 printf("error: could not find 22 glyphs in font\n");321 exit(-1);322 }323 324 206 while(cur < 7) 325 207 { 326 208 /* Try to find 1st letter */ 327 209 distmin = INT_MAX; 328 for(i = 0; i < 22; i++)210 for(i = 0; i < font->size; i++) 329 211 { 330 212 int localmin = INT_MAX, localx, localy; 331 //if(all[i] == 'i') continue; 332 xmin = font.glyphs[i].xmin; 333 ymin = font.glyphs[i].ymin; 334 xmax = font.glyphs[i].xmax; 335 ymax = font.glyphs[i].ymax; 336 //printf("trying to find %c (%i×%i) - ", all[i], xmax - xmin, ymax - ymin); 213 xmin = font->glyphs[i].xmin; 214 ymin = font->glyphs[i].ymin; 215 xmax = font->glyphs[i].xmax; 216 ymax = font->glyphs[i].ymax; 337 217 for(y = -5; y < 5; y++) 338 218 for(x = startx - 5; x < startx + 5; x++) … … 344 224 { 345 225 int r2; 346 getgray(font .img, xmin + z, ymin + t, &r);226 getgray(font->img, xmin + z, ymin + t, &r); 347 227 getgray(img, x + z, y + t, &r2); 348 228 dist += abs(r - r2); … … 350 230 // printf("%i %i -> %i\n", x, y, dist); 351 231 //dist /= sqrt(xmax - xmin); 352 dist = dist * 128 / font .glyphs[i].count;232 dist = dist * 128 / font->glyphs[i].count; 353 233 if(dist < localmin) 354 234 { … … 368 248 } 369 249 370 //fprintf(stderr, "%i (%i,%i)\n", distmin, distx - startx, disty); 371 //printf("min diff: %c - %i (%i, %i)\n", all[distch], distmin, distx, disty); 372 373 /* Print min glyph */ 374 xmin = font.glyphs[distch].xmin; 375 ymin = font.glyphs[distch].ymin; 376 xmax = font.glyphs[distch].xmax; 377 ymax = font.glyphs[distch].ymax; 250 /* Draw best glyph in picture (debugging purposes) */ 251 xmin = font->glyphs[distch].xmin; 252 ymin = font->glyphs[distch].ymin; 253 xmax = font->glyphs[distch].xmax; 254 ymax = font->glyphs[distch].ymax; 378 255 for(y = 0; y < ymax - ymin; y++) 379 256 for(x = 0; x < xmax - xmin; x++) 380 257 { 381 getpixel(font .img, xmin + x, ymin + y, &r, &g, &b);258 getpixel(font->img, xmin + x, ymin + y, &r, &g, &b); 382 259 if(r > 128) continue; 383 260 setpixel(tmp, distx + x, disty + y, r, g, b); … … 385 262 386 263 startx = distx + xmax - xmin; 387 result[cur++] = all[distch];264 result[cur++] = font->glyphs[distch].c; 388 265 } 389 266 -
pwntcha/trunk/src/test.c
r445 r448 19 19 #include "common.h" 20 20 21 /* Our macros */22 #define FONTNAME "font_phpbb.png"23 24 static void find_glyphs(struct image *img);25 26 /* Global stuff */27 struct { int xmin, ymin, xmax, ymax; } objlist[100];28 int objects, first, last;29 char *result;30 31 21 /* Main function */ 32 22 char *decode_test(struct image *img) 33 23 { 24 char *result; 34 25 struct image *tmp; 35 36 /* Initialise local data */37 objects = 0;38 first = -1;39 last = -1;40 26 41 27 /* phpBB captchas have 6 characters */ 42 28 result = malloc(7 * sizeof(char)); 29 result[0] = 0; 43 30 44 31 tmp = image_dup(img); … … 47 34 filter_equalize(tmp, 130); 48 35 filter_median(tmp); 49 find_glyphs(tmp);50 36 51 37 image_free(tmp); … … 56 42 /* The following functions are local */ 57 43 58 static void find_glyphs(struct image *img)59 {60 char all[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";61 struct image *tmp, *font;62 int x, y, i = 0;63 int r, g, b;64 int xmin, xmax, ymin, ymax, cur = 0, offset = -1;65 int distmin, distx, disty, distch;66 67 if(!font)68 {69 char fontname[BUFSIZ];70 sprintf(fontname, "%s/%s", share, FONTNAME);71 font = image_load(fontname);72 if(!font)73 {74 fprintf(stderr, "cannot load font %s\n", fontname);75 exit(-1);76 }77 }78 79 tmp = image_new(img->width, img->height);80 81 for(x = 0; x < img->width; x++)82 for(y = 0; y < img->height; y++)83 {84 getpixel(img, x, y, &r, &g, &b);85 setpixel(tmp, x, y, 255, g, 255);86 if(r == 0 && offset == -1)87 offset = x;88 }89 90 strcpy(result, " ");91 92 while(cur < 6)93 {94 /* Try to find 1st letter */95 distmin = INT_MAX;96 for(i = 0; i < 35; i++)97 {98 int localmin = INT_MAX, localx, localy;99 xmin = i * 40;100 ymin = 0;101 xmax = i * 40 + 40;102 ymax = 40;103 for(y = 0; y < img->height - 40; y++)104 {105 x = offset - 5;106 if(cur == 0)107 x -= 15;108 if(x < 0)109 x = 0;110 for(; x < offset + 10; x++)111 {112 int z, t, dist;113 dist = 0;114 for(t = 0; t < ymax - ymin; t++)115 for(z = 0; z < xmax - xmin; z++)116 {117 int r2;118 getgray(font, xmin + z, ymin + t, &r);119 getgray(img, x + z, y + t, &r2);120 dist += abs(r - r2);121 }122 if(dist < localmin)123 {124 localmin = dist;125 localx = x;126 localy = y;127 }128 }129 }130 if(localmin < distmin)131 {132 distmin = localmin;133 distx = localx;134 disty = localy;135 distch = i;136 }137 }138 139 /* Print min glyph (debug) */140 xmin = distch * 40;141 ymin = 0;142 xmax = distch * 40 + 40;143 ymax = 40;144 for(y = 0; y < ymax - ymin; y++)145 for(x = 0; x < xmax - xmin; x++)146 {147 getpixel(font, xmin + x, ymin + y, &r, &g, &b);148 if(r > 128) continue;149 setpixel(tmp, distx + x, disty + y, r, g, b);150 }151 152 offset = distx + xmax - xmin;153 result[cur++] = all[distch];154 }155 156 image_swap(img, tmp);157 image_free(tmp);158 }159 -
pwntcha/trunk/src/vbulletin.c
r445 r448 18 18 #include "common.h" 19 19 20 #define FONTNAME "font_vbulletin.png"21 static struct image *font = NULL;22 23 20 /* Main function */ 24 21 char *decode_vbulletin(struct image *img) 25 22 { 26 char all[] = "2346789ABCDEFGHJKLMNPRTWXYZ";23 static struct font *font = NULL; 27 24 char *result; 28 25 struct image *tmp; … … 32 29 if(!font) 33 30 { 34 char fontname[BUFSIZ]; 35 sprintf(fontname, "%s/%s", share, FONTNAME); 36 font = image_load(fontname); 31 font = font_load_fixed("font_vbulletin.png", 32 "2346789ABCDEFGHJKLMNPRTWXYZ"); 37 33 if(!font) 38 {39 fprintf(stderr, "cannot load font %s\n", fontname);40 34 exit(-1); 41 }42 35 } 43 36 … … 115 108 for(i = 0; i < 6; i++) 116 109 { 117 struct image *new = image_dup(tmp);118 110 int mindist = INT_MAX, min = -1; 119 filter_crop(new, limits[i], 15, limits[i] + 11, 45); 120 for(j = 0; j < 27; j++) 111 for(j = 0; j < font->size; j++) 121 112 { 122 113 int dist = 0; 123 for(y = 0; y < new->height; y++)124 for(x = 0; x < new->width; x++)114 for(y = 0; y < 11; y++) 115 for(x = 0; x < 30; x++) 125 116 { 126 117 int r2, g2, b2; 127 getpixel(font , 12 * j + x, y, &r, &g, &b);128 getpixel( new, x,y, &r2, &g2, &b2);118 getpixel(font->img, 12 * j + x, y, &r, &g, &b); 119 getpixel(tmp, limits[i] + x, 15 + y, &r2, &g2, &b2); 129 120 dist += (r - r2) * (r - r2); 130 121 } … … 135 126 } 136 127 } 137 image_free(new); 138 result[i] = all[min]; 128 result[i] = font->glyphs[min].c; 139 129 } 140 130 -
pwntcha/trunk/src/xanga.c
r445 r448 21 21 static void fill_white_holes(struct image *img); 22 22 23 /* Our macros */24 #define FACTOR 125 #define FONTNAME "font_xanga.png" // use with FACTOR = 126 //#define FONTNAME "font.png" // use with FACTOR = 227 //#define FONTNAME "font_dilated.png" // use with FACTOR = 228 static struct image *font = NULL;29 30 /* Global stuff */31 struct { int xmin, ymin, xmax, ymax; } objlist[100];32 int objects, first, last;33 char *result;34 35 23 /* Main function */ 36 24 char *decode_xanga(struct image *img) 37 25 { 26 static struct font *font1 = NULL, *font2 = NULL, *font3 = NULL; 38 27 struct image *tmp; 28 char *result; 39 29 40 /* Initialise local data */ 41 objects = 0; 42 first = -1; 43 last = -1; 30 if(!font1) 31 { 32 font1 = font_load_variable("font_freemonobold_32_az.bmp", 33 "abcdefghijklmnopqrstuvwxyz"); 34 if(!font1) 35 exit(1); 36 } 37 38 if(!font2) 39 { 40 font2 = font_load_variable("font_freemonobold_32_az.bmp", 41 "abcdefghijklmnopqrstuvwxyz"); 42 if(!font2) 43 exit(1); 44 } 45 46 if(!font3) 47 { 48 font3 = font_load_variable("font_freemonobold_32_az.bmp", 49 "abcdefghijklmnopqrstuvwxyz"); 50 if(!font3) 51 exit(1); 52 } 44 53 45 54 /* Xanga captchas have 7 characters */ … … 69 78 70 79 /* Invert rotation and find glyphs */ 71 rotate(tmp);72 80 filter_median(tmp); 73 81 … … 87 95 { 88 96 struct image *tmp; 89 int x, y , i;97 int x, y; 90 98 int r, g, b; 91 99
Note: See TracChangeset
for help on using the changeset viewer.