X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fmodules%2Fswfaction.c;h=33964c1724ce0738b7045a8a83e8a09b035e0c0d;hb=8526dcf3a698c688e2cc4430ae106b5ecf70677f;hp=7c6fb1de57c6dd125105bc07bc593b54d46494a0;hpb=aee9de2c6eb23628e54b6896f5b441d9b39317c1;p=swftools.git diff --git a/lib/modules/swfaction.c b/lib/modules/swfaction.c index 7c6fb1d..33964c1 100644 --- a/lib/modules/swfaction.c +++ b/lib/modules/swfaction.c @@ -38,7 +38,7 @@ f: frame (word) u: url (string) t: target (string) l: label (string) -C: constant pool header (byte) +C: constant pool header (word) c: constant pool entry (string) s: skip (byte) (number of actions) m: method (byte) swf_GetUrl2:(0=none, 1=get, 2=post)/GotoFrame2:(1=play) @@ -154,9 +154,10 @@ ActionTAG* swf_ActionGet(TAG*tag) U8*data; while(op) { - action->next = (ActionTAG*)malloc(sizeof(ActionTAG)); + action->next = (ActionTAG*)rfx_calloc(sizeof(ActionTAG)); action->next->prev = action; action->next->next = 0; + action->next->parent = tmp.next; action = action->next; op = swf_GetU8(tag); @@ -166,7 +167,7 @@ ActionTAG* swf_ActionGet(TAG*tag) length = swf_GetU16(tag); if(length) { - data = malloc(length); + data = rfx_alloc(length); swf_GetBlock(tag, data, length); } else { data = 0; @@ -180,15 +181,25 @@ ActionTAG* swf_ActionGet(TAG*tag) void swf_ActionFree(ActionTAG*action) { + if(!action) { + fprintf(stderr, "Warning: freeing zero action"); + return; + } + action = action->parent; + if(!action) { + fprintf(stderr, "Warning: freeing zero action (no parent)"); + return; + } + while(action) { ActionTAG*tmp; if(action->data && action->data != action->tmp) - free(action->data); + rfx_free(action->data); tmp = action; action=action->next; - free(tmp); + rfx_free(tmp); } } @@ -239,6 +250,8 @@ int OpAdvance(char c, U8*data) return 1+4; //float } else if (type == 2) { return 1+0; //NULL + } else if (type == 3) { + return 1+0; //Undefined } else if (type == 4) { return 1+1; //register } else if (type == 5) { @@ -249,6 +262,8 @@ int OpAdvance(char c, U8*data) return 1+4; //int } else if (type == 8) { return 1+1; //lookup + } else if (type == 9) { + return 1+2; //lookup 16 } else return 1; break; } @@ -300,7 +315,7 @@ void swf_DumpActions(ActionTAG*atag, char*prefix) while(atag) { char*indent = &spaces[sizeof(spaces)-1-countpos*4]; - U8 poollen = 0; + U16 poollen = 0; for(t=0;top) break; @@ -338,7 +353,7 @@ void swf_DumpActions(ActionTAG*atag, char*prefix) #endif } break; case 'C': { - poollen = *data; + poollen = data[0]+256*data[1]; entry = 0; printf("(%d entries)", poollen); } break; @@ -359,7 +374,7 @@ void swf_DumpActions(ActionTAG*atag, char*prefix) num = (data[s++]); //num num += (data[s++])*256; for(t=0;top) break; @@ -551,7 +575,7 @@ int swf_ActionEnumerate(ActionTAG*atag, char*(*callback)(char*), int type) } } break; case 'C': { - poollen = (*data); + poollen = (data[0]+256*data[1]); } break; case 'o': { } break; @@ -578,13 +602,13 @@ int swf_ActionEnumerate(ActionTAG*atag, char*(*callback)(char*), int type) if(replacement) { int newlen = strlen(replacement); - char * newdata = malloc(atag->len - replacelen + newlen); + char * newdata = rfx_alloc(atag->len - replacelen + newlen); int rpos = replacepos - atag->data; memcpy(newdata, atag->data, rpos); memcpy(&newdata[rpos], replacement, newlen); memcpy(&newdata[rpos+newlen], &replacepos[replacelen], &data[atag->len] - &replacepos[replacelen]); - free(atag->data); + rfx_free(atag->data); atag->data = newdata; data = &atag->data[rpos+newlen+1]; } @@ -612,7 +636,7 @@ void swf_ActionEnumerateURLs(ActionTAG*atag, char*(*callback)(char*)) /*static ActionTAG* swf_ActionStart() { ActionTAG*atag; - atag = (ActionTAG*)malloc(sizeof(ActionTAG)); + atag = (ActionTAG*)rfx_alloc(sizeof(ActionTAG)); atag->prev = 0; atag->next = 0; atag->parent = 0; @@ -630,7 +654,7 @@ void swf_ActionEnd(ActionTAG* atag) } last->prev->next = 0; - free(last); + rfx_free(last); }*/ static ActionTAG*lastATAG(ActionTAG*atag) @@ -646,7 +670,7 @@ static ActionTAG*lastATAG(ActionTAG*atag) ActionTAG* swf_AddActionTAG(ActionTAG*atag, U8 op, U8*data, U16 len) { ActionTAG*tmp; - tmp = (ActionTAG*)malloc(sizeof(ActionTAG)); + tmp = (ActionTAG*)rfx_alloc(sizeof(ActionTAG)); tmp->next = 0; if(atag) { tmp->prev = atag; @@ -952,6 +976,12 @@ ActionTAG* action_PushNULL(ActionTAG*atag) *(U8*)atag->tmp = 2; //NULL return atag; } +ActionTAG* action_PushUndefined(ActionTAG*atag) +{ + atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 1); + *(U8*)atag->tmp = 3; //Undefined + return atag; +} ActionTAG* action_PushBoolean(ActionTAG*atag, char c) { atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 2); @@ -973,17 +1003,25 @@ ActionTAG* action_PushLookup(ActionTAG*atag, U8 index) *(U8*)&atag->tmp[1] = index; return atag; } +ActionTAG* action_PushLookup16(ActionTAG*atag, U16 index) +{ + atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 3); + *(U8*)atag->tmp = 9; //lookup + *(U8*)&atag->tmp[1] = index; + *(U8*)&atag->tmp[2] = index>>8; + return atag; +} ActionTAG* action_PushString(ActionTAG*atag, char*str) { int l = strlen(str); - char*ptr = (char*)malloc(l+2); + char*ptr = (char*)rfx_alloc(l+2); ptr[0] = 0; // string strcpy(&ptr[1], str); return swf_AddActionTAG(atag, ACTION_PUSH, (U8*)ptr, l+2); } ActionTAG* action_PushFloat(ActionTAG*atag, float f) { - char*ptr = (char*)malloc(5); + char*ptr = (char*)rfx_alloc(5); U32 fd = *(U32*)&f; ptr[0] = 1; //float ptr[1] = fd; @@ -994,7 +1032,7 @@ ActionTAG* action_PushFloat(ActionTAG*atag, float f) } ActionTAG* action_PushDouble(ActionTAG*atag, double d) { - char*ptr = (char*)malloc(9); + char*ptr = (char*)rfx_alloc(9); U8*dd = (U8*)&d; ptr[0] = 6; //double #ifdef WORDS_BIGENDIAN @@ -1029,7 +1067,7 @@ ActionTAG* action_GetUrl(ActionTAG*atag, char* url, char* label) { int l1= strlen(url); int l2= strlen(label); - char*ptr = malloc(l1+l2+2); + char*ptr = rfx_alloc(l1+l2+2); strcpy(ptr, url); strcpy(&ptr[l1+1], label); return swf_AddActionTAG(atag, ACTION_GETURL, ptr, l1+l2+2); @@ -1039,6 +1077,32 @@ ActionTAG* action_DefineFunction(ActionTAG*atag, U8*data, int len) {return atag; ActionTAG* action_Constantpool(ActionTAG*atag, char* constantpool) {return atag;} ActionTAG* action_With(ActionTAG*atag, char*object) {return atag;} +#include "../action/actioncompiler.h" + +ActionTAG* swf_ActionCompile(const char* source, int version) +{ + TAG* tag; + ActionTAG* a = 0; + void*buffer = 0; + int len = 0; + int ret; + + tag = swf_InsertTag(NULL, ST_DOACTION); + ret = compileSWFActionCode(source, version, &buffer, &len); + if(!ret || buffer==0 || len == 0) + return 0; + + swf_SetBlock(tag, buffer, len); + swf_SetU8(tag, 0); + + rfx_free(buffer); + + a = swf_ActionGet(tag); + swf_DeleteTag(tag); + return a; +} + + /* Properties: