0278ec89d836b6040916d22878ec9a510ceda58c
[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 static char strbuf[800];
455 static int bufpos=0;
456
457 char* timestring(double f)
458 {
459     int hours   = (int)(f/3600);
460     int minutes = (int)((f-hours*3600)/60);
461     int seconds = (int)((f-hours*3600-minutes*60));
462     int useconds = (int)((f-(int)f)*1000+0.5);
463     bufpos+=100;
464     bufpos%=800;
465     sprintf(&strbuf[bufpos], "%02d:%02d:%02d,%03d",hours,minutes,seconds,useconds);
466     return &strbuf[bufpos];
467 }
468
469 int main (int argc,char ** argv)
470
471     TAG*tag;
472 #ifdef HAVE_STAT
473     struct stat statbuf;
474 #endif
475     int f;
476     int xsize,ysize;
477     char issprite = 0; // are we inside a sprite definition?
478     int spriteframe = 0;
479     int mainframe=0;
480     char* spriteframelabel = 0;
481     char* framelabel = 0;
482     char prefix[128];
483     int filesize = 0;
484     prefix[0] = 0;
485     memset(idtab,0,65536);
486
487     processargs(argc, argv);
488
489     if(!filename)
490     {
491         fprintf(stderr, "You must supply a filename.\n");
492         return 1;
493     }
494
495     f = open(filename,O_RDONLY);
496
497     if (f<0)
498     { 
499         perror("Couldn't open file: ");
500         exit(1);
501     }
502     if FAILED(swf_ReadSWF(f,&swf))
503     { 
504         fprintf(stderr, "%s is not a valid SWF file or contains errors.\n",filename);
505         close(f);
506         exit(1);
507     }
508
509 #ifdef HAVE_STAT
510     fstat(f, &statbuf);
511     if(statbuf.st_size != swf.fileSize && !swf.compressed)
512         dumperror("Real Filesize (%d) doesn't match header Filesize (%d)",
513                 statbuf.st_size, swf.fileSize);
514     filesize = statbuf.st_size;
515 #endif
516
517     close(f);
518
519     xsize = (swf.movieSize.xmax-swf.movieSize.xmin)/20;
520     ysize = (swf.movieSize.ymax-swf.movieSize.ymin)/20;
521     if(xy)
522     {
523         if(xy&1)
524         printf("-X %d", xsize);
525
526         if((xy&1) && (xy&6))
527         printf(" ");
528
529         if(xy&2)
530         printf("-Y %d", ysize);
531         
532         if((xy&3) && (xy&4))
533         printf(" ");
534
535         if(xy&4)
536         printf("-r %d", swf.frameRate*100/256);
537         
538         if((xy&7) && (xy&8))
539         printf(" ");
540         
541         if(xy&8)
542         printf("-f %d", swf.frameCount);
543         
544         printf("\n");
545         return 0;
546     }
547     if(html)
548     {
549         char*fileversions[] = {"","1,0,0,0", "2,0,0,0","3,0,0,0","4,0,0,0",
550                                "5,0,0,0","6,0,23,0","7,0,0,0","8,0,0,0"};
551         if(swf.fileVersion>8) {
552             fprintf(stderr, "Fileversion>8\n");
553             exit(1);
554         }
555         printf("<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n"
556                " WIDTH=\"%d\"\n"
557                //" BGCOLOR=#ffffffff\n"?
558                " HEIGHT=\"%d\"\n"
559                //http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,23,0?
560                " CODEBASE=\"http://active.macromedia.com/flash5/cabs/swflash.cab#version=%s\">\n"
561                "  <PARAM NAME=\"MOVIE\" VALUE=\"%s\">\n"
562                "  <PARAM NAME=\"PLAY\" VALUE=\"true\">\n" 
563                "  <PARAM NAME=\"LOOP\" VALUE=\"true\">\n"
564                "  <PARAM NAME=\"QUALITY\" VALUE=\"high\">\n"
565                "  <EMBED SRC=\"%s\" WIDTH=\"%d\" HEIGHT=\"%d\"\n" //bgcolor=#ffffff?
566                "   PLAY=\"true\" ALIGN=\"\" LOOP=\"true\" QUALITY=\"high\"\n"
567                "   TYPE=\"application/x-shockwave-flash\"\n"
568                "   PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\">\n"
569                "  </EMBED>\n" 
570                "</OBJECT>\n", xsize, ysize, fileversions[swf.fileVersion], 
571                               filename, filename, xsize, ysize);
572         return 0;
573     } 
574     printf("[HEADER]        File version: %d\n", swf.fileVersion);
575     if(swf.compressed) {
576         printf("[HEADER]        File is zlib compressed.");
577         if(filesize && swf.fileSize)
578             printf(" Ratio: %02d%%\n", filesize*100/(swf.fileSize));
579         else
580             printf("\n");
581     }
582     printf("[HEADER]        File size: %ld%s\n", swf.fileSize, swf.compressed?" (Depacked)":"");
583     printf("[HEADER]        Frame rate: %f\n",swf.frameRate/256.0);
584     printf("[HEADER]        Frame count: %d\n",swf.frameCount);
585     printf("[HEADER]        Movie width: %.3f\n",(swf.movieSize.xmax-swf.movieSize.xmin)/20.0);
586     printf("[HEADER]        Movie height: %.3f\n",(swf.movieSize.ymax-swf.movieSize.ymin)/20.0);
587
588     tag = swf.firstTag;
589    
590     if(showtext) {
591         fontnum = 0;
592         swf_FontEnumerate(&swf,&fontcallback1);
593         fonts = (SWFFONT**)malloc(fontnum*sizeof(SWFFONT*));
594         fontnum = 0;
595         swf_FontEnumerate(&swf,&fontcallback2);
596     }
597
598     while(tag) {
599         char*name = swf_TagGetName(tag);
600         char myprefix[128];
601         if(!name) {
602             dumperror("Unknown tag:0x%03x", tag->id);
603             tag = tag->next;
604             continue;
605         }
606         printf("[%03x] %9ld %s%s", tag->id, tag->len, prefix, swf_TagGetName(tag));
607         
608         if(tag->id == ST_FREECHARACTER) {
609             U16 id = swf_GetU16(tag);
610             idtab[id] = 0;
611         }
612
613         if(swf_isDefiningTag(tag)) {
614             U16 id = swf_GetDefineID(tag);
615             printf(" defines id %04d", id);
616             if(idtab[id])
617                 dumperror("Id %04d is defined more than once.", id);
618             idtab[id] = 1;
619         }
620         else if(swf_isPseudoDefiningTag(tag)) {
621             U16 id = swf_GetDefineID(tag);
622             printf(" adds information to id %04d", id);
623             if(!idtab[id])
624                 dumperror("Id %04d is not yet defined.\n", id);
625         }
626         else if(tag->id == ST_PLACEOBJECT) {
627             printf(" places id %04d at depth %04x", swf_GetPlaceID(tag), swf_GetDepth(tag));
628             if(swf_GetName(tag))
629                 printf(" name \"%s\"",swf_GetName(tag));
630         }
631         else if(tag->id == ST_PLACEOBJECT2) {
632             if(tag->data[0]&1)
633                 printf(" moves");
634             else
635                 printf(" places");
636             
637             if(tag->data[0]&2)
638                 printf(" id %04d",swf_GetPlaceID(tag));
639             else
640                 printf(" object");
641
642             printf(" at depth %04d", swf_GetDepth(tag));
643             if(swf_GetName(tag))
644                 printf(" name \"%s\"",swf_GetName(tag));
645         }
646         else if(tag->id == ST_REMOVEOBJECT) {
647             printf(" removes id %04d from depth %04d", swf_GetPlaceID(tag), swf_GetDepth(tag));
648         }
649         else if(tag->id == ST_REMOVEOBJECT2) {
650             printf(" removes object from depth %04d", swf_GetDepth(tag));
651         }
652         else if(tag->id == ST_FREECHARACTER) {
653             printf(" frees object %04d", swf_GetPlaceID(tag));
654         }
655         else if(tag->id == ST_STARTSOUND) {
656             printf(" starts id %04d", swf_GetPlaceID(tag));
657         }
658         else if(tag->id == ST_FRAMELABEL) {
659             int l = strlen(tag->data);
660             printf(" \"%s\"", tag->data);
661             if(l < tag->len-1) {
662                 printf(" has %d extra bytes", tag->len-1-l);
663                 if(tag ->len-1-l == 1 && tag->data[tag->len-1] == 1)
664                     printf(" (ANCHOR)");
665             }
666             if((framelabel && !issprite) ||
667                (spriteframelabel && issprite)) {
668                 dumperror("Frame %d has more than one label", 
669                         issprite?spriteframe:mainframe);
670             }
671             if(issprite) spriteframelabel = tag->data;
672             else framelabel = tag->data;
673         }
674         else if(tag->id == ST_SHOWFRAME) {
675             char*label = issprite?spriteframelabel:framelabel;
676             int frame = issprite?spriteframe:mainframe;
677             int nframe = frame;
678             if(!label) {
679                 while(tag->next && tag->next->id == ST_SHOWFRAME && tag->next->len == 0) {
680                     tag = tag->next;
681                     if(issprite) spriteframe++;
682                     else mainframe++;
683                     nframe++;
684                 }
685             }
686             if(nframe == frame)
687                 printf(" %d (%s)", frame, timestring(frame*(256.0/(swf.frameRate+0.1))));
688             else
689                 printf(" %d-%d (%s-%s)", frame, nframe,
690                         timestring(frame*(256.0/(swf.frameRate+0.1))),
691                         timestring(nframe*(256.0/(swf.frameRate+0.1)))
692                         );
693             if(label)
694                 printf(" (label \"%s\")", label);
695             if(issprite) {spriteframe++; spriteframelabel = 0;}
696             if(!issprite) {mainframe++; framelabel = 0;}
697         }
698
699         if(tag->id == ST_SETBACKGROUNDCOLOR) {
700             U8 r = swf_GetU8(tag);
701             U8 g = swf_GetU8(tag);
702             U8 b = swf_GetU8(tag);
703             printf(" (%02x/%02x/%02x)",r,g,b);
704         }
705
706         if(tag->id == ST_DEFINEBITSLOSSLESS ||
707            tag->id == ST_DEFINEBITSLOSSLESS2) {
708             handleDefineBits(tag);
709             printf("\n");
710         }
711         else if(tag->id == ST_DEFINESOUND) {
712             handleDefineSound(tag);
713             printf("\n");
714         }
715         else if(tag->id == ST_DEFINEEDITTEXT) {
716             handleEditText(tag);
717             printf("\n");
718         }
719         else if(tag->id == ST_DEFINETEXT || tag->id == ST_DEFINETEXT2) {
720             if(showtext)
721                 handleText(tag);
722             else
723                 printf("\n");
724         }
725         else if(tag->id == ST_PLACEOBJECT2) {
726         }
727         else {
728             printf("\n");
729         }
730         
731         sprintf(myprefix, "                %s", prefix);
732
733         if(tag->id == ST_DEFINESPRITE) {
734             sprintf(prefix, "         ");
735             if(issprite) {
736                 dumperror("Sprite definition inside a sprite definition");
737             }
738             issprite = 1;
739             spriteframe = 0;
740             spriteframelabel = 0;
741         }
742         else if(tag->id == ST_END) {
743             *prefix = 0;
744             issprite = 0;
745             spriteframelabel = 0;
746             if(tag->len)
747                 dumperror("End Tag not empty");
748         }
749         else if(tag->id == ST_DOACTION && action) {
750             ActionTAG*actions;
751             actions = swf_ActionGet(tag);
752             swf_DumpActions(actions, myprefix);
753         }
754         else if(tag->id == ST_DEFINEBUTTON && action) {
755             dumpButtonActions(tag, myprefix);
756         }
757         else if(tag->id == ST_DEFINEBUTTON2 && action) {
758             dumpButton2Actions(tag, myprefix);
759         }
760         else if(tag->id == ST_PLACEOBJECT2) {
761             if((*(U8*)tag->data)&0x80)
762                 handlePlaceObject2(tag, myprefix);
763             else
764                 printf("\n");
765         }
766
767         if(tag->len && used) {
768             int num = swf_GetNumUsedIDs(tag);
769             int* used;
770             int t;
771             if(num) {
772                 used = (int*)malloc(sizeof(int)*num);
773                 swf_GetUsedIDs(tag, used);
774                 printf("%s%suses IDs: ", indent, prefix);
775                 for(t=0;t<num;t++) {
776                     swf_SetTagPos(tag, used[t]);
777                     printf("%d%s", swf_GetU16(tag), t<num-1?", ":"");
778                 }
779                 printf("\n");
780             }
781         }
782
783         if(tag->len && hex) {
784             hexdumpTag(tag, prefix);
785         }
786         tag = tag->next;
787         fflush(stdout);
788     }
789
790     swf_FreeTags(&swf);
791     return 0;
792 }
793
794