+void dumpButton2Actions(TAG*tag, char*prefix)
+{
+ U32 oldTagPos;
+ U32 offsetpos;
+ U32 condition;
+
+ oldTagPos = swf_GetTagPos(tag);
+
+ // scan DefineButton2 Record
+
+ swf_GetU16(tag); // Character ID
+ swf_GetU8(tag); // Flags;
+
+ offsetpos = swf_GetTagPos(tag); // first offset
+ swf_GetU16(tag);
+
+ while (swf_GetU8(tag)) // state -> parse ButtonRecord
+ { swf_GetU16(tag); // id
+ swf_GetU16(tag); // layer
+ swf_GetMatrix(tag,NULL); // matrix
+ swf_GetCXForm(tag,NULL,1); // cxform
+ }
+
+ while(offsetpos)
+ { U8 a;
+ ActionTAG*actions;
+
+ if(tag->pos >= tag->len)
+ break;
+
+ offsetpos = swf_GetU16(tag);
+ condition = swf_GetU16(tag); // condition
+
+ actions = swf_ActionGet(tag);
+ printf("%s condition %04x\n", prefix, condition);
+ swf_DumpActions(actions, prefix);
+ }
+
+ swf_SetTagPos(tag,oldTagPos);
+ return;
+}
+
+void dumpButtonActions(TAG*tag, char*prefix)
+{
+ ActionTAG*actions;
+ swf_GetU16(tag); // id
+ while (swf_GetU8(tag)) // state -> parse ButtonRecord
+ { swf_GetU16(tag); // id
+ swf_GetU16(tag); // layer
+ swf_GetMatrix(tag,NULL); // matrix
+ }
+ actions = swf_ActionGet(tag);
+ swf_DumpActions(actions, prefix);
+}
+
+#define ET_HASTEXT 32768
+#define ET_WORDWRAP 16384
+#define ET_MULTILINE 8192
+#define ET_PASSWORD 4096
+#define ET_READONLY 2048
+#define ET_HASTEXTCOLOR 1024
+#define ET_HASMAXLENGTH 512
+#define ET_HASFONT 256
+#define ET_X3 128
+#define ET_X2 64
+#define ET_HASLAYOUT 32
+#define ET_NOSELECT 16
+#define ET_BORDER 8
+#define ET_X1 4
+#define ET_X0 2
+#define ET_USEOUTLINES 1
+
+SWF swf;
+int fontnum = 0;
+SWFFONT**fonts;
+
+void textcallback(int*glyphs, int nr, int fontid)
+{
+ int font=-1,t;
+ printf(" <%2d glyphs in font %2d> ",nr, fontid);
+ for(t=0;t<fontnum;t++)
+ {
+ if(fonts[t]->id == fontid) {
+ font = t;
+ break;
+ }
+ }
+
+ for(t=0;t<nr;t++)
+ {
+ unsigned char a;
+ if(font>=0) {
+ if(glyphs[t] >= fonts[font]->numchars)
+ continue;
+ a = fonts[font]->glyph2ascii[glyphs[t]];
+ } else {
+ a = glyphs[t];
+ }
+ if(a>=32)
+ printf("%c", a);
+ else
+ printf("\\x%x", (int)a);
+ }
+ printf("\n");
+}
+
+void handleText(TAG*tag)
+{
+ printf("\n");
+ swf_FontExtract_DefineTextCallback(-1,0,tag,4, textcallback);
+}
+
+void handleDefineSound(TAG*tag)
+{
+ U16 id = swf_GetU16(tag);
+ U8 flags = swf_GetU8(tag);
+ int compression = (flags>>4)&3;
+ int rate = (flags>>2)&3;
+ int bits = flags&2?16:8;
+ int stereo = flags&1;
+ printf(" (");
+ if(compression == 0) printf("Raw ");
+ else if(compression == 1) printf("ADPCM ");
+ else if(compression == 2) printf("MP3 ");
+ else printf("? ");
+ if(rate == 0) printf("5.5Khz ");
+ if(rate == 1) printf("11Khz ");
+ if(rate == 2) printf("22Khz ");
+ if(rate == 3) printf("44Khz ");
+ printf("%dBit ", bits);
+ if(stereo) printf("stereo");
+ else printf("mono");
+ printf(")");
+}
+
+void handleDefineBits(TAG*tag)
+{
+ U16 id;
+ U8 mode;
+ U16 width,height;
+ int bpp;
+ id = swf_GetU16(tag);
+ mode = swf_GetU8(tag);
+ width = swf_GetU16(tag);
+ height = swf_GetU16(tag);
+ printf(" image %dx%d",width,height);
+ if(mode == 3) printf(" (8 bpp)");
+ else if(mode == 4) printf(" (16 bpp)");
+ else if(mode == 5) printf(" (32 bpp)");
+ else printf(" (? bpp)");
+}
+
+void handleEditText(TAG*tag)
+{
+ U16 id ;
+ U16 flags;
+ int t;
+ id = swf_GetU16(tag);
+ swf_GetRect(tag,0);
+ //swf_ResetReadBits(tag);
+ if (tag->readBit)
+ { tag->pos++;
+ tag->readBit = 0;
+ }
+ flags = swf_GetBits(tag,16);
+ if(flags & ET_HASFONT) {
+ swf_GetU16(tag); //font
+ swf_GetU16(tag); //fontheight
+ }
+ if(flags & ET_HASTEXTCOLOR) {
+ swf_GetU8(tag); //rgba
+ swf_GetU8(tag);
+ swf_GetU8(tag);
+ swf_GetU8(tag);
+ }
+ if(flags & ET_HASMAXLENGTH) {
+ swf_GetU16(tag); //maxlength
+ }
+ if(flags & ET_HASLAYOUT) {
+ swf_GetU8(tag); //align
+ swf_GetU16(tag); //left margin
+ swf_GetU16(tag); //right margin
+ swf_GetU16(tag); //indent
+ swf_GetU16(tag); //leading
+ }
+ printf(" variable \"%s\"", &tag->data[tag->pos]);
+
+ if(flags & (ET_X1 | ET_X2 | ET_X3 | ET_X0))
+ {
+ printf(" undefined flags: %d%d%d%d",
+ (flags&ET_X0?1:0),
+ (flags&ET_X1?1:0),
+ (flags&ET_X2?1:0),
+ (flags&ET_X3?1:0));
+ }
+
+ while(tag->data[tag->pos++]);
+ if(flags & ET_HASTEXT)
+ // printf(" text \"%s\"\n", &tag->data[tag->pos])
+ ;
+}
+void printhandlerflags(U16 handlerflags)
+{
+ if(handlerflags&1) printf("[on load]");
+ if(handlerflags&2) printf("[enter frame]");
+ if(handlerflags&4) printf("[unload]");
+ if(handlerflags&8) printf("[mouse move]");
+ if(handlerflags&16) printf("[mouse down]");
+ if(handlerflags&32) printf("[mouse up]");
+ if(handlerflags&64) printf("[key down]");
+ if(handlerflags&128) printf("[key up]");
+ if(handlerflags&256) printf("[data]");
+ if(handlerflags&0xfe00) printf("[???]");
+}
+void handlePlaceObject2(TAG*tag, char*prefix)
+{
+ U8 flags = swf_GetU8(tag);
+ swf_GetU16(tag); //depth
+ //flags&1: move
+ if(flags&2) swf_GetU16(tag); //id
+ if(flags&4) swf_GetMatrix(tag,0);
+ if(flags&8) swf_GetCXForm(tag,0,1);
+ if(flags&16) swf_GetU16(tag); //ratio
+ if(flags&32) { while(swf_GetU8(tag)); }
+ if(flags&64) swf_GetU16(tag); //clip
+ if(flags&128) {
+ if (action) {
+ U16 unknown;
+ U32 globalflags;
+ U32 handlerflags;
+ char is32 = 0;
+ printf("\n");
+ unknown = swf_GetU16(tag);
+ globalflags = swf_GetU16(tag);
+ if(unknown) {
+ printf("Unknown parameter field not zero: %04x\n", unknown);
+ return;
+ }
+ printf("global flags: %04x\n", globalflags);
+ handlerflags = swf_GetU16(tag);
+ if(!handlerflags) {
+ handlerflags = swf_GetU32(tag);
+ is32 = 1;
+ }
+ while(handlerflags) {
+ int length;
+ int t;
+ ActionTAG*a;
+
+ globalflags &= ~handlerflags;
+ printf("%s flags %08x ",prefix, handlerflags);
+ printhandlerflags(handlerflags);
+ length = swf_GetU32(tag);
+ printf(", %d bytes actioncode\n",length);
+ a = swf_ActionGet(tag);
+ swf_DumpActions(a,prefix);
+ swf_ActionFree(a);
+
+ handlerflags = is32?swf_GetU32(tag):swf_GetU16(tag);
+ }
+ if(globalflags) // should go to sterr.
+ printf("ERROR: unsatisfied handlerflags: %02x\n", globalflags);
+ } else {
+ printf(" has action code\n");
+ }
+ } else printf("\n");
+}
+
+void fontcallback1(U16 id,U8 * name)
+{ fontnum++;
+}
+
+void fontcallback2(U16 id,U8 * name)
+{
+ swf_FontExtract(&swf,id,&fonts[fontnum]);
+ fontnum++;
+}
+
+void hexdumpTag(TAG*tag, char* prefix)
+{
+ int t;
+ printf(" %s-=> ",prefix);
+ for(t=0;t<tag->len;t++) {
+ printf("%02x ", tag->data[t]);
+ if((t && ((t&15)==15)) || (t==tag->len-1))
+ {
+ if(t==tag->len-1)
+ printf("\n");
+ else
+ printf("\n %s-=> ",prefix);
+ }
+ }
+}
+
+void dumperror(const char* format, ...)
+{
+ char buf[1024];
+ va_list arglist;
+
+ va_start(arglist, format);
+ vsprintf(buf, format, arglist);
+ va_end(arglist);
+
+ if(!html && !xy)
+ printf("==== Error: %s ====\n", buf);
+}
+