2 Shows the structure of a swf file
4 Part of the swftools package.
6 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
8 This file is distributed under the GPL, see file COPYING for details */
12 #ifdef HAVE_SYS_STAT_H
18 #ifdef HAVE_SYS_TYPES_H
19 #include <sys/types.h>
27 #include "../lib/rfxswf.h"
28 #include "../lib/args.h"
32 /* idtab stores the ids which are defined in the file. This allows us
33 to detect errors in the file. (i.e. ids which are defined more than
42 struct options_t options[] =
56 int args_callback_option(char*name,char*val)
58 if(!strcmp(name, "V")) {
59 printf("swfdump - part of %s %s\n", PACKAGE, VERSION);
62 else if(name[0]=='a') {
66 else if(name[0]=='t') {
70 else if(name[0]=='e') {
74 else if(name[0]=='X') {
78 else if(name[0]=='Y') {
82 else if(name[0]=='r') {
87 printf("Unknown option: -%s\n", name);
92 int args_callback_longoption(char*name,char*val)
94 return args_long2shortoption(options, name, val);
96 void args_callback_usage(char*name)
98 printf("Usage: %s [-at] file.swf\n", name);
99 printf("\t-h , --help\t\t\t Print help and exit\n");
100 printf("\t-e , --html\t\t\t Create a html embedding the file (simple, but useful)\n");
101 printf("\t-X , --width\t\t\t Prints out a string of the form \"-X width\"\n");
102 printf("\t-Y , --height\t\t\t Prints out a string of the form \"-Y height\"\n");
103 printf("\t-r , --rate\t\t\t Prints out a string of the form \"-r rate\"\n");
104 printf("\t-a , --action\t\t\t Disassemble action tags\n");
105 printf("\t-t , --text\t\t\t Show text data\n");
106 printf("\t-V , --version\t\t\t Print program version and exit\n");
108 int args_callback_command(char*name,char*val)
111 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
119 char* testfunc(char*str)
121 printf("%s: %s\n", what, str);
125 void dumpButton2Actions(TAG*tag, char*prefix)
131 oldTagPos = swf_GetTagPos(tag);
133 // scan DefineButton2 Record
135 swf_GetU16(tag); // Character ID
136 swf_GetU8(tag); // Flags;
138 offsetpos = swf_GetTagPos(tag); // first offset
141 while (swf_GetU8(tag)) // state -> parse ButtonRecord
142 { swf_GetU16(tag); // id
143 swf_GetU16(tag); // layer
144 swf_GetMatrix(tag,NULL); // matrix
145 swf_GetCXForm(tag,NULL,1); // matrix
152 offsetpos = swf_GetU16(tag);
153 condition = swf_GetU16(tag); // condition
155 actions = swf_ActionGet(tag);
156 printf("%s condition %04x\n", prefix, condition);
157 swf_DumpActions(actions, prefix);
160 swf_SetTagPos(tag,oldTagPos);
164 void dumpButtonActions(TAG*tag, char*prefix)
167 swf_GetU16(tag); // id
168 while (swf_GetU8(tag)) // state -> parse ButtonRecord
169 { swf_GetU16(tag); // id
170 swf_GetU16(tag); // layer
171 swf_GetMatrix(tag,NULL); // matrix
173 actions = swf_ActionGet(tag);
174 swf_DumpActions(actions, prefix);
177 #define ET_HASTEXT 32768
178 #define ET_WORDWRAP 16384
179 #define ET_MULTILINE 8192
180 #define ET_PASSWORD 4096
181 #define ET_READONLY 2048
182 #define ET_HASTEXTCOLOR 1024
183 #define ET_HASMAXLENGTH 512
184 #define ET_HASFONT 256
187 #define ET_HASLAYOUT 32
188 #define ET_NOSELECT 16
192 #define ET_USEOUTLINES 1
198 void textcallback(int*glyphs, int nr, int fontid)
201 printf(" <%2d glyphs in font %2d> ",nr, fontid);
202 for(t=0;t<fontnum;t++)
204 if(fonts[t]->id == fontid) {
211 return; // todo: should we report this? (may only be that it's a definefont without fontinfo)
217 if(glyphs[t] >= fonts[font]->numchars)
219 a = fonts[font]->glyph2ascii[glyphs[t]];
223 printf("\\x%x", (int)a);
228 void handleText(TAG*tag)
231 swf_FontExtract_DefineTextCallback(-1,0,tag,4, textcallback);
234 void handleEditText(TAG*tag)
239 id = swf_GetU16(tag);
241 //swf_ResetReadBits(tag);
246 flags = swf_GetBits(tag,16);
247 if(flags & ET_HASFONT) {
248 swf_GetU16(tag); //font
249 swf_GetU16(tag); //fontheight
251 if(flags & ET_HASTEXTCOLOR) {
252 swf_GetU8(tag); //rgba
257 if(flags & ET_HASMAXLENGTH) {
258 swf_GetU16(tag); //maxlength
260 if(flags & ET_HASLAYOUT) {
261 swf_GetU8(tag); //align
262 swf_GetU16(tag); //left margin
263 swf_GetU16(tag); //right margin
264 swf_GetU16(tag); //indent
265 swf_GetU16(tag); //leading
267 printf(" variable \"%s\"", &tag->data[tag->pos]);
269 if(flags & (ET_X1 | ET_X2 | ET_X3 | ET_X0))
271 printf(" undefined flags: %d%d%d%d",
278 while(tag->data[tag->pos++]);
279 if(flags & ET_HASTEXT)
280 // printf(" text \"%s\"\n", &tag->data[tag->pos])
284 void fontcallback1(U16 id,U8 * name)
288 void fontcallback2(U16 id,U8 * name)
289 { swf_FontExtract(&swf,id,&fonts[fontnum]);
293 int main (int argc,char ** argv)
301 char issprite = 0; // are we inside a sprite definition?
304 char* spriteframelabel;
305 char* framelabel = 0;
308 memset(idtab,0,65536);
310 processargs(argc, argv);
314 fprintf(stderr, "You must supply a filename.\n");
318 f = open(filename,O_RDONLY);
322 perror("Couldn't open file: ");
325 if FAILED(swf_ReadSWF(f,&swf))
327 fprintf(stderr, "%s is not a valid SWF file or contains errors.\n",filename);
334 if(statbuf.st_size != swf.FileSize)
335 fprintf(stderr, "Error: Real Filesize (%d) doesn't match header Filesize (%d)",
336 statbuf.st_size, swf.FileSize);
341 xsize = (swf.movieSize.xmax-swf.movieSize.xmin)/20;
342 ysize = (swf.movieSize.ymax-swf.movieSize.ymin)/20;
346 printf("-X %d", xsize);
352 printf("-Y %d", ysize);
358 printf("-r %d", swf.frameRate*100/256);
365 printf("<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n"
368 " CODEBASE=\"http://active.macromedia.com/flash5/cabs/swflash.cab#version=%d,0,0,0\">\n"
369 " <PARAM NAME=\"MOVIE\" VALUE=\"%s\">\n"
370 " <PARAM NAME=\"PLAY\" VALUE=\"true\">\n"
371 " <PARAM NAME=\"LOOP\" VALUE=\"true\">\n"
372 " <PARAM NAME=\"QUALITY\" VALUE=\"high\">\n"
373 " <EMBED SRC=\"%s\" WIDTH=\"%d\" HEIGHT=\"%d\"\n"
374 " PLAY=\"true\" LOOP=\"true\" QUALITY=\"high\"\n"
375 " TYPE=\"application/x-shockwave-flash\"\n"
376 " PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">\n"
378 "</OBJECT>\n", xsize, ysize, swf.fileVersion, filename, filename, xsize, ysize);
381 printf("[HEADER] File version: %d\n", swf.fileVersion);
382 printf("[HEADER] File size: %ld\n", swf.fileSize);
383 printf("[HEADER] Frame rate: %f\n",swf.frameRate/256.0);
384 printf("[HEADER] Frame count: %d\n",swf.frameCount);
385 printf("[HEADER] Movie width: %.3f\n",(swf.movieSize.xmax-swf.movieSize.xmin)/20.0);
386 printf("[HEADER] Movie height: %.3f\n",(swf.movieSize.ymax-swf.movieSize.ymin)/20.0);
392 swf_FontEnumerate(&swf,&fontcallback1);
393 fonts = (SWFFONT**)malloc(fontnum*sizeof(SWFFONT*));
395 swf_FontEnumerate(&swf,&fontcallback2);
399 char*name = swf_TagGetName(tag);
402 fprintf(stderr, "Error: Unknown tag:0x%03x\n", tag->id);
406 printf("[%03x] %9ld %s%s", tag->id, tag->len, prefix, swf_TagGetName(tag));
408 if(swf_isDefiningTag(tag)) {
409 U16 id = swf_GetDefineID(tag);
410 printf(" defines id %04x", id);
412 fprintf(stderr, "Error: Id %04x is defined more than once.\n", id);
415 else if(tag->id == ST_PLACEOBJECT ||
416 tag->id == ST_PLACEOBJECT2) {
417 printf(" places id %04x at depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
419 printf(" name \"%s\"",swf_GetName(tag));
421 else if(tag->id == ST_REMOVEOBJECT) {
422 printf(" removes id %04x from depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
424 else if(tag->id == ST_REMOVEOBJECT2) {
425 printf(" removes object from depth %04x", swf_GetDepth(tag));
427 else if(tag->id == ST_FRAMELABEL) {
428 printf(" \"%s\"", tag->data);
430 fprintf(stderr, "Error: Frame %d has more than one label\n",
431 issprite?spriteframe:mainframe);
433 if(issprite) spriteframelabel = tag->data;
434 else framelabel = tag->data;
436 else if(tag->id == ST_SHOWFRAME) {
437 char*label = issprite?spriteframelabel:framelabel;
438 printf(" %d", issprite?spriteframe:mainframe);
440 printf(" (label \"%s\")", label);
441 if(issprite) {spriteframe++; spriteframelabel = 0;}
442 if(!issprite) {mainframe++; framelabel = 0;}
445 if(tag->id == ST_DEFINEEDITTEXT) {
449 else if(tag->id == ST_DEFINETEXT || tag->id == ST_DEFINETEXT2) {
456 sprintf(myprefix, " %s", prefix);
458 if(tag->id == ST_DEFINESPRITE) {
459 sprintf(prefix, " ");
461 fprintf(stderr, "Error: Sprite definition inside a sprite definition");
465 spriteframelabel = 0;
467 else if(tag->id == ST_END) {
471 fprintf(stderr, "Error: End Tag not empty");
473 else if(tag->id == ST_DOACTION && action) {
475 actions = swf_ActionGet(tag);
476 swf_DumpActions(actions, myprefix);
478 else if(tag->id == ST_DEFINEBUTTON && action) {
479 dumpButtonActions(tag, myprefix);
481 else if(tag->id == ST_DEFINEBUTTON2 && action) {
482 dumpButton2Actions(tag, myprefix);