X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfaction.c;h=aa2894adc6d8e8991b152ba4059ffb6c96ad0695;hb=2bbdd7671706b7de8efa6e364f19f462bb428bb0;hp=d96dcb9792d98e92a366efae377af45878b63b45;hpb=eec072b962b440e0f795a417cc2dbc224a36657a;p=swftools.git diff --git a/lib/modules/swfaction.c b/lib/modules/swfaction.c index d96dcb9..aa2894a 100644 --- a/lib/modules/swfaction.c +++ b/lib/modules/swfaction.c @@ -128,7 +128,7 @@ r: register (byte) }; static int definedactions = sizeof(actions)/sizeof(struct Action); -ActionTAG* swf_GetActions(TAG*tag) +ActionTAG* swf_ActionGet(TAG*tag) { U8 op = 1; int length; @@ -149,10 +149,8 @@ ActionTAG* swf_GetActions(TAG*tag) length = swf_GetU16(tag); if(length) { - int t; data = malloc(length); - for(t=0;tdata && action->data != action->tmp) + free(action->data); + tmp = action; + action=action->next; + free(tmp); + } +} + +void swf_ActionSet(TAG*tag, ActionTAG*action) { while(action) { @@ -288,24 +299,27 @@ void swf_DumpActions(ActionTAG*atag, char*prefix) if(type == 0) { printf(" String:\"%s\"", value); } else if (type == 1) { - printf(" Float:\"%f\"", *(float*)value); + printf(" Float:%f", *(float*)value); } else if (type == 2) { printf(" NULL"); } else if (type == 4) { printf(" register:%d", *value); } else if (type == 5) { - printf(" %s", *value?"true":"false"); + printf(" bool:%s", *value?"true":"false"); } else if (type == 6) { - printf(" %f", *(double*)value); + printf(" float:%f", *(double*)value); } else if (type == 7) { - printf(" %d", *(int*)value); + printf(" int:%d", *(int*)value); } else if (type == 8) { printf(" Lookup:%d", *value); + } else { + printf(" UNKNOWN[%02x]",type); } } break; } data += OpAdvance(*cp, data); - if(*cp!='c' || !poollen) + if((*cp!='c' || !poollen) && + (*cp!='p' || !(data<&atag->data[atag->len]))) cp++; if(poollen) poollen--; @@ -315,14 +329,14 @@ void swf_DumpActions(ActionTAG*atag, char*prefix) { int nl = ((atag->data+atag->len)-data); int t; - printf(" remainder of %d bytes:\"", nl); + printf(" (remainder of %d bytes:\"", nl); for(t=0;tnext; @@ -473,6 +487,19 @@ void swf_AddActionTAG(U8 op, U8*data, U16 len) currentatag = currentatag->next; } +ActionMarker action_setMarker() +{ + ActionMarker m; + m.atag = currentatag; + return m; +} + +int inline ActionTagSize(ActionTAG*atag) +{ + return (atag->op&0x80)?3+(atag->len):1+0; +} + + #define ACTION_END 0x00 #define ACTION_NEXTFRAME 0x04 #define ACTION_PREVIOUSFRAME 0x05 @@ -563,6 +590,56 @@ void swf_AddActionTAG(U8 op, U8*data, U16 len) #define ACTION_CALL 0x9e #define ACTION_GOTOFRAME2 0x9f +void action_fixjump(ActionMarker m1, ActionMarker m2) +{ + ActionTAG* a1 = m1.atag; + ActionTAG* a2 = m2.atag; + ActionTAG* a; + int len = 0; + int oplen = 0; + a = a1; + while(a && a!=a2) + { + if(a != a1) //first one is for free + { + len += ActionTagSize(a); + oplen ++; + } + a = a->next; + } + if(!a) + { len = 0; + oplen = 0; + a = a2; + while(a && a!=a1) { + len -= ActionTagSize(a); + oplen --; + a = a->next; + } + if(!a) { + fprintf(stderr, "action_fixjump: couldn't find second tag\n"); + return; + } + len -= ActionTagSize(a); + oplen --; + } + + if (a1->op == ACTION_IF || a1->op == ACTION_JUMP) + { + *(U16*)(a1->data) = len; + } + else if(a1->op == ACTION_WAITFORFRAME) + { + ((U8*)(a1->data))[2] = oplen; + } + else if(a1->op == ACTION_WAITFORFRAME2) + { + ((U8*)(a1->data))[0] = oplen; + } + +} + + void action_NextFrame() {swf_AddActionTAG(ACTION_NEXTFRAME, 0, 0);} void action_PreviousFrame() {swf_AddActionTAG(ACTION_PREVIOUSFRAME, 0, 0);} void action_Play() {swf_AddActionTAG(ACTION_PLAY, 0, 0);}