3 Actionscript generation and parsing routines
5 Extension module for the rfxswf library.
6 Part of the swftools package.
8 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
24 #include "../rfxswf.h"
26 #define MAX_LOOKUP 1024 // make cross references in dumps
41 C: constant pool header (byte)
42 c: constant pool entry (string)
43 s: skip (byte) (number of actions)
44 m: method (byte) swf_GetUrl2:(0=none, 1=get, 2=post)/GotoFrame2:(1=play)
45 b: branch (word) (number of bytes)
46 p (push): type(byte), type=0:string, type=1:double
47 {: define function (name (string), num (word), params (num strings), codesize (word)
48 o: codesize (word) object (string)
52 {3,"GotoFrame", 0x81, "f"},
53 {4,"GotoFrame2", 0x9f, "m"}, // -1 (/Movieclip:3)
54 {3,"GetUrl", 0x83, "ul"},
55 {4,"GetUrl2", 0x9a, "m"}, //-2
56 {3,"NextFrame", 0x04, ""},
57 {3,"PreviousFrame", 0x05, ""},
60 {3,"ToggleQuality", 0x08, ""},
61 {3,"StopSounds", 0x09, ""},
62 {3,"WaitForFrame", 0x8a, "fs"},
63 {4,"WaitForFrame2", 0x8d, "s"}, // -1
64 {3,"SetTarget", 0x8b, "t"},
65 {4,"SetTarget2", 0x20, ""}, //-1
66 {3,"GotoLabel", 0x8c, "l"},
67 {4,"Add", 0x0a, ""}, // -2, +1
68 {4,"Multiply", 0x0c, ""}, // -2, +1
69 {4,"Divide", 0x0d, ""}, // -2, +1
70 {4,"Subtract", 0x0b, ""}, // -2, +1
71 {4,"Less", 0x0f, ""}, // -2, +1
72 {4,"Equals", 0x0e, ""}, // -2, +1
73 {4,"And", 0x10, ""}, // -2, +1
74 {4,"Or", 0x11, ""}, // -2, +1
75 {4,"Not", 0x12, ""}, // -1, +1
76 {4,"StringAdd", 0x21, ""}, // -2,+1
77 {4,"StringLength", 0x14, ""}, // -1, +1
78 {4,"MBStringLength", 0x31, ""}, // -1, +1
79 {4,"StringEquals", 0x13, ""}, // -2, +1
80 {4,"StringLess", 0x29, ""}, //-2, +1
81 {4,"StringExtract", 0x15, ""}, // -3, +1
82 {4,"MBStringExtract", 0x35, ""}, //-3 +1
83 {4,"Push", 0x96, "p"}, // +1
84 {4,"Pop", 0x17, ""}, // -1
85 {4,"ToInteger", 0x18, ""}, // -1, +1
86 {4,"CharToAscii", 0x32, ""}, // -1, +1
87 {4,"AsciiToChar", 0x33, ""}, // -1, +1
88 {4,"MBCharToAscii", 0x36, ""}, // -1, +1
89 {4,"MBAsciiToChar", 0x37, ""}, // -1, +1
90 {4,"Jump", 0x99, "b"},
91 {4,"If", 0x9d, "b"}, // -1
92 {4,"Call", 0x9e, ""}, //-1 (frame label/number) (high bit is wrong.)
93 {4,"GetVariable", 0x1c,""}, // -1, +1
94 {4,"SetVariable", 0x1d,""}, // -2
95 {4,"GetProperty", 0x22,""}, //-2, +1
96 {4,"SetProperty", 0x23, ""}, // -3
97 {4,"RemoveSprite", 0x25, ""}, //-1
98 {4,"StartDrag", 0x27, ""}, // -2, -1, (-4)
99 {4,"EndDrag", 0x28, ""},
100 {4,"CloneSprite", 0x24, ""}, // -3
101 {4,"Trace", 0x26, ""}, //-1
102 {4,"GetTime", 0x34, ""}, //+1
103 {4,"RandomNumber", 0x30, ""}, //-1,+1
104 {5,"Modulo", 0x3f,""},
105 {5,"BitAnd", 0x60,""},
106 {5,"BitLShift", 0x63,""},
107 {5,"BitOr", 0x61,""},
108 {5,"BitRShift", 0x64,""},
109 {5,"BitURShift", 0x65,""},
110 {5,"BitXor", 0x62,""},//66?
111 {5,"Decrement", 0x51,""},
112 {5,"Increment", 0x50,""},
113 {5,"PushDuplicate", 0x4c,""},
114 {5,"StackSwap", 0x4d,""}, //?
115 {5,"StoreRegister", 0x87,"r"},
116 {5,"CallFunction", 0x3d,""},
117 {5,"DefineFunction", 0x9b, "{"},
118 {5,"Return", 0x3e,""},
119 {5,"GetMember", 0x4e,""},
120 {5,"SetMember", 0x4f,""},
121 {5,"CallMethod", 0x52,""},
122 {5,"Constantpool", 0x88, "Cc"},
123 {5,"DefineLocal", 0x3c,""},
124 {5,"DefineLocal2", 0x41,""},
125 {5,"Makehash", 0x43, ""}, //??
126 {5,"Delete", 0x3a,""}, //?
127 {5,"Delete2", 0x3b,""},
128 {5,"Enumerate", 0x46,""},
129 {5,"Equals2", 0x49,""},
130 {5,"InitArray", 0x42,""}, // InitObject?
131 {5,"NewMethod", 0x53,""}, //?
132 {5,"NewObject", 0x40,""},
133 {5,"TargetPath", 0x45,""}, //?
134 {5,"With", 0x94, "o"},
135 {5,"ToNumber", 0x4a,""}, //?
136 {5,"ToString", 0x4b,""}, //?
137 {5,"TypeOf", 0x44,""},
139 {5,"Less2", 0x48,""},
140 {6,"Greater", 0x67,""},
141 {6,"StringGreater", 0x68,""},
142 {6,"Enumerate2", 0x55,""},
143 {6,"InstanceOf", 0x54,""},
144 {6,"StrictEquals", 0x66,""}
146 static int definedactions = sizeof(actions)/sizeof(struct Action);
148 ActionTAG* swf_ActionGet(TAG*tag)
153 ActionTAG*action = &tmp;
157 action->next = (ActionTAG*)malloc(sizeof(ActionTAG));
158 memset(action->next, 0, sizeof(ActionTAG));
159 action->next->prev = action;
160 action->next->next = 0;
161 action->next->parent = tmp.next;
162 action = action->next;
168 length = swf_GetU16(tag);
171 data = malloc(length);
172 swf_GetBlock(tag, data, length);
177 action->len = length;
183 void swf_ActionFree(ActionTAG*action)
186 fprintf(stderr, "Warning: freeing zero action");
189 action = action->parent;
191 fprintf(stderr, "Warning: freeing zero action (no parent)");
198 if(action->data && action->data != action->tmp)
207 void swf_ActionSet(TAG*tag, ActionTAG*action)
209 action=action->parent;
212 swf_SetU8(tag, action->op);
214 swf_SetU16(tag, action->len);
216 swf_SetBlock(tag, action->data, action->len);
218 action = action->next;
222 int OpAdvance(char c, U8*data)
229 return strlen(data)+1;
231 return strlen(data)+1;
233 return strlen(data)+1;
235 return strlen(data)+1;
249 return 1+strlen(data)+1; //string
250 } else if (type == 1) {
252 } else if (type == 2) {
254 } else if (type == 4) {
255 return 1+1; //register
256 } else if (type == 5) {
258 } else if (type == 6) {
260 } else if (type == 7) {
262 } else if (type == 8) {
275 while(*data++); //name
276 num = (*data++)*256; //num
279 while(*data++); //param
280 codesize = (*data++)*256; //num
281 codesize += (*data++);
287 #define ATAG_FULLLENGTH(atag) ((atag)->len + 1 + ((atag)->op&0x80?2:0))
288 #define MAX_LEVELS 16
289 /* TODO: * this should be in swfdump.c */
290 void swf_DumpActions(ActionTAG*atag, char*prefix)
296 char spaces[MAX_LEVELS*4+1];
300 } counter[MAX_LEVELS];
303 char * lookup[MAX_LOOKUP];
304 memset(lookup,0x00,sizeof(lookup));
306 memset(spaces, 32, sizeof(spaces));
307 spaces[sizeof(spaces)-1] = 0;
314 char*indent = &spaces[sizeof(spaces)-1-countpos*4];
316 for(t=0;t<definedactions;t++)
317 if(actions[t].op == atag->op)
320 if(t==definedactions) {
321 printf("%s (%5d bytes) action:%s unknown[%02x]", prefix, atag->len, indent, atag->op);
323 printf("%s (%5d bytes) action:%s %s", prefix, atag->len, indent, actions[t].name);
326 if(atag->len && t!=definedactions) //TODO: check for consistency: should we have a length?
328 cp = actions[t].flags;
334 printf(" %d", data[0]+256*data[1]);
337 printf(" URL:\"%s\"", data);
340 printf(" Target:\"%s\"", data);
343 printf(" Label:\"%s\"", data);
346 printf(" String:\"%s\"", data);
348 if (entry<MAX_LOOKUP)
349 lookup[entry++] = strdup(data);
355 printf("(%d entries)", poollen);
358 printf(" +%d", *data);
361 //m: method (byte) url:(0=none, 1=get, 2=datat)/gf2:(1=play)
362 printf(" %d", *data);
369 printf(" %s(", data);
370 while(data[s++]); //name
371 num = (data[s++]); //num
372 num += (data[s++])*256;
377 while(data[s++]); //param
380 codesize = (data[s++]); //num
381 codesize += (data[s++])*256;
382 printf(" codesize:%d ",codesize);
383 printf("\n%s %s{", prefix, indent);
385 printf("Error: nested too deep\n");
388 counter[countpos].text = "}";
389 counter[countpos].count = codesize + ATAG_FULLLENGTH(atag);
394 U16 codesize = data[0]+256*data[1];
395 printf(" codesize:%d ", codesize);
397 /* the following tries to find the "string"
398 the flash documentation speaks of- I've
399 never actually seen one yet. -mk */
400 for(t=2;t<atag->len;t++)
401 printf("[%02x]", atag->data[t]);
403 printf("\n%s %s{", prefix, indent);
405 printf("Error: nested too deep\n");
408 counter[countpos].text = "}";
409 counter[countpos].count = codesize + ATAG_FULLLENGTH(atag);
413 printf(" %d", data[0]+256*(signed char)data[1]);
416 printf(" %d", data[0]);
420 unsigned char*value = data+1;
422 printf(" String:\"%s\"", value);
423 } else if (type == 1) {
424 U32 f = value[0]+(value[1]<<8)+
425 (value[2]<<16)+(value[3]<<24);
426 printf(" Float:%f", *(float*)&f);
427 } else if (type == 2) {
429 } else if (type == 4) {
430 printf(" register:%d", *value);
431 } else if (type == 5) {
432 printf(" bool:%s", *value?"true":"false");
433 } else if (type == 6) {
436 memcpy(&a[4],value,4);
437 memcpy(a,&value[4],4);
438 #ifdef WORDS_BIGENDIAN
445 printf(" double:%f", *(double*)a);
446 } else if (type == 7) {
447 printf(" int:%d", value[0]+(value[1]<<8)+
448 (value[2]<<16)+(value[3]<<24));
449 } else if (type == 8) {
450 printf(" Lookup:%d", *value);
453 printf(" (\"%s\")",lookup[*value]);
456 printf(" UNKNOWN[%02x]",type);
460 data += OpAdvance(*cp, data);
461 if((*cp!='c' || !poollen) &&
462 (*cp!='p' || !(data<&atag->data[atag->len])))
469 if(data < atag->data + atag->len)
471 int nl = ((atag->data+atag->len)-data);
473 printf(" (remainder of %d bytes:\"", nl);
476 printf("\\%d",data[t]);
478 printf("%c", data[t]);
484 for(t=0;t<countpos;t++) {
485 counter[t].count -= ATAG_FULLLENGTH(atag);
486 if(counter[t].count < 0) {
487 printf("===== Error: Oplength errors =====\n");
493 while(countpos && !counter[countpos-1].count)
496 prefix, indent, counter[countpos-1].text);
505 for (t=0;t<MAX_LOOKUP;t++) if (lookup[t]) free(lookup[t]);
509 static const char TYPE_URL = 1;
510 static const char TYPE_TARGET = 2;
511 static const char TYPE_STRING = 4;
513 int swf_ActionEnumerate(ActionTAG*atag, char*(*callback)(char*), int type)
522 for(t=0;t<definedactions;t++)
523 if(actions[t].op == atag->op)
526 if(t==definedactions) {
532 cp = actions[t].flags;
538 U8 * replacement = 0;
544 replacelen = strlen(data);
546 replacement = callback(data); // may be null
552 replacelen = strlen(data);
554 replacement = callback(data); // may be null
560 replacelen = strlen(data);
562 replacement = callback(data); // may be null
572 char*value = &data[1];
573 if(datatype == 0) { //string
576 replacelen = strlen(value);
578 replacement = callback(value); // may be null
580 } else if (datatype == 8) { //lookup
584 data += OpAdvance(*cp, data);
585 if(*cp!='c' || !poollen)
592 int newlen = strlen(replacement);
593 char * newdata = malloc(atag->len - replacelen + newlen);
594 int rpos = replacepos - atag->data;
595 memcpy(newdata, atag->data, rpos);
596 memcpy(&newdata[rpos], replacement, newlen);
597 memcpy(&newdata[rpos+newlen], &replacepos[replacelen],
598 &data[atag->len] - &replacepos[replacelen]);
600 atag->data = newdata;
601 data = &atag->data[rpos+newlen+1];
611 void swf_ActionEnumerateTargets(ActionTAG*atag, char*(*callback)(char*))
613 swf_ActionEnumerate(atag, callback, TYPE_TARGET);
615 void swf_ActionEnumerateStrings(ActionTAG*atag, char*(*callback)(char*))
617 swf_ActionEnumerate(atag, callback, TYPE_STRING);
619 void swf_ActionEnumerateURLs(ActionTAG*atag, char*(*callback)(char*))
621 swf_ActionEnumerate(atag, callback, TYPE_URL);
624 /*static ActionTAG* swf_ActionStart()
627 atag = (ActionTAG*)malloc(sizeof(ActionTAG));
636 void swf_ActionEnd(ActionTAG* atag)
644 last->prev->next = 0;
648 static ActionTAG*lastATAG(ActionTAG*atag)
658 ActionTAG* swf_AddActionTAG(ActionTAG*atag, U8 op, U8*data, U16 len)
661 tmp = (ActionTAG*)malloc(sizeof(ActionTAG));
666 tmp->parent = atag->parent;
674 tmp->data = tmp->tmp;
681 ActionMarker action_setMarker(ActionTAG*atag)
688 int inline ActionTagSize(ActionTAG*atag)
690 return (atag->op&0x80)?3+(atag->len):1+0;
694 #define ACTION_END 0x00
695 #define ACTION_NEXTFRAME 0x04
696 #define ACTION_PREVIOUSFRAME 0x05
697 #define ACTION_PLAY 0x06
698 #define ACTION_STOP 0x07
699 #define ACTION_TOGGLEQUALITY 0x08
700 #define ACTION_STOPSOUNDS 0x09
701 #define ACTION_ADD 0x0a
702 #define ACTION_SUBTRACT 0x0b
703 #define ACTION_MULTIPLY 0x0c
704 #define ACTION_DIVIDE 0x0d
705 #define ACTION_EQUALS 0x0e
706 #define ACTION_LESS 0x0f
707 #define ACTION_AND 0x10
708 #define ACTION_OR 0x11
709 #define ACTION_NOT 0x12
710 #define ACTION_STRINGEQUALS 0x13
711 #define ACTION_STRINGLENGTH 0x14
712 #define ACTION_STRINGEXTRACT 0x15
713 #define ACTION_POP 0x17
714 #define ACTION_TOINTEGER 0x18
715 #define ACTION_GETVARIABLE 0x1c
716 #define ACTION_SETVARIABLE 0x1d
717 #define ACTION_SETTARGET2 0x20
718 #define ACTION_STRINGADD 0x21
719 #define ACTION_GETPROPERTY 0x22
720 #define ACTION_SETPROPERTY 0x23
721 #define ACTION_CLONESPRITE 0x24
722 #define ACTION_REMOVESPRITE 0x25
723 #define ACTION_TRACE 0x26
724 #define ACTION_STARTDRAG 0x27
725 #define ACTION_ENDDRAG 0x28
726 #define ACTION_STRINGLESS 0x29
727 #define ACTION_RANDOMNUMBER 0x30
728 #define ACTION_MBSTRINGLENGTH 0x31
729 #define ACTION_CHARTOASCII 0x32
730 #define ACTION_ASCIITOCHAR 0x33
731 #define ACTION_GETTIME 0x34
732 #define ACTION_MBSTRINGEXTRACT 0x35
733 #define ACTION_MBCHARTOASCII 0x36
734 #define ACTION_MBASCIITOCHAR 0x37
735 #define ACTION_DELETE 0x3a
736 #define ACTION_DELETE2 0x3b
737 #define ACTION_DEFINELOCAL 0x3c
738 #define ACTION_CALLFUNCTION 0x3d
739 #define ACTION_RETURN 0x3e
740 #define ACTION_MODULO 0x3f
741 #define ACTION_NEWOBJECT 0x40
742 #define ACTION_DEFINELOCAL2 0x41
743 #define ACTION_INITARRAY 0x42
744 #define ACTION_MAKEHASH 0x43
745 #define ACTION_TYPEOF 0x44
746 #define ACTION_TARGETPATH 0x45
747 #define ACTION_ENUMERATE 0x46
748 #define ACTION_ADD2 0x47
749 #define ACTION_LESS2 0x48
750 #define ACTION_EQUALS2 0x49
751 #define ACTION_TONUMBER 0x4a
752 #define ACTION_TOSTRING 0x4b
753 #define ACTION_PUSHDUPLICATE 0x4c
754 #define ACTION_STACKSWAP 0x4d
755 #define ACTION_GETMEMBER 0x4e
756 #define ACTION_SETMEMBER 0x4f
757 #define ACTION_INCREMENT 0x50
758 #define ACTION_DECREMENT 0x51
759 #define ACTION_CALLMETHOD 0x52
760 #define ACTION_NEWMETHOD 0x53
761 #define ACTION_BITAND 0x60
762 #define ACTION_BITOR 0x61
763 #define ACTION_BITXOR 0x62
764 #define ACTION_BITLSHIFT 0x63
765 #define ACTION_BITRSHIFT 0x64
766 #define ACTION_BITURSHIFT 0x65
767 #define ACTION_GOTOFRAME 0x81
768 #define ACTION_GETURL 0x83
769 #define ACTION_STOREREGISTER 0x87
770 #define ACTION_CONSTANTPOOL 0x88
771 #define ACTION_WAITFORFRAME 0x8a
772 #define ACTION_SETTARGET 0x8b
773 #define ACTION_GOTOLABEL 0x8c
774 #define ACTION_WAITFORFRAME2 0x8d
775 #define ACTION_WITH 0x94
776 #define ACTION_PUSH 0x96
777 #define ACTION_JUMP 0x99
778 #define ACTION_GETURL2 0x9a
779 #define ACTION_DEFINEFUNCTION 0x9b
780 #define ACTION_IF 0x9d
781 #define ACTION_CALL 0x9e
782 #define ACTION_GOTOFRAME2 0x9f
784 void action_fixjump(ActionMarker m1, ActionMarker m2)
786 ActionTAG* a1 = m1.atag;
787 ActionTAG* a2 = m2.atag;
793 a = a->next; //first one is free
796 len += ActionTagSize(a);
805 len -= ActionTagSize(a);
810 fprintf(stderr, "action_fixjump: couldn't find second tag\n");
813 len -= ActionTagSize(a);
817 if (a1->op == ACTION_IF || a1->op == ACTION_JUMP)
819 *(U16*)(a1->data) = SWAP16(len);
821 else if(a1->op == ACTION_WAITFORFRAME)
823 ((U8*)(a1->data))[2] = oplen;
825 else if(a1->op == ACTION_WAITFORFRAME2)
827 ((U8*)(a1->data))[0] = oplen;
832 ActionTAG* action_NextFrame(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_NEXTFRAME, 0, 0);}
833 ActionTAG* action_PreviousFrame(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_PREVIOUSFRAME, 0, 0);}
834 ActionTAG* action_Play(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_PLAY, 0, 0);}
835 ActionTAG* action_Stop(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STOP, 0, 0);}
836 ActionTAG* action_ToggleQuality(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TOGGLEQUALITY, 0, 0);}
837 ActionTAG* action_StopSounds(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STOPSOUNDS, 0, 0);}
838 ActionTAG* action_Add(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ADD, 0, 0);}
839 ActionTAG* action_Subtract(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SUBTRACT, 0, 0);}
840 ActionTAG* action_Multiply(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MULTIPLY, 0, 0);}
841 ActionTAG* action_Divide(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DIVIDE, 0, 0);}
842 ActionTAG* action_Equals(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_EQUALS, 0, 0);}
843 ActionTAG* action_Less(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_LESS, 0, 0);}
844 ActionTAG* action_And(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_AND, 0, 0);}
845 ActionTAG* action_Or(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_OR, 0, 0);}
846 ActionTAG* action_Not(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_NOT, 0, 0);}
847 ActionTAG* action_StringEquals(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGEQUALS, 0, 0);}
848 ActionTAG* action_StringLength(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGLENGTH, 0, 0);}
849 ActionTAG* action_StringExtract(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGEXTRACT, 0, 0);}
850 ActionTAG* action_Pop(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_POP, 0, 0);}
851 ActionTAG* action_ToInteger(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TOINTEGER, 0, 0);}
852 ActionTAG* action_GetVariable(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_GETVARIABLE, 0, 0);}
853 ActionTAG* action_SetVariable(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SETVARIABLE, 0, 0);}
854 ActionTAG* action_SetTarget2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SETTARGET2, 0, 0);}
855 ActionTAG* action_StringAdd(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGADD, 0, 0);}
856 ActionTAG* action_GetProperty(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_GETPROPERTY, 0, 0);}
857 ActionTAG* action_SetProperty(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SETPROPERTY, 0, 0);}
858 ActionTAG* action_CloneSprite(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CLONESPRITE, 0, 0);}
859 ActionTAG* action_RemoveSprite(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_REMOVESPRITE, 0, 0);}
860 ActionTAG* action_Trace(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TRACE, 0, 0);}
861 ActionTAG* action_StartDrag(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STARTDRAG, 0, 0);}
862 ActionTAG* action_EndDrag(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ENDDRAG, 0, 0);}
863 ActionTAG* action_StringLess(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STRINGLESS, 0, 0);}
864 ActionTAG* action_RandomNumber(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_RANDOMNUMBER, 0, 0);}
865 ActionTAG* action_MBStringLength(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MBSTRINGLENGTH, 0, 0);}
866 ActionTAG* action_CharToAscii(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CHARTOASCII, 0, 0);}
867 ActionTAG* action_AsciiToChar(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ASCIITOCHAR, 0, 0);}
868 ActionTAG* action_GetTime(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_GETTIME, 0, 0);}
869 ActionTAG* action_MBStringExtract(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MBSTRINGEXTRACT, 0, 0);}
870 ActionTAG* action_MBCharToAscii(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MBCHARTOASCII, 0, 0);}
871 ActionTAG* action_MBAsciiToChar(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MBASCIITOCHAR, 0, 0);}
872 ActionTAG* action_Delete(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DELETE, 0, 0);}
873 ActionTAG* action_Delete2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DELETE2, 0, 0);}
874 ActionTAG* action_DefineLocal(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DEFINELOCAL, 0, 0);}
875 ActionTAG* action_CallFunction(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CALLFUNCTION, 0, 0);}
876 ActionTAG* action_Return(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_RETURN, 0, 0);}
877 ActionTAG* action_Modulo(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MODULO, 0, 0);}
878 ActionTAG* action_NewObject(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_NEWOBJECT, 0, 0);}
879 ActionTAG* action_DefineLocal2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DEFINELOCAL2, 0, 0);}
880 ActionTAG* action_InitArray(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_INITARRAY, 0, 0);}
881 ActionTAG* action_Makehash(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_MAKEHASH, 0, 0);}
882 ActionTAG* action_TypeOf(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TYPEOF, 0, 0);}
883 ActionTAG* action_TargetPath(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TARGETPATH, 0, 0);}
884 ActionTAG* action_Enumerate(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ENUMERATE, 0, 0);}
885 ActionTAG* action_Add2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_ADD2, 0, 0);}
886 ActionTAG* action_Less2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_LESS2, 0, 0);}
887 ActionTAG* action_Equals2(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_EQUALS2, 0, 0);}
888 ActionTAG* action_ToNumber(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TONUMBER, 0, 0);}
889 ActionTAG* action_ToString(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_TOSTRING, 0, 0);}
890 ActionTAG* action_PushDuplicate(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_PUSHDUPLICATE, 0, 0);}
891 ActionTAG* action_StackSwap(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_STACKSWAP, 0, 0);}
892 ActionTAG* action_GetMember(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_GETMEMBER, 0, 0);}
893 ActionTAG* action_SetMember(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_SETMEMBER, 0, 0);}
894 ActionTAG* action_Increment(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_INCREMENT, 0, 0);}
895 ActionTAG* action_Decrement(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_DECREMENT, 0, 0);}
896 ActionTAG* action_CallMethod(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CALLMETHOD, 0, 0);}
897 ActionTAG* action_NewMethod(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_NEWMETHOD, 0, 0);}
898 ActionTAG* action_BitAnd(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITAND, 0, 0);}
899 ActionTAG* action_BitOr(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITOR, 0, 0);}
900 ActionTAG* action_BitXor(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITXOR, 0, 0);}
901 ActionTAG* action_BitLShift(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITLSHIFT, 0, 0);}
902 ActionTAG* action_BitRShift(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITRSHIFT, 0, 0);}
903 ActionTAG* action_BitURShift(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_BITURSHIFT, 0, 0);}
904 ActionTAG* action_Call(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_CALL, 0, 0);}
905 ActionTAG* action_End(ActionTAG*atag) {return swf_AddActionTAG(atag, ACTION_END, 0, 0);}
906 ActionTAG* action_GotoFrame(ActionTAG*atag, U16 frame)
908 atag = swf_AddActionTAG(atag, ACTION_GOTOFRAME, 0, 2);
909 *(U16*)atag->tmp = SWAP16(frame);
913 ActionTAG* action_Jump(ActionTAG*atag, U16 branch)
915 atag = swf_AddActionTAG(atag, ACTION_JUMP, 0, 2);
916 *(U16*)atag->tmp = SWAP16(branch);
919 ActionTAG* action_If(ActionTAG*atag, U16 branch)
921 atag = swf_AddActionTAG(atag, ACTION_IF, 0, 2);
922 *(U16*)atag->tmp = SWAP16(branch);
925 ActionTAG* action_StoreRegister(ActionTAG*atag, U8 reg)
927 atag = swf_AddActionTAG(atag, ACTION_STOREREGISTER, 0, 1);
928 *(U8*)atag->tmp = reg;
931 ActionTAG* action_GotoFrame2(ActionTAG*atag, U8 method)
933 atag = swf_AddActionTAG(atag, ACTION_GOTOFRAME2, 0, 1);
934 *(U8*)atag->tmp = method;
937 ActionTAG* action_GetUrl2(ActionTAG*atag, U8 method)
939 atag = swf_AddActionTAG(atag, ACTION_GETURL2, 0, 1);
940 *(U8*)atag->tmp = method;
943 ActionTAG* action_WaitForFrame2(ActionTAG*atag, U8 skip)
945 atag = swf_AddActionTAG(atag, ACTION_WAITFORFRAME2, 0, 1);
946 *(U8*)atag->tmp = skip;
949 ActionTAG* action_WaitForFrame(ActionTAG*atag, U16 frame, U8 skip)
951 atag = swf_AddActionTAG(atag, ACTION_WAITFORFRAME, 0, 3);
952 *(U16*)atag->tmp = SWAP16(frame);
953 *(U8*)&atag->tmp[2] = skip;
956 ActionTAG* action_SetTarget(ActionTAG*atag, char* target)
958 char*ptr = strdup(target);
959 return swf_AddActionTAG(atag, ACTION_SETTARGET, (U8*)ptr, strlen(ptr)+1);
961 ActionTAG* action_PushNULL(ActionTAG*atag)
963 atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 1);
964 *(U8*)atag->tmp = 2; //NULL
967 ActionTAG* action_PushBoolean(ActionTAG*atag, char c)
969 atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 2);
970 *(U8*)atag->tmp = 5; //bool
971 *(U8*)&atag->tmp[1] = c;
974 ActionTAG* action_PushRegister(ActionTAG*atag, U8 reg)
976 atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 2);
977 *(U8*)atag->tmp = 4; //register
978 *(U8*)&atag->tmp[1] = reg;
981 ActionTAG* action_PushLookup(ActionTAG*atag, U8 index)
983 atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 2);
984 *(U8*)atag->tmp = 8; //lookup
985 *(U8*)&atag->tmp[1] = index;
988 ActionTAG* action_PushString(ActionTAG*atag, char*str)
991 char*ptr = (char*)malloc(l+2);
992 ptr[0] = 0; // string
993 strcpy(&ptr[1], str);
994 return swf_AddActionTAG(atag, ACTION_PUSH, (U8*)ptr, l+2);
996 ActionTAG* action_PushFloat(ActionTAG*atag, float f)
998 char*ptr = (char*)malloc(5);
1005 return swf_AddActionTAG(atag, ACTION_PUSH, (U8*)ptr, 5);
1007 ActionTAG* action_PushDouble(ActionTAG*atag, double d)
1009 char*ptr = (char*)malloc(9);
1011 ptr[0] = 6; //double
1012 #ifdef WORDS_BIGENDIAN
1013 ptr[1] = dd[7];ptr[2] = dd[6];
1014 ptr[3] = dd[5];ptr[4] = dd[4];
1015 ptr[5] = dd[3];ptr[6] = dd[2];
1016 ptr[7] = dd[1];ptr[8] = dd[0];
1018 ptr[1] = dd[0];ptr[2] = dd[1];
1019 ptr[3] = dd[2];ptr[4] = dd[3];
1020 ptr[5] = dd[4];ptr[6] = dd[5];
1021 ptr[7] = dd[6];ptr[8] = dd[7];
1023 return swf_AddActionTAG(atag, ACTION_PUSH, (U8*)ptr, 9);
1025 ActionTAG* action_PushInt(ActionTAG*atag, int i)
1027 atag = swf_AddActionTAG(atag, ACTION_PUSH, 0, 5);
1028 *(U8*)atag->tmp = 7; //int
1030 atag->tmp[2] = i>>8;
1031 atag->tmp[3] = i>>16;
1032 atag->tmp[4] = i>>24;
1035 ActionTAG* action_GotoLabel(ActionTAG*atag, char* label)
1037 char*ptr = strdup(label);
1038 return swf_AddActionTAG(atag, ACTION_GOTOLABEL, (U8*)ptr, strlen(ptr));
1040 ActionTAG* action_GetUrl(ActionTAG*atag, char* url, char* label)
1042 int l1= strlen(url);
1043 int l2= strlen(label);
1044 char*ptr = malloc(l1+l2+2);
1046 strcpy(&ptr[l1+1], label);
1047 return swf_AddActionTAG(atag, ACTION_GETURL, ptr, l1+l2+2);
1050 ActionTAG* action_DefineFunction(ActionTAG*atag, U8*data, int len) {return atag;}
1051 ActionTAG* action_Constantpool(ActionTAG*atag, char* constantpool) {return atag;}
1052 ActionTAG* action_With(ActionTAG*atag, char*object) {return atag;}
1054 #include "../action/actioncompiler.h"
1056 ActionTAG* swf_ActionCompile(const char* source, int version)
1064 tag = swf_InsertTag(NULL, ST_DOACTION);
1065 ret = compileSWFActionCode(source, version, &buffer, &len);
1066 if(!ret || buffer==0 || len == 0)
1069 swf_SetBlock(tag, buffer, len);
1074 a = swf_ActionGet(tag);