2 Scans a swf file for strings
4 Part of the swftools package.
6 Copyright (c) 2000,2001 Rainer Böhme <rfxswf@reflex-studio.de>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 #include "../lib/rfxswf.h"
25 #include "../lib/args.h"
26 #include "../lib/utf8.h"
28 static char * filename
= 0;
29 static char showfonts
= 0;
30 static int x
=0,y
=0,w
=0,h
=0;
32 static struct options_t options
[] = {
42 int args_callback_option(char*name
,char*val
)
44 if(!strcmp(name
, "V")) {
45 printf("swfstrings - part of %s %s\n", PACKAGE
, VERSION
);
47 } else if(!strcmp(name
, "x")) {
50 } else if(!strcmp(name
, "y")) {
53 } else if(!strcmp(name
, "W")) {
56 } else if(!strcmp(name
, "H")) {
59 } else if(!strcmp(name
, "f")) {
62 } else if(!strcmp(name
, "V")) {
63 printf("swfstrings - part of %s %s\n", PACKAGE
, VERSION
);
66 fprintf(stderr
, "Unknown option: -%s\n", name
);
71 int args_callback_longoption(char*name
,char*val
)
73 return args_long2shortoption(options
, name
, val
);
75 void args_callback_usage(char *name
)
78 printf("Usage: %s [options] file.swf\n", name
);
80 printf("-f , --fonts Print out font information for each text block\n");
81 printf("-x , --xpos <x> Set bounding box x coordinate\n");
82 printf("-y , --ypos <y> Set bounding box y coordinate\n");
83 printf("-W , --width <width> Set bounding box width\n");
84 printf("-H , --height <height> Set bounding box height\n");
85 printf("-V , --version Print version information and exit\n");
88 int args_callback_command(char*name
,char*val
)
91 fprintf(stderr
, "Only one file allowed. You supplied at least two. (%s and %s)\n",
99 static int fontnum
= 0;
100 static SWFFONT
**fonts
= 0;
102 void fontcallback1(void*self
, U16 id
,U8
* name
)
106 void fontcallback2(void*self
, U16 id
,U8
* name
)
108 swf_FontExtract(&swf
,id
,&fonts
[fontnum
]);
113 void textcallback(void*self
, int*glyphs
, int*advance
, int nr
, int fontid
, int fontsize
, int startx
, int starty
, RGBA
*color
)
117 for(t
=0;t
<fontnum
;t
++)
119 if(fonts
[t
]->id
== fontid
) {
127 printf("#<font %d \"%s\"%s%s>\n", fontid
, font
->name
, swf_FontIsBold(font
)?" bold":"",swf_FontIsItalic(font
)?" italic":"");
128 printf("#<color #%02x%02x%02x%02x>\n", color
->r
, color
->g
, color
->b
, color
->a
);
129 printf("#<size %d>\n", fontsize
);
134 int xx
= startx
+ advance
[t
];
136 MATRIX
*m
= (MATRIX
*)self
;
139 p
= swf_TurnPoint(p
, m
);
144 if(xx
< x
|| yy
< y
|| xx
> x
+w
|| yy
> y
+h
) {
145 /* outside of bounding box */
146 ///printf("(%d+%d,%d) -> (%d,%d)\n", startx, advance[t]/20, starty, xx, yy);
155 if(glyphs
[t
]<0 || glyphs
[t
] >= font
->numchars
/*glyph is not in range*/
156 || !font
->glyph2ascii
/* font has ascii<->glyph mapping */
159 if(font
->glyph2ascii
[glyphs
[t
]])
160 a
= font
->glyph2ascii
[glyphs
[t
]];
169 char* utf8
= getUTF8(a
);
172 printf("\\x%x", (int)a
);
178 void fontcallback(void*self
,U16 id
,U8
* name
)
182 swf_FontExtract(&swf
,id
,&font
);
191 int main (int argc
,char ** argv
)
194 processargs(argc
, argv
);
198 f
= open(filename
,O_RDONLY
|O_BINARY
);
199 if (f
<0 || swf_ReadSWF(f
,&swf
)<0) {
200 fprintf(stderr
,"%s is not a valid SWF file or contains errors.\n",filename
);
207 if(!w
) w
= (swf
.movieSize
.xmax
- swf
.movieSize
.xmin
) / 20;
208 if(!h
) h
= (swf
.movieSize
.ymax
- swf
.movieSize
.ymin
) / 20;
211 id2tag
= malloc(sizeof(TAG
)*65536);
214 swf_FontEnumerate(&swf
,&fontcallback1
, 0);
215 fonts
= (SWFFONT
**)malloc(fontnum
*sizeof(SWFFONT
*));
217 swf_FontEnumerate(&swf
,&fontcallback2
, 0);
219 TAG
*tag
= swf
.firstTag
;
222 if(swf_isTextTag(tag
)) {
223 id2tag
[swf_GetDefineID(tag
)] = tag
;
224 } else if(swf_isPlaceTag(tag
)) {
226 swf_SetTagPos(tag
, 0);
227 swf_GetPlaceObject(tag
, &po
);
228 if(!po
.move
&& id2tag
[po
.id
]) {
229 TAG
*text
= id2tag
[po
.id
];
230 swf_SetTagPos(text
, 0);
232 swf_GetRect(text
, NULL
);
233 swf_ResetReadBits(text
);
235 swf_GetMatrix(text
, &tm
);
236 swf_MatrixJoin(&m
, &po
.matrix
, &tm
);
237 swf_ParseDefineText(text
, textcallback
, &m
);