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