bugfixes.
[swftools.git] / src / swfdump.c
1 /* swfdump.c
2    Shows the structure of a swf file
3
4    Part of the swftools package.
5    
6    Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
7
8    This file is distributed under the GPL, see file COPYING for details */
9
10 #include "../config.h"
11
12 #ifdef HAVE_SYS_STAT_H
13 #include <sys/stat.h>
14 #else
15 #undef HAVE_STAT
16 #endif
17
18 #ifdef HAVE_SYS_TYPES_H
19 #include <sys/types.h>
20 #else
21 #undef HAVE_STAT
22 #endif
23
24 #include <unistd.h>
25 #include <stdio.h>
26 #include <fcntl.h>
27 #include <stdarg.h>
28 #include "../lib/rfxswf.h"
29 #include "../lib/args.h"
30
31 char * filename = 0;
32
33 /* idtab stores the ids which are defined in the file. This allows us
34    to detect errors in the file. (i.e. ids which are defined more than 
35    once */
36 char idtab[65536];
37 char * indent = "                ";
38
39 int action = 0;
40 int html = 0;
41 int xy = 0;
42 int showtext = 0;
43 int hex = 0;
44 int used = 0;
45
46 struct options_t options[] =
47 {
48  {"a","action"},
49  {"t","text"},
50  {"X","width"},
51  {"Y","height"},
52  {"f","frames"},
53  {"r","rate"},
54  {"e","html"},
55  {"u","used"},
56  {"v","verbose"},
57  {"V","version"},
58  {"d","hex"},
59  {0,0}
60 };
61
62
63 int args_callback_option(char*name,char*val)
64 {
65     if(!strcmp(name, "V")) {
66         printf("swfdump - part of %s %s\n", PACKAGE, VERSION);
67         exit(0);
68     } 
69     else if(name[0]=='a') {
70         action = 1;
71         return 0;
72     }
73     else if(name[0]=='t') {
74         showtext = 1;
75         return 0;
76     }
77     else if(name[0]=='e') {
78         html = 1;
79         return 0;
80     }
81     else if(name[0]=='X') {
82         xy |= 1;
83         return 0;
84     }
85     else if(name[0]=='Y') {
86         xy |= 2;
87         return 0;
88     }
89     else if(name[0]=='r') {
90         xy |= 4;
91         return 0;
92     }
93     else if(name[0]=='f') {
94         xy |= 8;
95         return 0;
96     }
97     else if(name[0]=='d') {
98         hex = 1;
99         return 0;
100     }
101     else if(name[0]=='u') {
102         used = 1;
103         return 0;
104     }
105     else {
106         printf("Unknown option: -%s\n", name);
107         exit(1);
108     }
109
110     return 0;
111 }
112 int args_callback_longoption(char*name,char*val)
113 {
114     return args_long2shortoption(options, name, val);
115 }
116 void args_callback_usage(char*name)
117 {    
118     printf("Usage: %s [-at] file.swf\n", name);
119     printf("\t-h , --help\t\t Print help and exit\n");
120     printf("\t-e , --html\t\t Create html output embedding the file (simple, but useful)\n");
121     printf("\t-X , --width\t\t Prints out a string of the form \"-X width\"\n");
122     printf("\t-Y , --height\t\t Prints out a string of the form \"-Y height\"\n");
123     printf("\t-r , --rate\t\t Prints out a string of the form \"-r rate\"\n");
124     printf("\t-f , --frames\t\t Prints out a string of the form \"-f framenum\"\n");
125     printf("\t-a , --action\t\t Disassemble action tags\n");
126     printf("\t-t , --text\t\t Show text data\n");
127     printf("\t-d , --hex\t\t Print hex output of tag data, too\n");
128     printf("\t-u , --used\t\t Show referred IDs for each Tag\n");
129     printf("\t-V , --version\t\t Print program version and exit\n");
130 }
131 int args_callback_command(char*name,char*val)
132 {
133     if(filename) {
134         fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
135                  filename, name);
136     }
137     filename = name;
138     return 0;
139 }
140
141 char* what;
142 char* testfunc(char*str)
143 {
144     printf("%s: %s\n", what, str);
145     return 0;
146 }
147
148 void dumpButton2Actions(TAG*tag, char*prefix)
149 {
150     U32 oldTagPos;
151     U32 offsetpos;
152     U32 condition;
153
154     oldTagPos = swf_GetTagPos(tag);
155
156     // scan DefineButton2 Record
157     
158     swf_GetU16(tag);          // Character ID
159     swf_GetU8(tag);           // Flags;
160
161     offsetpos = swf_GetTagPos(tag);  // first offset
162     swf_GetU16(tag);
163
164     while (swf_GetU8(tag))      // state  -> parse ButtonRecord
165     { swf_GetU16(tag);          // id
166       swf_GetU16(tag);          // layer
167       swf_GetMatrix(tag,NULL);  // matrix
168       swf_GetCXForm(tag,NULL,1);  // cxform
169     }
170
171     while(offsetpos)
172     { U8 a;
173       ActionTAG*actions;
174
175       if(tag->pos >= tag->len)
176           break;
177         
178       offsetpos = swf_GetU16(tag);
179       condition = swf_GetU16(tag);                // condition
180       
181       actions = swf_ActionGet(tag);
182       printf("%s condition %04x\n", prefix, condition);
183       swf_DumpActions(actions, prefix);
184     }
185     
186     swf_SetTagPos(tag,oldTagPos);
187     return;
188 }
189
190 void dumpButtonActions(TAG*tag, char*prefix)
191 {
192     ActionTAG*actions;
193     swf_GetU16(tag); // id
194     while (swf_GetU8(tag))      // state  -> parse ButtonRecord
195     { swf_GetU16(tag);          // id
196       swf_GetU16(tag);          // layer
197       swf_GetMatrix(tag,NULL);  // matrix
198     }
199     actions = swf_ActionGet(tag);
200     swf_DumpActions(actions, prefix);
201 }
202
203 #define ET_HASTEXT 32768
204 #define ET_WORDWRAP 16384
205 #define ET_MULTILINE 8192
206 #define ET_PASSWORD 4096
207 #define ET_READONLY 2048
208 #define ET_HASTEXTCOLOR 1024
209 #define ET_HASMAXLENGTH 512
210 #define ET_HASFONT 256
211 #define ET_X3 128
212 #define ET_X2 64
213 #define ET_HASLAYOUT 32
214 #define ET_NOSELECT 16
215 #define ET_BORDER 8
216 #define ET_X1 4
217 #define ET_X0 2
218 #define ET_USEOUTLINES 1
219
220 SWF swf;
221 int fontnum = 0;
222 SWFFONT**fonts;
223
224 void textcallback(int*glyphs, int nr, int fontid) 
225 {
226     int font=-1,t;
227     printf("                <%2d glyphs in font %2d> ",nr, fontid);
228     for(t=0;t<fontnum;t++)
229     {
230         if(fonts[t]->id == fontid) {
231             font = t;
232             break;
233         }
234     }
235
236     for(t=0;t<nr;t++)
237     {
238         unsigned char a; 
239         if(font>=0) {
240             if(glyphs[t] >= fonts[font]->numchars)
241                 continue;
242             a = fonts[font]->glyph2ascii[glyphs[t]];
243         } else {
244             a = glyphs[t];
245         }
246         if(a>=32)
247             printf("%c", a);
248         else
249             printf("\\x%x", (int)a);
250     }
251     printf("\n");
252 }
253
254 void handleText(TAG*tag) 
255 {
256   printf("\n");
257   swf_FontExtract_DefineTextCallback(-1,0,tag,4, textcallback);
258 }
259             
260 void handleDefineSound(TAG*tag)
261 {
262     U16 id = swf_GetU16(tag);
263     U8 flags = swf_GetU8(tag);
264     int compression = (flags>>4)&3;
265     int rate = (flags>>2)&3;
266     int bits = flags&2?16:8;
267     int stereo = flags&1;
268     printf(" (");
269     if(compression == 0) printf("Raw ");
270     else if(compression == 1) printf("ADPCM ");
271     else if(compression == 2) printf("MP3 ");
272     else printf("? ");
273     if(rate == 0) printf("5.5Khz ");
274     if(rate == 1) printf("11Khz ");
275     if(rate == 2) printf("22Khz ");
276     if(rate == 3) printf("44Khz ");
277     printf("%dBit ", bits);
278     if(stereo) printf("stereo");
279     else printf("mono");
280     printf(")");
281 }
282
283 void handleDefineBits(TAG*tag)
284 {
285     U16 id;
286     U8 mode;
287     U16 width,height;
288     int bpp;
289     id = swf_GetU16(tag);
290     mode = swf_GetU8(tag);
291     width = swf_GetU16(tag);
292     height = swf_GetU16(tag);
293     printf(" image %dx%d",width,height);
294     if(mode == 3) printf(" (8 bpp)");
295     else if(mode == 4) printf(" (16 bpp)");
296     else if(mode == 5) printf(" (32 bpp)");
297     else printf(" (? bpp)");
298 }
299
300 void handleEditText(TAG*tag)
301 {
302     U16 id ;
303     U16 flags;
304     int t;
305     id = swf_GetU16(tag);
306     swf_GetRect(tag,0);
307     //swf_ResetReadBits(tag);
308     if (tag->readBit)  
309     { tag->pos++; 
310       tag->readBit = 0; 
311     }
312     flags = swf_GetBits(tag,16);
313     if(flags & ET_HASFONT) {
314         swf_GetU16(tag); //font
315         swf_GetU16(tag); //fontheight
316     }
317     if(flags & ET_HASTEXTCOLOR) {
318         swf_GetU8(tag); //rgba
319         swf_GetU8(tag);
320         swf_GetU8(tag);
321         swf_GetU8(tag);
322     }
323     if(flags & ET_HASMAXLENGTH) {
324         swf_GetU16(tag); //maxlength
325     }
326     if(flags & ET_HASLAYOUT) {
327         swf_GetU8(tag); //align
328         swf_GetU16(tag); //left margin
329         swf_GetU16(tag); //right margin
330         swf_GetU16(tag); //indent
331         swf_GetU16(tag); //leading
332     }
333     printf(" variable \"%s\"", &tag->data[tag->pos]);
334
335     if(flags & (ET_X1 | ET_X2 | ET_X3 | ET_X0))
336     {
337         printf(" undefined flags: %d%d%d%d", 
338                 (flags&ET_X0?1:0),
339                 (flags&ET_X1?1:0),
340                 (flags&ET_X2?1:0),
341                 (flags&ET_X3?1:0));
342     }
343     
344     while(tag->data[tag->pos++]);
345     if(flags & ET_HASTEXT)
346    //  printf(" text \"%s\"\n", &tag->data[tag->pos])
347         ;
348 }
349 void printhandlerflags(U16 handlerflags) 
350 {
351     if(handlerflags&1) printf("[on load]");
352     if(handlerflags&2) printf("[enter frame]");
353     if(handlerflags&4) printf("[unload]");
354     if(handlerflags&8) printf("[mouse move]");
355     if(handlerflags&16) printf("[mouse down]");
356     if(handlerflags&32) printf("[mouse up]");
357     if(handlerflags&64) printf("[key down]");
358     if(handlerflags&128) printf("[key up]");
359     if(handlerflags&256) printf("[data]");
360     if(handlerflags&0xfe00) printf("[???]");
361 }
362 void handlePlaceObject2(TAG*tag, char*prefix)
363 {
364     U8 flags = swf_GetU8(tag);
365     swf_GetU16(tag); //depth
366     //flags&1: move
367     if(flags&2) swf_GetU16(tag); //id
368     if(flags&4) swf_GetMatrix(tag,0);
369     if(flags&8) swf_GetCXForm(tag,0,1);
370     if(flags&16) swf_GetU16(tag); //ratio
371     if(flags&32) { while(swf_GetU8(tag)); }
372     if(flags&64) swf_GetU16(tag); //clip
373     if(flags&128) {
374       if (action) {
375         U16 unknown;
376         U32 globalflags;
377         U32 handlerflags;
378         char is32 = 0;
379         printf("\n");
380         unknown = swf_GetU16(tag);
381         globalflags = swf_GetU16(tag);
382         if(unknown) {
383             printf("Unknown parameter field not zero: %04x\n", unknown);
384             return;
385         }
386         printf("global flags: %04x\n", globalflags);
387         handlerflags = swf_GetU16(tag);
388         if(!handlerflags) {
389             handlerflags = swf_GetU32(tag);
390             is32 = 1;
391         }
392         while(handlerflags)  {
393             int length;
394             int t;
395             ActionTAG*a;
396
397             globalflags &= ~handlerflags;
398             printf("%s flags %08x ",prefix, handlerflags);
399             printhandlerflags(handlerflags);
400             length = swf_GetU32(tag);
401             printf(", %d bytes actioncode\n",length);
402             a = swf_ActionGet(tag);
403             swf_DumpActions(a,prefix);
404             swf_ActionFree(a);
405
406             handlerflags = is32?swf_GetU32(tag):swf_GetU16(tag);
407         }
408         if(globalflags) // should go to sterr.
409             printf("ERROR: unsatisfied handlerflags: %02x\n", globalflags);
410     } else {
411       printf(" has action code\n");
412     }
413     } else printf("\n");
414 }
415     
416 void fontcallback1(U16 id,U8 * name)
417 { fontnum++;
418 }
419
420 void fontcallback2(U16 id,U8 * name)
421
422   swf_FontExtract(&swf,id,&fonts[fontnum]);
423   fontnum++;
424 }
425
426 void hexdumpTag(TAG*tag, char* prefix)
427 {
428     int t;
429     printf("                %s-=> ",prefix);
430     for(t=0;t<tag->len;t++) {
431         printf("%02x ", tag->data[t]);
432         if((t && ((t&15)==15)) || (t==tag->len-1))
433         {
434             if(t==tag->len-1)
435                 printf("\n");
436             else
437                 printf("\n                %s-=> ",prefix);
438         }
439     }
440 }
441
442 void dumperror(const char* format, ...)
443 {
444     char buf[1024];
445     va_list arglist;
446
447     va_start(arglist, format);
448     vsprintf(buf, format, arglist);
449     va_end(arglist);
450
451     if(!html && !xy)
452         printf("==== Error: %s ====\n", buf);
453 }
454
455 static char strbuf[800];
456 static int bufpos=0;
457
458 char* timestring(double f)
459 {
460     int hours   = (int)(f/3600);
461     int minutes = (int)((f-hours*3600)/60);
462     int seconds = (int)((f-hours*3600-minutes*60));
463     int useconds = (int)((f-(int)f)*1000+0.5);
464     bufpos+=100;
465     bufpos%=800;
466     sprintf(&strbuf[bufpos], "%02d:%02d:%02d,%03d",hours,minutes,seconds,useconds);
467     return &strbuf[bufpos];
468 }
469
470 int main (int argc,char ** argv)
471
472     TAG*tag;
473 #ifdef HAVE_STAT
474     struct stat statbuf;
475 #endif
476     int f;
477     int xsize,ysize;
478     char issprite = 0; // are we inside a sprite definition?
479     int spriteframe = 0;
480     int mainframe=0;
481     char* spriteframelabel = 0;
482     char* framelabel = 0;
483     char prefix[128];
484     int filesize = 0;
485     prefix[0] = 0;
486     memset(idtab,0,65536);
487
488     processargs(argc, argv);
489
490     if(!filename)
491     {
492         fprintf(stderr, "You must supply a filename.\n");
493         return 1;
494     }
495
496     f = open(filename,O_RDONLY);
497
498     if (f<0)
499     { 
500         perror("Couldn't open file: ");
501         exit(1);
502     }
503     if FAILED(swf_ReadSWF(f,&swf))
504     { 
505         fprintf(stderr, "%s is not a valid SWF file or contains errors.\n",filename);
506         close(f);
507         exit(1);
508     }
509
510 #ifdef HAVE_STAT
511     fstat(f, &statbuf);
512     if(statbuf.st_size != swf.fileSize && !swf.compressed)
513         dumperror("Real Filesize (%d) doesn't match header Filesize (%d)",
514                 statbuf.st_size, swf.fileSize);
515     filesize = statbuf.st_size;
516 #endif
517
518     close(f);
519
520     xsize = (swf.movieSize.xmax-swf.movieSize.xmin)/20;
521     ysize = (swf.movieSize.ymax-swf.movieSize.ymin)/20;
522     if(xy)
523     {
524         if(xy&1)
525         printf("-X %d", xsize);
526
527         if((xy&1) && (xy&6))
528         printf(" ");
529
530         if(xy&2)
531         printf("-Y %d", ysize);
532         
533         if((xy&3) && (xy&4))
534         printf(" ");
535
536         if(xy&4)
537         printf("-r %d", swf.frameRate*100/256);
538         
539         if((xy&7) && (xy&8))
540         printf(" ");
541         
542         if(xy&8)
543         printf("-f %d", swf.frameCount);
544         
545         printf("\n");
546         return 0;
547     }
548     if(html)
549     {
550         char*fileversions[] = {"","1,0,0,0", "2,0,0,0","3,0,0,0","4,0,0,0",
551                                "5,0,0,0","6,0,23,0","7,0,0,0","8,0,0,0"};
552         if(swf.fileVersion>8) {
553             fprintf(stderr, "Fileversion>8\n");
554             exit(1);
555         }
556         printf("<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n"
557                " WIDTH=\"%d\"\n"
558                //" BGCOLOR=#ffffffff\n"?
559                " HEIGHT=\"%d\"\n"
560                //http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,23,0?
561                " CODEBASE=\"http://active.macromedia.com/flash5/cabs/swflash.cab#version=%s\">\n"
562                "  <PARAM NAME=\"MOVIE\" VALUE=\"%s\">\n"
563                "  <PARAM NAME=\"PLAY\" VALUE=\"true\">\n" 
564                "  <PARAM NAME=\"LOOP\" VALUE=\"true\">\n"
565                "  <PARAM NAME=\"QUALITY\" VALUE=\"high\">\n"
566                "  <EMBED SRC=\"%s\" WIDTH=\"%d\" HEIGHT=\"%d\"\n" //bgcolor=#ffffff?
567                "   PLAY=\"true\" ALIGN=\"\" LOOP=\"true\" QUALITY=\"high\"\n"
568                "   TYPE=\"application/x-shockwave-flash\"\n"
569                "   PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\">\n"
570                "  </EMBED>\n" 
571                "</OBJECT>\n", xsize, ysize, fileversions[swf.fileVersion], 
572                               filename, filename, xsize, ysize);
573         return 0;
574     } 
575     printf("[HEADER]        File version: %d\n", swf.fileVersion);
576     if(swf.compressed) {
577         printf("[HEADER]        File is zlib compressed.");
578         if(filesize && swf.fileSize)
579             printf(" Ratio: %02d%%\n", filesize*100/(swf.fileSize));
580         else
581             printf("\n");
582     }
583     printf("[HEADER]        File size: %ld%s\n", swf.fileSize, swf.compressed?" (Depacked)":"");
584     printf("[HEADER]        Frame rate: %f\n",swf.frameRate/256.0);
585     printf("[HEADER]        Frame count: %d\n",swf.frameCount);
586     printf("[HEADER]        Movie width: %.3f\n",(swf.movieSize.xmax-swf.movieSize.xmin)/20.0);
587     printf("[HEADER]        Movie height: %.3f\n",(swf.movieSize.ymax-swf.movieSize.ymin)/20.0);
588
589     tag = swf.firstTag;
590    
591     if(showtext) {
592         fontnum = 0;
593         swf_FontEnumerate(&swf,&fontcallback1);
594         fonts = (SWFFONT**)malloc(fontnum*sizeof(SWFFONT*));
595         fontnum = 0;
596         swf_FontEnumerate(&swf,&fontcallback2);
597     }
598
599     while(tag) {
600         char*name = swf_TagGetName(tag);
601         char myprefix[128];
602         if(!name) {
603             dumperror("Unknown tag:0x%03x", tag->id);
604             tag = tag->next;
605             continue;
606         }
607         printf("[%03x] %9ld %s%s", tag->id, tag->len, prefix, swf_TagGetName(tag));
608         
609         if(tag->id == ST_FREECHARACTER) {
610             U16 id = swf_GetU16(tag);
611             idtab[id] = 0;
612         }
613
614         if(swf_isDefiningTag(tag)) {
615             U16 id = swf_GetDefineID(tag);
616             printf(" defines id %04d", id);
617             if(idtab[id])
618                 dumperror("Id %04d is defined more than once.", id);
619             idtab[id] = 1;
620         }
621         else if(swf_isPseudoDefiningTag(tag)) {
622             U16 id = swf_GetDefineID(tag);
623             printf(" adds information to id %04d", id);
624             if(!idtab[id])
625                 dumperror("Id %04d is not yet defined.\n", id);
626         }
627         else if(tag->id == ST_PLACEOBJECT) {
628             printf(" places id %04d at depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
629             if(swf_GetName(tag))
630                 printf(" name \"%s\"",swf_GetName(tag));
631         }
632         else if(tag->id == ST_PLACEOBJECT2) {
633             if(tag->data[0]&1)
634                 printf(" moves");
635             else
636                 printf(" places");
637             
638             if(tag->data[0]&2)
639                 printf(" id %04d",swf_GetPlaceID(tag));
640             else
641                 printf(" object");
642
643             printf(" at depth %04d", swf_GetDepth(tag));
644             if(swf_GetName(tag))
645                 printf(" name \"%s\"",swf_GetName(tag));
646         }
647         else if(tag->id == ST_REMOVEOBJECT) {
648             printf(" removes id %04d from depth %04d", swf_GetPlaceID(tag), swf_GetDepth(tag));
649         }
650         else if(tag->id == ST_REMOVEOBJECT2) {
651             printf(" removes object from depth %04d", swf_GetDepth(tag));
652         }
653         else if(tag->id == ST_FREECHARACTER) {
654             printf(" frees object %04d", swf_GetPlaceID(tag));
655         }
656         else if(tag->id == ST_STARTSOUND) {
657             U8 flags;
658             U16 id;
659             id = swf_GetU16(tag);
660             flags = swf_GetU8(tag);
661             if(flags & 32)
662                 printf(" stops sound with id %04d", id);
663             else
664                 printf(" starts sound with id %04d", id);
665             if(flags & 16)
666                 printf(" (if not already playing)");
667             if(flags & 1)
668                 swf_GetU32(tag);
669             if(flags & 2)
670                 swf_GetU32(tag);
671             if(flags & 4) {
672                 printf(" looping %d times", swf_GetU16(tag));
673             }
674         }
675         else if(tag->id == ST_FRAMELABEL) {
676             int l = strlen(tag->data);
677             printf(" \"%s\"", tag->data);
678             if(l < tag->len-1) {
679                 printf(" has %d extra bytes", tag->len-1-l);
680                 if(tag ->len-1-l == 1 && tag->data[tag->len-1] == 1)
681                     printf(" (ANCHOR)");
682             }
683             if((framelabel && !issprite) ||
684                (spriteframelabel && issprite)) {
685                 dumperror("Frame %d has more than one label", 
686                         issprite?spriteframe:mainframe);
687             }
688             if(issprite) spriteframelabel = tag->data;
689             else framelabel = tag->data;
690         }
691         else if(tag->id == ST_SHOWFRAME) {
692             char*label = issprite?spriteframelabel:framelabel;
693             int frame = issprite?spriteframe:mainframe;
694             int nframe = frame;
695             if(!label) {
696                 while(tag->next && tag->next->id == ST_SHOWFRAME && tag->next->len == 0) {
697                     tag = tag->next;
698                     if(issprite) spriteframe++;
699                     else mainframe++;
700                     nframe++;
701                 }
702             }
703             if(nframe == frame)
704                 printf(" %d (%s)", frame, timestring(frame*(256.0/(swf.frameRate+0.1))));
705             else
706                 printf(" %d-%d (%s-%s)", frame, nframe,
707                         timestring(frame*(256.0/(swf.frameRate+0.1))),
708                         timestring(nframe*(256.0/(swf.frameRate+0.1)))
709                         );
710             if(label)
711                 printf(" (label \"%s\")", label);
712             if(issprite) {spriteframe++; spriteframelabel = 0;}
713             if(!issprite) {mainframe++; framelabel = 0;}
714         }
715
716         if(tag->id == ST_SETBACKGROUNDCOLOR) {
717             U8 r = swf_GetU8(tag);
718             U8 g = swf_GetU8(tag);
719             U8 b = swf_GetU8(tag);
720             printf(" (%02x/%02x/%02x)",r,g,b);
721         }
722
723         if(tag->id == ST_DEFINEBITSLOSSLESS ||
724            tag->id == ST_DEFINEBITSLOSSLESS2) {
725             handleDefineBits(tag);
726             printf("\n");
727         }
728         else if(tag->id == ST_DEFINESOUND) {
729             handleDefineSound(tag);
730             printf("\n");
731         }
732         else if(tag->id == ST_DEFINEEDITTEXT) {
733             handleEditText(tag);
734             printf("\n");
735         }
736         else if(tag->id == ST_DEFINETEXT || tag->id == ST_DEFINETEXT2) {
737             if(showtext)
738                 handleText(tag);
739             else
740                 printf("\n");
741         }
742         else if(tag->id == ST_PLACEOBJECT2) {
743         }
744         else {
745             printf("\n");
746         }
747         
748         sprintf(myprefix, "                %s", prefix);
749
750         if(tag->id == ST_DEFINESPRITE) {
751             sprintf(prefix, "         ");
752             if(issprite) {
753                 dumperror("Sprite definition inside a sprite definition");
754             }
755             issprite = 1;
756             spriteframe = 0;
757             spriteframelabel = 0;
758         }
759         else if(tag->id == ST_END) {
760             *prefix = 0;
761             issprite = 0;
762             spriteframelabel = 0;
763             if(tag->len)
764                 dumperror("End Tag not empty");
765         }
766         else if(tag->id == ST_DOACTION && action) {
767             ActionTAG*actions;
768             actions = swf_ActionGet(tag);
769             swf_DumpActions(actions, myprefix);
770         }
771         else if(tag->id == ST_DEFINEBUTTON && action) {
772             dumpButtonActions(tag, myprefix);
773         }
774         else if(tag->id == ST_DEFINEBUTTON2 && action) {
775             dumpButton2Actions(tag, myprefix);
776         }
777         else if(tag->id == ST_PLACEOBJECT2) {
778             if((*(U8*)tag->data)&0x80)
779                 handlePlaceObject2(tag, myprefix);
780             else
781                 printf("\n");
782         }
783
784         if(tag->len && used) {
785             int num = swf_GetNumUsedIDs(tag);
786             int* used;
787             int t;
788             if(num) {
789                 used = (int*)malloc(sizeof(int)*num);
790                 swf_GetUsedIDs(tag, used);
791                 printf("%s%suses IDs: ", indent, prefix);
792                 for(t=0;t<num;t++) {
793                     swf_SetTagPos(tag, used[t]);
794                     printf("%d%s", swf_GetU16(tag), t<num-1?", ":"");
795                 }
796                 printf("\n");
797             }
798         }
799
800         if(tag->len && hex) {
801             hexdumpTag(tag, prefix);
802         }
803         tag = tag->next;
804         fflush(stdout);
805     }
806
807     swf_FreeTags(&swf);
808     return 0;
809 }
810
811