removed lame.
[swftools.git] / src / swfdump.c
blob038104b4f76bc0d7c0e71faf1d8f3d141fdad3bb
1 /* swfdump.c
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 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 */
22 #include "../config.h"
24 #ifdef HAVE_SYS_STAT_H
25 #include <sys/stat.h>
26 #else
27 #undef HAVE_STAT
28 #endif
30 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
32 #else
33 #undef HAVE_STAT
34 #endif
36 #include <unistd.h>
37 #include <stdio.h>
38 #include <fcntl.h>
39 #include <stdarg.h>
40 #include "../lib/rfxswf.h"
41 #include "../lib/args.h"
43 static char * filename = 0;
45 /* idtab stores the ids which are defined in the file. This allows us
46 to detect errors in the file. (i.e. ids which are defined more than
47 once */
48 static char idtab[65536];
49 static char * indent = " ";
51 static int placements = 0;
52 static int action = 0;
53 static int html = 0;
54 static int xy = 0;
55 static int showtext = 0;
56 static int hex = 0;
57 static int used = 0;
59 static struct options_t options[] = {
60 {"h", "help"},
61 {"D", "full"},
62 {"V", "version"},
63 {"e", "html"},
64 {"a", "action"},
65 {"t", "text"},
66 {"p", "placements"},
67 {"X", "width"},
68 {"Y", "height"},
69 {"r", "rate"},
70 {"f", "frames"},
71 {"d", "hex"},
72 {"u", "used"},
73 {0,0}
76 int args_callback_option(char*name,char*val)
78 if(!strcmp(name, "V")) {
79 printf("swfdump - part of %s %s\n", PACKAGE, VERSION);
80 exit(0);
82 else if(name[0]=='a') {
83 action = 1;
84 return 0;
86 else if(name[0]=='p') {
87 placements = 1;
88 return 0;
90 else if(name[0]=='t') {
91 showtext = 1;
92 return 0;
94 else if(name[0]=='e') {
95 html = 1;
96 return 0;
98 else if(name[0]=='X') {
99 xy |= 1;
100 return 0;
102 else if(name[0]=='Y') {
103 xy |= 2;
104 return 0;
106 else if(name[0]=='r') {
107 xy |= 4;
108 return 0;
110 else if(name[0]=='f') {
111 xy |= 8;
112 return 0;
114 else if(name[0]=='d') {
115 hex = 1;
116 return 0;
118 else if(name[0]=='u') {
119 used = 1;
120 return 0;
122 else if(name[0]=='D') {
123 action = placements = showtext = 1;
124 return 0;
126 else {
127 printf("Unknown option: -%s\n", name);
128 exit(1);
131 return 0;
133 int args_callback_longoption(char*name,char*val)
135 return args_long2shortoption(options, name, val);
137 void args_callback_usage(char *name)
139 printf("\n");
140 printf("Usage: %s [-atpdu] file.swf\n", name);
141 printf("\n");
142 printf("-h , --help Print short help message and exit\n");
143 printf("-D , --full Show everything. Same as -atp\n");
144 printf("-V , --version Print version info and exit\n");
145 printf("-e , --html Print out html code for embedding the file\n");
146 printf("-a , --action Disassemble action tags\n");
147 printf("-t , --text Show text fields (like swfstrings).\n");
148 printf("-p , --placements Show placement information\n");
149 printf("-X , --width Prints out a string of the form \"-X width\".\n");
150 printf("-Y , --height Prints out a string of the form \"-Y height\".\n");
151 printf("-r , --rate Prints out a string of the form \"-r rate\".\n");
152 printf("-f , --frames Prints out a string of the form \"-f framenum\".\n");
153 printf("-d , --hex Print hex output of tag data, too.\n");
154 printf("-u , --used Show referred IDs for each Tag.\n");
155 printf("\n");
157 int args_callback_command(char*name,char*val)
159 if(filename) {
160 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
161 filename, name);
163 filename = name;
164 return 0;
167 char* what;
168 char* testfunc(char*str)
170 printf("%s: %s\n", what, str);
171 return 0;
174 void dumpButton2Actions(TAG*tag, char*prefix)
176 U32 oldTagPos;
177 U32 offsetpos;
178 U32 condition;
180 oldTagPos = swf_GetTagPos(tag);
182 // scan DefineButton2 Record
184 swf_GetU16(tag); // Character ID
185 swf_GetU8(tag); // Flags;
187 offsetpos = swf_GetTagPos(tag); // first offset
188 swf_GetU16(tag);
190 while (swf_GetU8(tag)) // state -> parse ButtonRecord
191 { swf_GetU16(tag); // id
192 swf_GetU16(tag); // layer
193 swf_GetMatrix(tag,NULL); // matrix
194 swf_GetCXForm(tag,NULL,1); // cxform
197 while(offsetpos)
198 { U8 a;
199 ActionTAG*actions;
201 if(tag->pos >= tag->len)
202 break;
204 offsetpos = swf_GetU16(tag);
205 condition = swf_GetU16(tag); // condition
207 actions = swf_ActionGet(tag);
208 printf("%s condition %04x\n", prefix, condition);
209 swf_DumpActions(actions, prefix);
212 swf_SetTagPos(tag,oldTagPos);
213 return;
216 void dumpButtonActions(TAG*tag, char*prefix)
218 ActionTAG*actions;
219 swf_GetU16(tag); // id
220 while (swf_GetU8(tag)) // state -> parse ButtonRecord
221 { swf_GetU16(tag); // id
222 swf_GetU16(tag); // layer
223 swf_GetMatrix(tag,NULL); // matrix
225 actions = swf_ActionGet(tag);
226 swf_DumpActions(actions, prefix);
229 #define ET_HASTEXT 32768
230 #define ET_WORDWRAP 16384
231 #define ET_MULTILINE 8192
232 #define ET_PASSWORD 4096
233 #define ET_READONLY 2048
234 #define ET_HASTEXTCOLOR 1024
235 #define ET_HASMAXLENGTH 512
236 #define ET_HASFONT 256
237 #define ET_X3 128
238 #define ET_X2 64
239 #define ET_HASLAYOUT 32
240 #define ET_NOSELECT 16
241 #define ET_BORDER 8
242 #define ET_X1 4
243 #define ET_X0 2
244 #define ET_USEOUTLINES 1
246 SWF swf;
247 int fontnum = 0;
248 SWFFONT**fonts;
250 void textcallback(void*self, int*glyphs, int*ypos, int nr, int fontid, int fontsize, int startx, int starty, RGBA*color)
252 int font=-1,t;
253 printf(" <%2d glyphs in font %2d, color #%02x%02x%02x%02x> ",nr, fontid, color->r, color->g, color->b, color->a);
254 for(t=0;t<fontnum;t++)
256 if(fonts[t]->id == fontid) {
257 font = t;
258 break;
262 for(t=0;t<nr;t++)
264 unsigned char a;
265 if(font>=0) {
266 if(glyphs[t] >= fonts[font]->numchars /*glyph is in range*/
267 || !fonts[font]->glyph2ascii /* font has ascii<->glyph mapping */
268 ) a = glyphs[t];
269 else
270 a = fonts[font]->glyph2ascii[glyphs[t]];
271 } else {
272 a = glyphs[t];
274 if(a>=32)
275 printf("%c", a);
276 else
277 printf("\\x%x", (int)a);
279 printf("\n");
282 void handleText(TAG*tag)
284 printf("\n");
285 swf_ParseDefineText(tag,textcallback, 0);
288 void handleDefineSound(TAG*tag)
290 U16 id = swf_GetU16(tag);
291 U8 flags = swf_GetU8(tag);
292 int compression = (flags>>4)&3;
293 int rate = (flags>>2)&3;
294 int bits = flags&2?16:8;
295 int stereo = flags&1;
296 printf(" (");
297 if(compression == 0) printf("Raw ");
298 else if(compression == 1) printf("ADPCM ");
299 else if(compression == 2) printf("MP3 ");
300 else printf("? ");
301 if(rate == 0) printf("5.5Khz ");
302 if(rate == 1) printf("11Khz ");
303 if(rate == 2) printf("22Khz ");
304 if(rate == 3) printf("44Khz ");
305 printf("%dBit ", bits);
306 if(stereo) printf("stereo");
307 else printf("mono");
308 printf(")");
311 void handleDefineBits(TAG*tag)
313 U16 id;
314 U8 mode;
315 U16 width,height;
316 int bpp;
317 id = swf_GetU16(tag);
318 mode = swf_GetU8(tag);
319 width = swf_GetU16(tag);
320 height = swf_GetU16(tag);
321 printf(" image %dx%d",width,height);
322 if(mode == 3) printf(" (8 bpp)");
323 else if(mode == 4) printf(" (16 bpp)");
324 else if(mode == 5) printf(" (32 bpp)");
325 else printf(" (? bpp)");
328 void handleEditText(TAG*tag)
330 U16 id ;
331 U16 flags;
332 int t;
333 id = swf_GetU16(tag);
334 swf_GetRect(tag,0);
335 //swf_ResetReadBits(tag);
336 if (tag->readBit)
337 { tag->pos++;
338 tag->readBit = 0;
340 flags = swf_GetBits(tag,16);
341 if(flags & ET_HASFONT) {
342 swf_GetU16(tag); //font
343 swf_GetU16(tag); //fontheight
345 if(flags & ET_HASTEXTCOLOR) {
346 swf_GetU8(tag); //rgba
347 swf_GetU8(tag);
348 swf_GetU8(tag);
349 swf_GetU8(tag);
351 if(flags & ET_HASMAXLENGTH) {
352 swf_GetU16(tag); //maxlength
354 if(flags & ET_HASLAYOUT) {
355 swf_GetU8(tag); //align
356 swf_GetU16(tag); //left margin
357 swf_GetU16(tag); //right margin
358 swf_GetU16(tag); //indent
359 swf_GetU16(tag); //leading
361 printf(" variable \"%s\"", &tag->data[tag->pos]);
363 if(flags & (ET_X1 | ET_X2 | ET_X3 | ET_X0))
365 printf(" undefined flags: %d%d%d%d",
366 (flags&ET_X0?1:0),
367 (flags&ET_X1?1:0),
368 (flags&ET_X2?1:0),
369 (flags&ET_X3?1:0));
372 while(tag->data[tag->pos++]);
373 if(flags & ET_HASTEXT)
374 // printf(" text \"%s\"\n", &tag->data[tag->pos])
377 void printhandlerflags(U32 handlerflags)
379 if(handlerflags&1) printf("[on load]");
380 if(handlerflags&2) printf("[enter frame]");
381 if(handlerflags&4) printf("[unload]");
382 if(handlerflags&8) printf("[mouse move]");
383 if(handlerflags&16) printf("[mouse down]");
384 if(handlerflags&32) printf("[mouse up]");
385 if(handlerflags&64) printf("[key down]");
386 if(handlerflags&128) printf("[key up]");
388 if(handlerflags&256) printf("[data]");
389 if(handlerflags&512) printf("[initialize]");
390 if(handlerflags&1024) printf("[mouse press]");
391 if(handlerflags&2048) printf("[mouse release]");
392 if(handlerflags&4096) printf("[mouse release outside]");
393 if(handlerflags&8192) printf("[mouse rollover]");
394 if(handlerflags&16384) printf("[mouse rollout]");
395 if(handlerflags&32768) printf("[mouse drag over]");
397 if(handlerflags&0x10000) printf("[mouse drag out]");
398 if(handlerflags&0x20000) printf("[key press]");
399 if(handlerflags&0x40000) printf("[construct even]");
400 if(handlerflags&0xfff80000) printf("[???]");
402 void handleVideoStream(TAG*tag, char*prefix)
404 U16 id = swf_GetU16(tag);
405 U16 frames = swf_GetU16(tag);
406 U16 width = swf_GetU16(tag);
407 U16 height = swf_GetU16(tag);
408 U8 flags = swf_GetU8(tag); //5-2(videopacket 01=off 10=on)-1(smoothing 1=on)
409 U8 codec = swf_GetU8(tag);
410 printf(" (%d frames, %dx%d", frames, width, height);
411 if(flags&1)
412 printf(" smoothed");
413 if(codec == 2)
414 printf(" sorenson h.263)");
415 else
416 printf(" codec 0x%02x)", codec);
418 void handleVideoFrame(TAG*tag, char*prefix)
420 U32 code, version, reference, sizeflags;
421 U32 width=0, height=0;
422 U8 type;
423 U16 id = swf_GetU16(tag);
424 U16 frame = swf_GetU16(tag);
425 U8 deblock,flags, tmp, bit;
426 U32 quantizer;
427 char*types[] = {"I-frame", "P-frame", "disposable P-frame", "<reserved>"};
428 printf(" (frame %d) ", frame);
430 /* video packet follows */
431 code = swf_GetBits(tag, 17);
432 version = swf_GetBits(tag, 5);
433 reference = swf_GetBits(tag, 8);
435 sizeflags = swf_GetBits(tag, 3);
436 switch(sizeflags)
438 case 0: width = swf_GetBits(tag, 8); height = swf_GetBits(tag, 8); break;
439 case 1: width = swf_GetBits(tag, 16); height = swf_GetBits(tag, 16); break;
440 case 2: width = 352; height = 288; break;
441 case 3: width = 176; height = 144; break;
442 case 4: width = 128; height = 96; break;
443 case 5: width = 320; height = 240; break;
444 case 6: width = 160; height = 120; break;
445 case 7: width = -1; height = -1;/*reserved*/ break;
447 printf("%dx%d ", width, height);
448 type = swf_GetBits(tag, 2);
449 printf("%s", types[type]);
451 deblock = swf_GetBits(tag, 1);
452 if(deblock)
453 printf(" deblock ", deblock);
454 quantizer = swf_GetBits(tag, 5);
455 printf(" quant: %d ", quantizer);
458 void handlePlaceObject2(TAG*tag, char*prefix)
460 U8 flags = swf_GetU8(tag);
461 MATRIX m;
462 CXFORM cx;
463 char pstr[3][160];
464 int ppos[3] = {0,0,0};
465 swf_GetU16(tag); //depth
467 //flags&1: move
468 if(flags&2) swf_GetU16(tag); //id
469 if(flags&4) {
470 swf_GetMatrix(tag,&m);
471 if(placements) {
472 ppos[0] += sprintf(pstr[0], "| Matrix ");
473 ppos[1] += sprintf(pstr[1], "| %5.3f %5.3f %6.2f ", m.sx/65536.0, m.r1/65536.0, m.tx/20.0);
474 ppos[2] += sprintf(pstr[2], "| %5.3f %5.3f %6.2f ", m.r0/65536.0, m.sy/65536.0, m.ty/20.0);
477 if(flags&8) {
478 swf_GetCXForm(tag, &cx, 1);
479 if(placements) {
480 ppos[0] += sprintf(pstr[0]+ppos[0], "| CXForm r g b a ");
481 ppos[1] += sprintf(pstr[1]+ppos[1], "| mul %4.1f %4.1f %4.1f %4.1f ", cx.r0/256.0, cx.g0/256.0, cx.b0/256.0, cx.a0/256.0);
482 ppos[2] += sprintf(pstr[2]+ppos[2], "| add %4d %4d %4d %4d ", cx.r1, cx.g1, cx.b1, cx.a1);
485 if(flags&16) {
486 U16 ratio = swf_GetU16(tag); //ratio
487 if(placements) {
488 ppos[0] += sprintf(pstr[0]+ppos[0], "| Ratio ");
489 ppos[1] += sprintf(pstr[1]+ppos[1], "| %-5d ", ratio);
490 ppos[2] += sprintf(pstr[2]+ppos[2], "| ");
493 if(flags&64) {
494 U16 clip = swf_GetU16(tag); //clip
495 if(placements) {
496 ppos[0] += sprintf(pstr[0]+ppos[0], "| Clip ");
497 ppos[1] += sprintf(pstr[1]+ppos[1], "| %-5d ", clip);
498 ppos[2] += sprintf(pstr[2]+ppos[2], "| ");
501 if(flags&32) { while(swf_GetU8(tag)); }
502 if(placements && ppos[0]) {
503 printf("\n");
504 printf("%s %s\n", prefix, pstr[0]);
505 printf("%s %s\n", prefix, pstr[1]);
506 printf("%s %s", prefix, pstr[2]);
508 if(flags&128) {
509 if (action) {
510 U16 reserved;
511 U32 globalflags;
512 U32 handlerflags;
513 char is32 = 0;
514 printf("\n");
515 reserved = swf_GetU16(tag); // must be 0
516 globalflags = swf_GetU16(tag); //TODO: 32 if version>=6
517 if(reserved) {
518 printf("Unknown parameter field not zero: %04x\n", reserved);
519 return;
521 printf("global flags: %04x\n", globalflags);
523 handlerflags = swf_GetU16(tag); //TODO: 32 if version>=6
524 if(!handlerflags) {
525 handlerflags = swf_GetU32(tag);
526 is32 = 1;
528 while(handlerflags) {
529 int length;
530 int t;
531 ActionTAG*a;
533 globalflags &= ~handlerflags;
534 printf("%s flags %08x ",prefix, handlerflags);
535 printhandlerflags(handlerflags);
536 length = swf_GetU32(tag);
537 printf(", %d bytes actioncode\n",length);
538 a = swf_ActionGet(tag);
539 swf_DumpActions(a,prefix);
540 swf_ActionFree(a);
542 handlerflags = is32?swf_GetU32(tag):swf_GetU16(tag); //TODO: 32 if version>=6
544 if(globalflags) // should go to sterr.
545 printf("ERROR: unsatisfied handlerflags: %02x\n", globalflags);
546 } else {
547 printf(" has action code\n");
549 } else printf("\n");
552 void handlePlaceObject(TAG*tag, char*prefix)
554 /*TODO*/
557 void fontcallback1(U16 id,U8 * name)
558 { fontnum++;
561 void fontcallback2(U16 id,U8 * name)
563 swf_FontExtract(&swf,id,&fonts[fontnum]);
564 fontnum++;
567 static U8 printable(U8 a)
569 if(a<32 || a==127) return '.';
570 else return a;
572 void hexdumpTag(TAG*tag, char* prefix)
574 int t;
575 char ascii[32];
576 printf(" %s-=> ",prefix);
577 for(t=0;t<tag->len;t++) {
578 printf("%02x ", tag->data[t]);
579 ascii[t&15] = printable(tag->data[t]);
580 if((t && ((t&15)==15)) || (t==tag->len-1))
582 int s,p=((t-1)&15)+1;
583 ascii[p] = 0;
584 for(s=p;s<16;s++) {
585 printf(" ");
587 if(t==tag->len-1)
588 printf(" %s\n", ascii);
589 else
590 printf(" %s\n %s-=> ",ascii,prefix);
595 void handleExportAssets(TAG*tag, char* prefix)
597 int num;
598 U16 id;
599 char* name;
600 int t;
601 num = swf_GetU16(tag);
602 for(t=0;t<num;t++)
604 id = swf_GetU16(tag);
605 name = swf_GetString(tag);
606 printf("%sexports %04d as \"%s\"\n", prefix, id, name);
610 void dumperror(const char* format, ...)
612 char buf[1024];
613 va_list arglist;
615 va_start(arglist, format);
616 vsprintf(buf, format, arglist);
617 va_end(arglist);
619 if(!html && !xy)
620 printf("==== Error: %s ====\n", buf);
623 static char strbuf[800];
624 static int bufpos=0;
626 char* timestring(double f)
628 int hours = (int)(f/3600);
629 int minutes = (int)((f-hours*3600)/60);
630 int seconds = (int)((f-hours*3600-minutes*60));
631 int useconds = (int)((f-(int)f)*1000+0.5);
632 bufpos+=100;
633 bufpos%=800;
634 sprintf(&strbuf[bufpos], "%02d:%02d:%02d,%03d",hours,minutes,seconds,useconds);
635 return &strbuf[bufpos];
638 int main (int argc,char ** argv)
640 TAG*tag;
641 #ifdef HAVE_STAT
642 struct stat statbuf;
643 #endif
644 int f;
645 int xsize,ysize;
646 char issprite = 0; // are we inside a sprite definition?
647 int spriteframe = 0;
648 int mainframe=0;
649 char* spriteframelabel = 0;
650 char* framelabel = 0;
651 char prefix[128];
652 int filesize = 0;
653 prefix[0] = 0;
654 memset(idtab,0,65536);
656 processargs(argc, argv);
658 if(!filename)
660 fprintf(stderr, "You must supply a filename.\n");
661 return 1;
664 f = open(filename,O_RDONLY|O_BINARY);
666 if (f<0)
668 char buffer[256];
669 sprintf(buffer, "Couldn't open %s", filename);
670 perror(buffer);
671 exit(1);
673 if FAILED(swf_ReadSWF(f,&swf))
675 fprintf(stderr, "%s is not a valid SWF file or contains errors.\n",filename);
676 close(f);
677 exit(1);
680 #ifdef HAVE_STAT
681 fstat(f, &statbuf);
682 if(statbuf.st_size != swf.fileSize && !swf.compressed)
683 dumperror("Real Filesize (%d) doesn't match header Filesize (%d)",
684 statbuf.st_size, swf.fileSize);
685 filesize = statbuf.st_size;
686 #endif
688 close(f);
690 xsize = (swf.movieSize.xmax-swf.movieSize.xmin)/20;
691 ysize = (swf.movieSize.ymax-swf.movieSize.ymin)/20;
692 if(xy)
694 if(xy&1)
695 printf("-X %d", xsize);
697 if((xy&1) && (xy&6))
698 printf(" ");
700 if(xy&2)
701 printf("-Y %d", ysize);
703 if((xy&3) && (xy&4))
704 printf(" ");
706 if(xy&4)
707 printf("-r %.2f", swf.frameRate/256.0);
709 if((xy&7) && (xy&8))
710 printf(" ");
712 if(xy&8)
713 printf("-f %d", swf.frameCount);
715 printf("\n");
716 return 0;
718 if(html)
720 char*fileversions[] = {"","1,0,0,0", "2,0,0,0","3,0,0,0","4,0,0,0",
721 "5,0,0,0","6,0,23,0","7,0,0,0","8,0,0,0"};
722 if(swf.fileVersion>8) {
723 fprintf(stderr, "Fileversion>8\n");
724 exit(1);
726 printf("<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n"
727 " WIDTH=\"%d\"\n"
728 //" BGCOLOR=#ffffffff\n"?
729 " HEIGHT=\"%d\"\n"
730 //http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,23,0?
731 " CODEBASE=\"http://active.macromedia.com/flash5/cabs/swflash.cab#version=%s\">\n"
732 " <PARAM NAME=\"MOVIE\" VALUE=\"%s\">\n"
733 " <PARAM NAME=\"PLAY\" VALUE=\"true\">\n"
734 " <PARAM NAME=\"LOOP\" VALUE=\"true\">\n"
735 " <PARAM NAME=\"QUALITY\" VALUE=\"high\">\n"
736 " <EMBED SRC=\"%s\" WIDTH=\"%d\" HEIGHT=\"%d\"\n" //bgcolor=#ffffff?
737 " PLAY=\"true\" ALIGN=\"\" LOOP=\"true\" QUALITY=\"high\"\n"
738 " TYPE=\"application/x-shockwave-flash\"\n"
739 " PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\">\n"
740 " </EMBED>\n"
741 "</OBJECT>\n", xsize, ysize, fileversions[swf.fileVersion],
742 filename, filename, xsize, ysize);
743 return 0;
745 printf("[HEADER] File version: %d\n", swf.fileVersion);
746 if(swf.compressed) {
747 printf("[HEADER] File is zlib compressed.");
748 if(filesize && swf.fileSize)
749 printf(" Ratio: %02d%%\n", filesize*100/(swf.fileSize));
750 else
751 printf("\n");
753 printf("[HEADER] File size: %ld%s\n", swf.fileSize, swf.compressed?" (Depacked)":"");
754 printf("[HEADER] Frame rate: %f\n",swf.frameRate/256.0);
755 printf("[HEADER] Frame count: %d\n",swf.frameCount);
756 printf("[HEADER] Movie width: %.2f",(swf.movieSize.xmax-swf.movieSize.xmin)/20.0);
757 if(swf.movieSize.xmin)
758 printf(" (left offset: %.2f)\n", swf.movieSize.xmin/20.0);
759 else
760 printf("\n");
761 printf("[HEADER] Movie height: %.2f",(swf.movieSize.ymax-swf.movieSize.ymin)/20.0);
762 if(swf.movieSize.ymin)
763 printf(" (top offset: %.2f)\n", swf.movieSize.ymin/20.0);
764 else
765 printf("\n");
767 tag = swf.firstTag;
769 if(showtext) {
770 fontnum = 0;
771 swf_FontEnumerate(&swf,&fontcallback1);
772 fonts = (SWFFONT**)malloc(fontnum*sizeof(SWFFONT*));
773 fontnum = 0;
774 swf_FontEnumerate(&swf,&fontcallback2);
777 while(tag) {
778 char*name = swf_TagGetName(tag);
779 char myprefix[128];
780 if(!name) {
781 dumperror("Unknown tag:0x%03x", tag->id);
782 //tag = tag->next;
783 //continue;
785 if(swf_TagGetName(tag)) {
786 printf("[%03x] %9ld %s%s", tag->id, tag->len, prefix, swf_TagGetName(tag));
787 } else {
788 printf("[%03x] %9ld %sUNKNOWN TAG %03x", tag->id, tag->len, prefix, tag->id);
791 if(tag->id == ST_FREECHARACTER) {
792 U16 id = swf_GetU16(tag);
793 idtab[id] = 0;
796 if(swf_isDefiningTag(tag)) {
797 U16 id = swf_GetDefineID(tag);
798 printf(" defines id %04d", id);
799 if(idtab[id])
800 dumperror("Id %04d is defined more than once.", id);
801 idtab[id] = 1;
803 else if(swf_isPseudoDefiningTag(tag)) {
804 U16 id = swf_GetDefineID(tag);
805 printf(" adds information to id %04d", id);
806 if(!idtab[id])
807 dumperror("Id %04d is not yet defined.\n", id);
809 else if(tag->id == ST_PLACEOBJECT) {
810 printf(" places id %04d at depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
811 if(swf_GetName(tag))
812 printf(" name \"%s\"",swf_GetName(tag));
813 handlePlaceObject(tag, myprefix);
815 else if(tag->id == ST_PLACEOBJECT2) {
816 if(tag->data[0]&1)
817 printf(" moves");
818 else
819 printf(" places");
821 if(tag->data[0]&2)
822 printf(" id %04d",swf_GetPlaceID(tag));
823 else
824 printf(" object");
826 printf(" at depth %04d", swf_GetDepth(tag));
827 if(swf_GetName(tag))
828 printf(" name \"%s\"",swf_GetName(tag));
830 else if(tag->id == ST_REMOVEOBJECT) {
831 printf(" removes id %04d from depth %04d", swf_GetPlaceID(tag), swf_GetDepth(tag));
833 else if(tag->id == ST_REMOVEOBJECT2) {
834 printf(" removes object from depth %04d", swf_GetDepth(tag));
836 else if(tag->id == ST_FREECHARACTER) {
837 printf(" frees object %04d", swf_GetPlaceID(tag));
839 else if(tag->id == ST_STARTSOUND) {
840 U8 flags;
841 U16 id;
842 id = swf_GetU16(tag);
843 flags = swf_GetU8(tag);
844 if(flags & 32)
845 printf(" stops sound with id %04d", id);
846 else
847 printf(" starts sound with id %04d", id);
848 if(flags & 16)
849 printf(" (if not already playing)");
850 if(flags & 1)
851 swf_GetU32(tag);
852 if(flags & 2)
853 swf_GetU32(tag);
854 if(flags & 4) {
855 printf(" looping %d times", swf_GetU16(tag));
858 else if(tag->id == ST_FRAMELABEL) {
859 int l = strlen(tag->data);
860 printf(" \"%s\"", tag->data);
861 if(l < tag->len-1) {
862 printf(" has %d extra bytes", tag->len-1-l);
863 if(tag ->len-1-l == 1 && tag->data[tag->len-1] == 1)
864 printf(" (ANCHOR)");
866 if((framelabel && !issprite) ||
867 (spriteframelabel && issprite)) {
868 dumperror("Frame %d has more than one label",
869 issprite?spriteframe:mainframe);
871 if(issprite) spriteframelabel = tag->data;
872 else framelabel = tag->data;
874 else if(tag->id == ST_SHOWFRAME) {
875 char*label = issprite?spriteframelabel:framelabel;
876 int frame = issprite?spriteframe:mainframe;
877 int nframe = frame;
878 if(!label) {
879 while(tag->next && tag->next->id == ST_SHOWFRAME && tag->next->len == 0) {
880 tag = tag->next;
881 if(issprite) spriteframe++;
882 else mainframe++;
883 nframe++;
886 if(nframe == frame)
887 printf(" %d (%s)", frame, timestring(frame*(256.0/(swf.frameRate+0.1))));
888 else
889 printf(" %d-%d (%s-%s)", frame, nframe,
890 timestring(frame*(256.0/(swf.frameRate+0.1))),
891 timestring(nframe*(256.0/(swf.frameRate+0.1)))
893 if(label)
894 printf(" (label \"%s\")", label);
895 if(issprite) {spriteframe++; spriteframelabel = 0;}
896 if(!issprite) {mainframe++; framelabel = 0;}
899 if(tag->id == ST_SETBACKGROUNDCOLOR) {
900 U8 r = swf_GetU8(tag);
901 U8 g = swf_GetU8(tag);
902 U8 b = swf_GetU8(tag);
903 printf(" (%02x/%02x/%02x)\n",r,g,b);
905 else if(tag->id == ST_PROTECT) {
906 if(tag->len>0) {
907 printf(" %s\n", swf_GetString(tag));
910 else if(tag->id == ST_DEFINEBITSLOSSLESS ||
911 tag->id == ST_DEFINEBITSLOSSLESS2) {
912 handleDefineBits(tag);
913 printf("\n");
915 else if(tag->id == ST_DEFINESOUND) {
916 handleDefineSound(tag);
917 printf("\n");
919 else if(tag->id == ST_VIDEOFRAME) {
920 handleVideoFrame(tag, myprefix);
921 printf("\n");
923 else if(tag->id == ST_DEFINEVIDEOSTREAM) {
924 handleVideoStream(tag, myprefix);
925 printf("\n");
927 else if(tag->id == ST_DEFINEEDITTEXT) {
928 handleEditText(tag);
929 printf("\n");
931 else if(tag->id == ST_DEFINEMOVIE) {
932 U16 id = swf_GetU16(tag);
933 char*s = swf_GetString(tag);
934 printf(" URL: %s\n", s);
936 else if(tag->id == ST_DEFINETEXT || tag->id == ST_DEFINETEXT2) {
937 if(showtext)
938 handleText(tag);
939 else
940 printf("\n");
942 else if(tag->id == ST_PLACEOBJECT2) {
944 else if(tag->id == ST_NAMECHARACTER) {
945 swf_GetU16(tag);
946 printf(" \"%s\"\n", swf_GetString(tag));
948 else {
949 printf("\n");
952 sprintf(myprefix, " %s", prefix);
954 if(tag->id == ST_DEFINESPRITE) {
955 sprintf(prefix, " ");
956 if(issprite) {
957 dumperror("Sprite definition inside a sprite definition");
959 issprite = 1;
960 spriteframe = 0;
961 spriteframelabel = 0;
963 else if(tag->id == ST_END) {
964 *prefix = 0;
965 issprite = 0;
966 spriteframelabel = 0;
967 if(tag->len)
968 dumperror("End Tag not empty");
970 else if(tag->id == ST_EXPORTASSETS) {
971 handleExportAssets(tag, myprefix);
973 else if(tag->id == ST_DOACTION && action) {
974 ActionTAG*actions;
975 actions = swf_ActionGet(tag);
976 swf_DumpActions(actions, myprefix);
978 else if(tag->id == ST_DEFINEBUTTON && action) {
979 dumpButtonActions(tag, myprefix);
981 else if(tag->id == ST_DEFINEBUTTON2 && action) {
982 dumpButton2Actions(tag, myprefix);
984 else if(tag->id == ST_PLACEOBJECT2) {
985 handlePlaceObject2(tag, myprefix);
988 if(tag->len && used) {
989 int num = swf_GetNumUsedIDs(tag);
990 int* used;
991 int t;
992 if(num) {
993 used = (int*)malloc(sizeof(int)*num);
994 swf_GetUsedIDs(tag, used);
995 printf("%s%suses IDs: ", indent, prefix);
996 for(t=0;t<num;t++) {
997 int id;
998 swf_SetTagPos(tag, used[t]);
999 id = swf_GetU16(tag);
1000 printf("%d%s", id, t<num-1?", ":"");
1001 if(!idtab[id]) {
1002 dumperror("Id %04d is not yet defined.\n", id);
1005 printf("\n");
1009 if(tag->len && hex) {
1010 hexdumpTag(tag, prefix);
1012 tag = tag->next;
1013 fflush(stdout);
1016 swf_FreeTags(&swf);
1017 return 0;