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