Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2021
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 116.45 KB | None | 0 0
  1. /*
  2. flasm, command line assembler & disassembler of flash actionscript bytecode
  3. Copyright (c) 2001 Opaque Industries, (c) 2002-2003 Igor Kogan
  4. All rights reserved. See LICENSE.TXT for terms of use.
  5. */
  6.  
  7. %{
  8.  
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <math.h>
  12. #include "util.h"
  13. #include "flasm.h"
  14.  
  15. void yyerror(const char *s);
  16. void warning(char *msg);
  17. int yylex(void);
  18.  
  19. extern char *yytext;
  20. extern long int len;
  21. extern unsigned int nConstants;
  22. extern int mode;
  23. extern char compressAfter;
  24. extern int numActions;
  25. extern int clearregisterargs;
  26. extern char *arNames[];
  27. extern unsigned int arFlags[];
  28. extern unsigned int arNotFlags[];
  29.  
  30. static char *func_args[MAX_FUNCARGS];
  31. static char *regfunc_args[MAX_FUNCDEPTH][MAX_REGISTERS];
  32. static unsigned int numRegisters[MAX_FUNCDEPTH];
  33. static int curFunc = -1;
  34. static unsigned int numAssets;
  35. static unsigned long int curEvent, allEvents;
  36. static int frameloadedStart = -1;
  37. static unsigned int numArgs;
  38. static unsigned int autoregFlags;
  39. %}
  40.  
  41. %glr-parser
  42. %debug
  43. %union
  44. {
  45. long int num;
  46. char *str;
  47. }
  48.  
  49. %expect 33 /* double nots shift/reduce warning */
  50. %expect-rr 145
  51.  
  52. %token <str> MOVIENAME
  53. %token <str> STRING
  54. %token <num> INTEGER
  55. %token <str> HEX
  56. %token <str> FLOAT
  57. %token <str> DOUBLE
  58. %token <str> TRUEVAL
  59. %token <str> FALSEVAL
  60. %token <str> NULLVAL
  61. %token <str> UNDEFVAL
  62. %token <num> REGISTER
  63. %token <str> REGISTERALIAS
  64. %token <str> LABEL
  65.  
  66. %token MOVIE
  67. %token COMPRESSED
  68. %token PROTECT
  69. %token SCRIPTLIMITS
  70. %token RECURSION
  71. %token TIMEOUT
  72. %token ENABLEDEBUGGER
  73. %token ENABLEDEBUGGER2
  74. %token FRAME
  75. %token PLACEMOVIECLIP
  76. %token DEFINEMOVIECLIP
  77. %token INITMOVIECLIP
  78. %token DEFINEBUTTON
  79. %token ON
  80. %token ONCLIPEVENT
  81. %token AS
  82. %token IMPORTASSETS
  83. %token EXPORTASSETS
  84. %token FROM
  85.  
  86. // special double values
  87. %token _NAN
  88. %token POSITIVE_INFINITY
  89. %token NEGATIVE_INFINITY
  90.  
  91. // special float values - push type 1
  92. %token _NANF
  93. %token POSITIVE_INFINITYF
  94. %token NEGATIVE_INFINITYF
  95.  
  96. // button events
  97. %token BIDLETOOVERUP
  98. %token BOVERUPTOIDLE
  99. %token BOVERUPTOOVERDOWN
  100. %token BOVERDOWNTOOVERUP
  101. %token BOVERDOWNTOOUTDOWN
  102. %token BOUTDOWNTOOVERDOWN
  103. %token BOUTDOWNTOIDLE
  104. %token BIDLETOOVERDOWN
  105. %token BOVERDOWNTOIDLE
  106.  
  107. %token KEYPRESS
  108.  
  109. // keyPress pre-defined
  110. %token _LEFT
  111. %token _RIGHT
  112. %token _HOME
  113. %token _END
  114. %token _INSERT
  115. %token _DELETE
  116. %token _BACKSPACE
  117. %token _ENTER
  118. %token _UP
  119. %token _DOWN
  120. %token _PGUP
  121. %token _PGDN
  122. %token _TAB
  123. %token _ESCAPE
  124. %token _SPACE
  125.  
  126. // onClipEvents
  127. %token MCLOAD
  128. %token MCENTERFRAME
  129. %token MCUNLOAD
  130. %token MCMOUSEMOVE
  131. %token MCMOUSEDOWN
  132. %token MCMOUSEUP
  133. %token MCKEYDOWN
  134. %token MCKEYUP
  135. %token MCINITIALIZE
  136. %token MCCONSTRUCT
  137. %token MCDATA
  138. %token MCPRESS
  139. %token MCRELEASE
  140. %token MCRELEASEOUTSIDE
  141. %token MCROLLOVER
  142. %token MCROLLOUT
  143. %token MCDRAGOVER
  144. %token MCDRAGOUT
  145.  
  146. // old-style properties
  147. %token X_PROPERTY
  148. %token Y_PROPERTY
  149. %token XSCALE_PROPERTY
  150. %token YSCALE_PROPERTY
  151. %token WIDTH_PROPERTY
  152. %token HEIGHT_PROPERTY
  153. %token ALPHA_PROPERTY
  154. %token VISIBLE_PROPERTY
  155. %token ROTATION_PROPERTY
  156. %token CURRENTFRAME_PROPERTY
  157. %token TOTALFRAMES_PROPERTY
  158. %token TARGET_PROPERTY
  159. %token FRAMESLOADED_PROPERTY
  160. %token NAME_PROPERTY
  161. %token DROPTARGET_PROPERTY
  162. %token URL_PROPERTY
  163. %token QUALITY_PROPERTY
  164. %token XMOUSE_PROPERTY
  165. %token YMOUSE_PROPERTY
  166. %token HIGHQUALITY_PROPERTY
  167. %token FOCUSRECT_PROPERTY
  168. %token SOUNDBUFTIME_PROPERTY
  169.  
  170. %token NEXTFRAME
  171. %token PREVFRAME
  172. %token GOTOFRAME
  173. %token GOTOLABEL
  174. %token PLAY
  175. %token STOP
  176. %token TOGGLEQUALITY
  177. %token STOPSOUNDS
  178. %token FUNCTION
  179. %token FUNCTION2
  180. %token CONSTANTS
  181. %token END
  182. %token DUP
  183. %token SWAP
  184. %token POP
  185. %token WITH
  186. %token PUSH
  187. %token SETREGISTER
  188. %token CALLFUNCTION
  189. %token RETURN
  190. %token NEWMETHOD
  191. %token CALLMETHOD
  192. %token BITWISEAND
  193. %token BITWISEOR
  194. %token BITWISEXOR
  195. %token MODULO
  196. %token NEWADD
  197. %token NEWLESSTHAN
  198. %token NEWEQUALS
  199. %token TONUMBER
  200. %token TOSTRING
  201. %token INCREMENT
  202. %token DECREMENT
  203. %token TYPEOF
  204. %token TARGETPATH
  205. %token ENUMERATE
  206. %token ENUMERATEVALUE
  207. %token INSTANCEOF
  208. %token DELETE
  209. %token DELETE2
  210. %token NEW
  211. %token INITARRAY
  212. %token INITOBJECT
  213. %token GETMEMBER
  214. %token SETMEMBER
  215. %token SHIFTLEFT
  216. %token SHIFTRIGHT
  217. %token SHIFTRIGHT2
  218. %token VAR
  219. %token VAREQUALS
  220. %token OLDADD
  221. %token SUBTRACT
  222. %token MULTIPLY
  223. %token DIVIDE
  224. %token OLDEQUALS
  225. %token OLDLESSTHAN
  226. %token STRICTEQUALS
  227. %token GREATERTHAN
  228. %token LOGICALAND
  229. %token LOGICALOR
  230. %token LOGICALNOT
  231. %token STRINGEQ
  232. %token STRINGLENGTH
  233. %token SUBSTRING
  234. %token INT
  235. %token GETVARIABLE
  236. %token SETVARIABLE
  237. %token SETTARGET
  238. %token SETTARGETEXPR
  239. %token STRINGCONCAT
  240. %token GETPROPERTY
  241. %token SETPROPERTY
  242. %token DUPLICATECLIP
  243. %token REMOVECLIP
  244. %token TRACE
  245. %token STARTDRAGMOVIE
  246. %token STOPDRAGMOVIE
  247. %token STRINGLESSTHAN
  248. %token STRINGGREATERTHAN
  249. %token RANDOM
  250. %token MBLENGTH
  251. %token ORD
  252. %token CHR
  253. %token GETTIMER
  254. %token MBSUBSTRING
  255. %token MBORD
  256. %token MBCHR
  257. %token BRANCHALWAYS
  258. %token GETURL
  259. %token GETURL2
  260. %token LOADMOVIE
  261. %token LOADMOVIENUM
  262. %token LOADVARIABLES
  263. %token LOADVARIABLESNUM
  264. %token POST
  265. %token GET
  266. %token BRANCHIFTRUE
  267. %token CALLFRAME
  268. %token GOTOANDPLAY
  269. %token GOTOANDSTOP
  270. %token SKIP
  271. %token IFFRAMELOADEDEXPR
  272. %token IFFRAMELOADED
  273. %token ELSE
  274. %token STRICTMODE
  275. %token OFF
  276. %token IMPLEMENTS
  277. %token EXTENDS
  278. %token THROW
  279. %token CAST
  280. %token TRY
  281. %token CATCH
  282. %token FINALLY
  283. %token EQUALSIGN
  284. %token PUSHONE
  285. %token PUSHZERO
  286. %token PUSHTRUE
  287. %token PUSHFALSE
  288. %token PUSHBYTE
  289. %token PUSHSHORT
  290. %token PUSHLONG
  291. %token PUSHS
  292. %token PUSHSDB
  293. %token PUSHSDW
  294. %token CALLFP
  295. %token CALLFSV
  296. %token CALLMP
  297. %token CALLMSV
  298. %token PUSHSDBGV
  299. %token PUSHSDBGM
  300. %token PUSHTHIS
  301. %token PUSHGLOBAL
  302. %token PUSHNULL
  303. %token PUSHUNDEF
  304. %token DCALLFP
  305. %token DCALLFSV
  306. %token DCALLMP
  307. %token DCALLMSV
  308. %token PUSHFLOAT
  309. %token PUSHTHISGV
  310. %token PUSHGLOBALGV
  311. %token PUSHSGV
  312. %token PUSHSGM
  313. %token PUSHZEROSV
  314. %token PUSHSSV
  315. %token PUSHSSM
  316. %token BRANCHIFFALSE
  317. %token APTTRACESTART
  318.  
  319. /* unknown instruction handling */
  320. %token SWFACTION
  321. %token HEXDATA
  322.  
  323. %token '(' ')' ',' ':' '"' '.'
  324.  
  325. %type <str> name_opt mcname_opt
  326. %type <num> statements statement statements_opt
  327. %type <num> statementOptimized statementScanned
  328. %type <num> function function_args function2 regarglist regarg autoregarglist autoregarg
  329. %type <num> trycatchfinally catch_opt finally_opt
  330. %type <num> impassets impassetsblocks_opt impassetsblocks impassetsblock
  331. %type <num> expassets expassetsblocks_opt expassetsblocks expassetsblock
  332. %type <num> push_list push_item
  333. %type <num> register
  334. %type <num> with
  335. %type <num> settarget settargetexpression ifframeloaded ifframeloadedexpression
  336. %type <num> actionblocks actionblock actionblocks_opt
  337. %type <num> buttoneventblocks buttoneventblock buttoneventblocks_opt
  338. %type <num> mceventblocks mceventblock mceventblocks_opt
  339. %type <num> mcblocks mcblock mcblocks_opt
  340. %type <num> frame definebutton definemc placemc initmc
  341. %type <num> buttonevent buttonevents mcevent mcevents key property
  342. %type <num> opcode hex_list hexdata_opt
  343. %type <num> opcodeOptimized opcodeScanned
  344.  
  345. %type <num> urlmethod
  346.  
  347. %%
  348.  
  349. /* rules */
  350. program
  351. : MOVIE MOVIENAME { startUpdate($2); }
  352. actionblocks_opt END { finishUpdate(); }
  353. ;
  354.  
  355. actionblocks_opt
  356. : /* empty */ { $$ = 0; }
  357. | actionblocks { $$ = $1; }
  358. ;
  359.  
  360. actionblocks
  361. : actionblock { $$ = $1; }
  362. | actionblocks actionblock { $$ = $1 + $2; }
  363. ;
  364.  
  365. actionblock
  366. : frame { $$ = $1; }
  367. | definebutton { $$ = $1; }
  368. | definemc { $$ = $1; }
  369. | placemc { $$ = $1; }
  370. | initmc { $$ = $1; }
  371. | impassets { $$ = $1; }
  372. | expassets { $$ = $1; }
  373. | COMPRESSED { compressAfter = 1; $$ = 0; }
  374. | PROTECT { writeProtect(""); $$ = 0; }
  375. | PROTECT STRING { writeProtect($2); $$ = 0; }
  376. | ENABLEDEBUGGER { writeEnableDebugger(""); $$ = 0; }
  377. | ENABLEDEBUGGER STRING { writeEnableDebugger($2); $$ = 0; }
  378. | ENABLEDEBUGGER2 STRING { writeEnableDebugger2($2); $$ = 0; }
  379. | SCRIPTLIMITS RECURSION INTEGER TIMEOUT INTEGER
  380. {
  381. if ($3>65535)
  382. yyerror("Recursion depth out of range");
  383. if ($5>65535)
  384. yyerror("Timeout out of range");
  385. writeScriptLimits((unsigned int)$3, (unsigned int)$5);
  386. $$ = 0;
  387. }
  388. ;
  389.  
  390. frame
  391. : FRAME INTEGER statements_opt END {
  392. $$ = $3;
  393. /*action end*/
  394. $$ += writeByte(0);
  395. writeDoAction();
  396. $$ = 0;
  397. }
  398. ;
  399.  
  400. initmc
  401. : INITMOVIECLIP INTEGER statements_opt END
  402. {
  403. $$ = $3;
  404. /*action end*/
  405. $$ += writeByte(0);
  406. writeInitMC($2);
  407. $$ = 0;
  408. }
  409. ;
  410.  
  411. definebutton
  412. : DEFINEBUTTON INTEGER { writeButtonStart($2); }
  413. buttoneventblocks_opt END { $$ = $4; writeButtonEnd(); }
  414. ;
  415.  
  416. buttoneventblocks_opt
  417. : /* empty */ { $$ = 0; }
  418. | buttoneventblocks { $$ = $1; }
  419. ;
  420.  
  421. buttoneventblocks
  422. : buttoneventblock { $$ = $1; }
  423. | buttoneventblocks buttoneventblock { $$ = $1 + $2; }
  424. ;
  425.  
  426. buttoneventblock
  427. : ON { curEvent = 0; }
  428. buttonevents statements_opt END {
  429. $$ = $4;
  430. /*event action end*/
  431. $$ += writeByte(0);
  432. writeButtonEvent((unsigned int)curEvent);
  433. }
  434. ;
  435.  
  436. buttonevents
  437. : buttonevent { $$ = $1; curEvent += $1; }
  438. | buttonevents ',' buttonevent { $$ += $3; curEvent += $3; }
  439. ;
  440.  
  441. buttonevent
  442. : BIDLETOOVERUP { $$ = 0x01; }
  443. | BOVERUPTOIDLE { $$ = 0x02; }
  444. | BOVERUPTOOVERDOWN { $$ = 0x04; }
  445. | BOVERDOWNTOOVERUP { $$ = 0x08; }
  446. | BOVERDOWNTOOUTDOWN { $$ = 0x10; }
  447. | BOUTDOWNTOOVERDOWN { $$ = 0x20; }
  448. | BOUTDOWNTOIDLE { $$ = 0x40; }
  449. | BIDLETOOVERDOWN { $$ = 0x80; }
  450. | BOVERDOWNTOIDLE { $$ = 0x100; }
  451. | KEYPRESS key { $$ = $2<<9; }
  452. ;
  453.  
  454. key
  455. : _LEFT { $$ = 1; }
  456. | _RIGHT { $$ = 2; }
  457. | _HOME { $$ = 3; }
  458. | _END { $$ = 4; }
  459. | _INSERT { $$ = 5; }
  460. | _DELETE { $$ = 6; }
  461. | _BACKSPACE { $$ = 8; }
  462. | _ENTER { $$ = 13; }
  463. | _UP { $$ = 14; }
  464. | _DOWN { $$ = 15; }
  465. | _PGUP { $$ = 16; }
  466. | _PGDN { $$ = 17; }
  467. | _TAB { $$ = 18; }
  468. | _ESCAPE { $$ = 19; }
  469. | _SPACE { $$ = 32; }
  470. | STRING { $$ = $1[0]; }
  471. ;
  472.  
  473. register
  474. : REGISTER {
  475. /* only 255 regs can be allocated within function2,
  476. r:0 being the first and r:254 the last;
  477. outside 4 global registers exist */
  478. if ($1 >= 255)
  479. yyerror("Register number out of range");
  480. if ((byte)$1 > 3 && curFunc < 0)
  481. warning("Local registers r:4 to r:255 work in function2 context only");
  482. /* if needed, increase the number of registers
  483. to allocate for function2 */
  484. if (curFunc >= 0 && $1 + 1 > (long int) numRegisters[curFunc])
  485. numRegisters[curFunc] = $1 + 1;
  486. $$ = $1;
  487. }
  488.  
  489. | REGISTERALIAS {
  490. unsigned int m;
  491. int r = -1;
  492.  
  493. if (curFunc >= 0) {
  494. for(m = 1; m < numRegisters[curFunc]; ++m) {
  495. if (regfunc_args[curFunc][m] != NULL && !strcmp($1, regfunc_args[curFunc][m])) {
  496. r = m;
  497. break;
  498. }
  499. }
  500. }
  501.  
  502. if (r == -1)
  503. yyerror("Register alias not found");
  504.  
  505. $$ = r;
  506. }
  507. ;
  508.  
  509. definemc
  510. : DEFINEMOVIECLIP INTEGER { writeDefineMCStart($2); }
  511. mcblocks_opt END { $$ = $4; writeDefineMCEnd(); }
  512. ;
  513.  
  514. mcblocks_opt
  515. : /* empty */ { $$ = 0; }
  516. | mcblocks { $$ = $1; }
  517. ;
  518.  
  519. mcblocks
  520. : mcblock { $$ = $1; }
  521. | mcblocks mcblock { $$ = $1 + $2; }
  522. ;
  523.  
  524. mcblock
  525. : frame { $$ = $1; }
  526. | placemc { $$ = $1; }
  527. ;
  528.  
  529. placemc
  530. : PLACEMOVIECLIP INTEGER mcname_opt { allEvents = 0; writePlaceMCStart($2); }
  531. mceventblocks_opt END { $$ = $5; writePlaceMCEnd(allEvents); }
  532. ;
  533.  
  534. mcname_opt
  535. : /* empty */ { $$ = ""; }
  536. | AS STRING { $$ = $2; }
  537. ;
  538.  
  539. mceventblocks_opt
  540. : /* empty */ { $$ = 0; }
  541. | mceventblocks { $$ = $1; }
  542. ;
  543.  
  544. mceventblocks
  545. : mceventblock { $$ = $1; }
  546. | mceventblocks mceventblock { $$ = $1 + $2; }
  547. ;
  548.  
  549. mceventblock
  550. : ONCLIPEVENT mcevents {
  551. curEvent = $2;
  552. allEvents |= curEvent;
  553. }
  554.  
  555. statements_opt END {
  556. $$ = $4;
  557. /*event action end*/
  558. $$ += writeByte(0);
  559. writeOnClipEvent(curEvent);
  560. curEvent = 0;
  561. }
  562. ;
  563.  
  564. mcevents
  565. : mcevent { $$ = $1; curEvent += $1; }
  566. | mcevents ',' mcevent { $$ += $3; curEvent += $3; }
  567. ;
  568.  
  569. mcevent
  570. : /* empty */ { yyerror("Missing mc event condition"); }
  571. | MCLOAD { $$ = 0x01; }
  572. | MCENTERFRAME { $$ = 0x02; }
  573. | MCUNLOAD { $$ = 0x04; }
  574. | MCMOUSEMOVE { $$ = 0x08; }
  575. | MCMOUSEDOWN { $$ = 0x10; }
  576. | MCMOUSEUP { $$ = 0x20; }
  577. | MCKEYDOWN { $$ = 0x40; }
  578. | MCKEYUP { $$ = 0x80; }
  579. | MCDATA { $$ = 0x100; }
  580. | MCINITIALIZE { $$ = 0x200; }
  581. | MCPRESS { $$ = 0x400; }
  582. | MCRELEASE { $$ = 0x800; }
  583. | MCRELEASEOUTSIDE { $$ = 0x1000; }
  584. | MCROLLOVER { $$ = 0x2000; }
  585. | MCROLLOUT { $$ = 0x4000; }
  586. | MCDRAGOVER { $$ = 0x8000; }
  587. | MCDRAGOUT { $$ = 0x10000; }
  588. | KEYPRESS key { $$ = 0x20000; writeByte($2); }
  589. | MCCONSTRUCT { $$ = 0x40000; }
  590. ;
  591.  
  592. catch_opt
  593. : /* empty */ { $$ = 0; }
  594. | CATCH statements_opt { $$ = $2; }
  595. ;
  596.  
  597. finally_opt
  598. : /* empty */ { $$ = 0; }
  599. | FINALLY statements_opt { $$ = $2; }
  600. ;
  601.  
  602. trycatchfinally
  603. : TRY name_opt {
  604. $$ = writeByte(SWFACTION_TRY);
  605. /* action length */
  606. $$ += writeShort(strlen($2)+8);
  607. /* zero flag */
  608. $$ += writeByte(0);
  609. /* zero try length */
  610. $$ += writeShort(0);
  611. /* zero catch length */
  612. $$ += writeShort(0);
  613. /* zero finally length */
  614. $$ += writeShort(0);
  615. /* error variable name */
  616. $$ += writeString($2);
  617. }
  618.  
  619. statements_opt { $$ = $<num>3 + $4; patchLength($$ - 6, $4); }
  620. catch_opt { $$ = $<num>5 + $6; patchLength($$ - 8, $6); }
  621. finally_opt { $$ = $<num>7 + $8; patchLength($$ - 10, $8); }
  622. END {
  623. byte flag = 0;
  624. $$ = $<num>9;
  625. if ($6>0)
  626. flag = flag + 1;
  627. if ($8>0)
  628. flag = flag + 2;
  629. patchFlag($$ - 4, flag);
  630. }
  631.  
  632. | TRY register {
  633. $$ = writeByte(SWFACTION_TRY);
  634. /* action length */
  635. $$ += writeShort(8);
  636. /* zero flag */
  637. $$ += writeByte(0);
  638. /* zero try length */
  639. $$ += writeShort(0);
  640. /* zero catch length */
  641. $$ += writeShort(0);
  642. /* zero finally length */
  643. $$ += writeShort(0);
  644. /* error register number */
  645. $$ += writeByte((byte) $2);
  646. }
  647. ;
  648.  
  649. statements
  650. : statement { $$ = $1; } %dprec 5
  651. | statements statement { $$ = $1 + $2; } %dprec 1
  652. | statementOptimized { $$ = $1; } %dprec 20
  653. | statementScanned { $$ = $1; } %dprec 15
  654. | statements statementOptimized { $$ = $1 + $2; } %dprec 10
  655. | statements statementScanned { $$ = $1 + $2; } %dprec 8
  656. ;
  657.  
  658. statement
  659. : label { $$ = 0; }
  660. | function { $$ = $1; }
  661. | function2 { $$ = $1; }
  662. | with { $$ = $1; }
  663. | settarget { $$ = $1; }
  664. | settargetexpression { $$ = $1; }
  665. | ifframeloaded { $$ = $1; }
  666. | ifframeloadedexpression { $$ = $1; }
  667. | trycatchfinally { $$ = $1; }
  668. | opcode { $$ = $1; }
  669. ;
  670.  
  671. statementOptimized
  672. : opcodeOptimized { $$ = $1; }
  673.  
  674. statementScanned
  675. : opcodeScanned { $$ = $1; }
  676.  
  677. label
  678. : LABEL { addLabel($1); }
  679. ;
  680.  
  681. /* this is weird/dumb- now we're returning the number of args instead
  682. of their length, and the args are stored in a global array func_args. */
  683.  
  684. function_args
  685. : /* empty */ { $$ = 0; }
  686. | STRING { func_args[0] = $1; $$ = 1; }
  687. | function_args ',' STRING { func_args[$1] = $3; $$ = $1 + 1; }
  688. ;
  689.  
  690. statements_opt
  691. : /* empty */ { $$ = 0; }
  692. | statements { $$ = $1; }
  693. ;
  694.  
  695. name_opt
  696. : /* empty */ { $$ = ""; }
  697. | STRING { $$ = $1; }
  698. ;
  699.  
  700. function
  701. : FUNCTION name_opt {
  702. $$ = writeByte(SWFACTION_DEFINEFUNCTION);
  703. /* zero block length */
  704. $$ += writeShort(0);
  705. $$ += writeString($2);
  706. }
  707.  
  708. '(' function_args ')' {
  709. unsigned int i;
  710. numArgs = $5;
  711.  
  712. $$ = $<num>3 + writeShort(numArgs);
  713.  
  714. for(i = 0; i < numArgs; ++i)
  715. $$ += writeString(func_args[i]);
  716.  
  717. /* zero function length */
  718. $$ += writeShort(0);
  719. /* patch block length */
  720. patchLength($$-3, $$-3);
  721. }
  722.  
  723. statements_opt END {
  724. $$ = $<num>7 + $8;
  725. /* patch function length */
  726. patchLength($8, $8);
  727. }
  728. ;
  729.  
  730. regarg
  731. : REGISTER EQUALSIGN STRING {
  732. numArgs++;
  733. $$ = writeByte((byte) $1);
  734.  
  735. if ($1 == 0)
  736. yyerror("Function argument can't be stored in r:0");
  737.  
  738. if ($1 + 1 >= MAX_REGISTERS)
  739. yyerror("Too many registers");
  740.  
  741. if (numArgs >= MAX_FUNCARGS)
  742. yyerror("Too many function arguments");
  743.  
  744. if (regfunc_args[curFunc][$1] != NULL)
  745. yyerror("Duplicate register");
  746.  
  747. regfunc_args[curFunc][$1] = $3;
  748.  
  749. if ($1 + 1 > (long int) numRegisters[curFunc])
  750. numRegisters[curFunc] = $1 + 1;
  751.  
  752. /* if parameter is stored in register, may skip its name */
  753. if ($1 > 0 && clearregisterargs && mode >= MODE_UPDATE)
  754. $$ += writeString("");
  755. else
  756. $$ += writeString($3);
  757. }
  758. | STRING {
  759. numArgs++;
  760. /* r:0 - not stored in register */
  761. $$ = writeByte(0);
  762. $$ += writeString($1);
  763. }
  764. ;
  765.  
  766. regarglist
  767. : /* empty */ { $$ = 0; }
  768. | regarg { $$ = $1; }
  769. | regarglist ',' regarg { $$ = $1 + $3; }
  770. ;
  771.  
  772. autoregarg
  773. : REGISTER EQUALSIGN STRING {
  774. unsigned int autoregFlag = 0, i;
  775.  
  776. if ($1 == 0 || $1 > MAX_AUTO_REGS)
  777. yyerror("Automatic values should be placed into consequent registers starting with r:1\nin this order: this, arguments, super, _root, _parent, _global");
  778.  
  779. if (regfunc_args[curFunc][$1] != NULL && strcmp(regfunc_args[curFunc][$1], $3))
  780. yyerror("Duplicate register");
  781.  
  782. regfunc_args[curFunc][$1] = $3;
  783.  
  784. if ($1 + 1 > (long int) numRegisters[curFunc])
  785. numRegisters[curFunc] = $1 + 1;
  786.  
  787. for (i = 0; i < MAX_AUTO_REGS; i++) {
  788. if (!strcmp($3, arNames[i])) {
  789. autoregFlag = arFlags[i];
  790. break;
  791. }
  792. }
  793.  
  794. if (autoregFlag == 0)
  795. yyerror("Only automatic values (this, arguments, super, _root, _parent, _global) are allowed here");
  796.  
  797. if (!(autoregFlags & autoregFlag))
  798. autoregFlags += autoregFlag;
  799. else
  800. yyerror("Duplicate automatic value");
  801. }
  802. ;
  803.  
  804. autoregarglist
  805. : /* empty */ { $$ = 0; }
  806. | autoregarg { $$ = 1; }
  807. | autoregarglist ',' autoregarg { $$ = $1 + 1; }
  808. ;
  809.  
  810. function2
  811. : FUNCTION2 name_opt {
  812. $$ = writeByte(SWFACTION_DEFINEFUNCTION2);
  813. /* zero block length */
  814. $$ += writeShort(0);
  815. /* function name */
  816. $$ += writeString($2);
  817. curFunc++;
  818. memset(regfunc_args[curFunc], 0, sizeof (regfunc_args[curFunc]));
  819. numArgs = 0;
  820. /* zero num of function arguments */
  821. $$ += writeShort(numArgs);
  822. /* allocate zero registers */
  823. numRegisters[curFunc] = 0;
  824. $$ += writeByte(numRegisters[curFunc]);
  825. /* zero automatic register flags */
  826. $$ += writeShort(0);
  827. }
  828.  
  829. '(' regarglist ')' {
  830. $$ = $<num>3 + $5;
  831. /* patch num of function arguments */
  832. patchLength($5 + 3, numArgs);
  833. autoregFlags = 0;
  834. }
  835.  
  836. '(' autoregarglist ')' {
  837. byte curautoreg = 1;
  838. unsigned int i;
  839.  
  840. $$ = $<num>7;
  841. /* zero body length */
  842. $$ += writeShort(0);
  843.  
  844. /* make sure auto registers are allocated in the right order */
  845. for (i = 0; i < MAX_AUTO_REGS; i++) {
  846. if (autoregFlags & arFlags[i]) {
  847. if (regfunc_args[curFunc][curautoreg] != NULL && !strcmp(regfunc_args[curFunc][curautoreg], arNames[i]))
  848. curautoreg++;
  849. else
  850. yyerror("Automatic values should be placed into consequent registers starting with r:1\nin this order: this, arguments, super, _root, _parent, _global");
  851. }
  852. else
  853. autoregFlags += arNotFlags[i];
  854. }
  855.  
  856. /* patch automatic register flags */
  857. patchLength($$ - $<num>3, autoregFlags);
  858. /* patch block length */
  859. patchLength($$ - 3, $$ - 3);
  860. }
  861.  
  862. statements_opt END {
  863. $$ = $<num>11 + $12;
  864.  
  865. /* patch number of registers to allocate */
  866. if (numRegisters[curFunc] < MAX_REGISTERS)
  867. patchFlag($$ - $<num>3 + 2, (byte) numRegisters[curFunc]);
  868. else
  869. yyerror("Too many registers.");
  870.  
  871. /* patch function length */
  872. patchLength($12, $12);
  873. curFunc--;
  874. }
  875. ;
  876.  
  877. with
  878. : WITH {
  879. $$ = writeByte(SWFACTION_WITH);
  880. /* length of with action */
  881. $$ += writeShort(2);
  882. /* length of with block - will be patched */
  883. $$ += writeShort(0);
  884. }
  885.  
  886. statements_opt END {
  887. $$ = $<num>2 + $3;
  888. patchLength($3, $3);
  889. }
  890.  
  891. ;
  892.  
  893. settarget
  894. : SETTARGET STRING {
  895. $$ = writeByte(SWFACTION_SETTARGET);
  896. $$ += writeShort(strlen($2)+1);
  897. $$ += writeString($2);
  898. }
  899.  
  900. statements_opt END {
  901. $$ = $4 + writeByte(SWFACTION_SETTARGET);
  902. $$ += $<num>3 + writeShort(1);
  903. $$ += writeByte(0);
  904. }
  905. ;
  906.  
  907. settargetexpression
  908. : SETTARGETEXPR { $$ = writeByte(SWFACTION_SETTARGETEXPRESSION); }
  909. statements_opt END {
  910. $$ = $3 + writeByte(SWFACTION_SETTARGET);
  911. $$ += $<num>2 + writeShort(1);
  912. $$ += writeByte(0);
  913. }
  914. ;
  915.  
  916. ifframeloadedexpression
  917. : IFFRAMELOADEDEXPR {
  918. if (frameloadedStart>-1)
  919. yyerror("IfFrameLoaded actions can't be nested");
  920. $$ = writeByte(SWFACTION_IFFRAMELOADEDEXPRESSION);
  921. $$ += writeShort(1);
  922. $$ += writeByte(0);
  923. frameloadedStart = numActions;
  924. }
  925.  
  926. statements_opt END {
  927. $$ = $<num>2 + $3;
  928. patchFrameLoaded($3, numActions-frameloadedStart);
  929. frameloadedStart = -1;
  930. }
  931. ;
  932.  
  933. ifframeloaded
  934. : IFFRAMELOADED INTEGER {
  935. if (frameloadedStart>-1)
  936. yyerror("IfFrameLoaded actions can't be nested");
  937. $$ = writeByte(SWFACTION_IFFRAMELOADED);
  938. $$ += writeShort(3);
  939. $$ += writeShort($2);
  940. $$ += writeByte(0);
  941. frameloadedStart = numActions;
  942. }
  943.  
  944. statements_opt END {
  945. $$ = $<num>3 + $4;
  946. patchFrameLoaded($4, numActions-frameloadedStart);
  947. frameloadedStart = -1;
  948. }
  949. ;
  950.  
  951. impassets
  952. : IMPORTASSETS FROM STRING { numAssets = 0; }
  953. impassetsblocks_opt END {
  954. $$ = $5;
  955. writeImportAssets($3, numAssets);
  956. $$ = 0;
  957. }
  958. ;
  959.  
  960. impassetsblocks_opt
  961. : /* empty */ { $$ = 0; }
  962. | impassetsblocks { $$ = $1; }
  963. ;
  964.  
  965. impassetsblocks
  966. : impassetsblock { $$ = $1; }
  967. | impassetsblocks impassetsblock { $$ = $1 + $2; }
  968. ;
  969.  
  970. impassetsblock
  971. : STRING AS INTEGER {
  972. $$ = strlen($1)+3;
  973. writeShort($3);
  974. writeString($1);
  975. numAssets++;
  976. }
  977. ;
  978.  
  979. expassets
  980. : EXPORTASSETS { numAssets = 0; }
  981. expassetsblocks_opt END {
  982. $$ = $3;
  983. writeExportAssets(numAssets);
  984. $$ = 0;
  985. }
  986. ;
  987.  
  988. expassetsblocks_opt
  989. : /* empty */ { $$ = 0; }
  990. | expassetsblocks { $$ = $1; }
  991. ;
  992.  
  993. expassetsblocks
  994. : expassetsblock { $$ = $1; }
  995. | expassetsblocks expassetsblock { $$ = $1 + $2; }
  996. ;
  997.  
  998. expassetsblock
  999. : INTEGER AS STRING {
  1000. $$ = strlen($3)+3;
  1001. writeShort($1);
  1002. writeString($3);
  1003. numAssets++;
  1004. }
  1005. ;
  1006.  
  1007. push_item
  1008. : STRING { $$ = writePushString($1); }
  1009.  
  1010. | property {
  1011. $$ = writeByte(0x01);
  1012. $$ += writeFloat((float)$1);
  1013. }
  1014.  
  1015. | FLOAT {
  1016. float f;
  1017. sscanf($1, "%f", &f);
  1018. $$ = writeByte(0x01);
  1019. $$ += writeFloat(f);
  1020. }
  1021.  
  1022. | _NANF {
  1023. $$ = writeByte(0x01);
  1024. $$ += writeFloat(0/zero);
  1025. }
  1026.  
  1027. | POSITIVE_INFINITYF {
  1028. $$ = writeByte(0x01);
  1029. $$ += writeFloat(1/zero);
  1030. }
  1031.  
  1032. | NEGATIVE_INFINITYF {
  1033. $$ = writeByte(0x01);
  1034. $$ += writeFloat(-1/zero);
  1035. }
  1036.  
  1037. | HEX {
  1038. unsigned long int li = xtoi($1);
  1039. if (li > 65535)
  1040. yyerror("Hex number should be unsigned integer in the range from 0x0000 to 0xFFFF");
  1041.  
  1042. $$ = writeByte(0x07);
  1043. $$ += writeLongInt(xtoi($1));
  1044. }
  1045.  
  1046. | INTEGER {
  1047. $$ = writeByte(0x07);
  1048. $$ += writeLongInt($1);
  1049. }
  1050.  
  1051. | DOUBLE {
  1052. $$ = writeByte(0x06);
  1053. $$ += writeDouble(atof($1));
  1054. }
  1055.  
  1056. | _NAN {
  1057. $$ = writeByte(0x06);
  1058. $$ += writeDouble(0/zero);
  1059. }
  1060.  
  1061. | POSITIVE_INFINITY {
  1062. $$ = writeByte(0x06);
  1063. $$ += writeDouble(1/zero);
  1064. }
  1065.  
  1066. | NEGATIVE_INFINITY {
  1067. $$ = writeByte(0x06);
  1068. $$ += writeDouble(-1/zero);
  1069. }
  1070.  
  1071. | TRUEVAL {
  1072. $$ = writeByte(0x05);
  1073. $$ += writeByte(1);
  1074. }
  1075.  
  1076. | FALSEVAL {
  1077. $$ = writeByte(0x05);
  1078. $$ += writeByte(0);
  1079. }
  1080.  
  1081. | NULLVAL { $$ = writeByte(2); }
  1082.  
  1083. | UNDEFVAL { $$ = writeByte(3); }
  1084.  
  1085. | register {
  1086. $$ = writeByte(0x04);
  1087. $$ += writeByte((byte)$1);
  1088. }
  1089. ;
  1090.  
  1091. property
  1092. : X_PROPERTY { $$ = 0; }
  1093. | Y_PROPERTY { $$ = 1; }
  1094. | XSCALE_PROPERTY { $$ = 2; }
  1095. | YSCALE_PROPERTY { $$ = 3; }
  1096. | CURRENTFRAME_PROPERTY { $$ = 4; }
  1097. | TOTALFRAMES_PROPERTY { $$ = 5; }
  1098. | ALPHA_PROPERTY { $$ = 6; }
  1099. | VISIBLE_PROPERTY { $$ = 7; }
  1100. | WIDTH_PROPERTY { $$ = 8; }
  1101. | HEIGHT_PROPERTY { $$ = 9; }
  1102. | ROTATION_PROPERTY { $$ = 10; }
  1103. | TARGET_PROPERTY { $$ = 11; }
  1104. | FRAMESLOADED_PROPERTY { $$ = 12; }
  1105. | NAME_PROPERTY { $$ = 13; }
  1106. | DROPTARGET_PROPERTY { $$ = 14; }
  1107. | URL_PROPERTY { $$ = 15; }
  1108. | HIGHQUALITY_PROPERTY { $$ = 16; }
  1109. | FOCUSRECT_PROPERTY { $$ = 17; }
  1110. | SOUNDBUFTIME_PROPERTY { $$ = 18; }
  1111. | QUALITY_PROPERTY { $$ = 19; }
  1112. | XMOUSE_PROPERTY { $$ = 20; }
  1113. | YMOUSE_PROPERTY { $$ = 21; }
  1114. ;
  1115.  
  1116. push_list
  1117. : push_item { $$ = $1; }
  1118. | push_list ',' push_item { $$ += $3; }
  1119. ;
  1120.  
  1121. constant_list
  1122. : STRING { addConstant($1); }
  1123. | constant_list ',' STRING { addConstant($3); }
  1124. ;
  1125.  
  1126. hex_list
  1127. : HEX {
  1128. if (xtoi($1)>0xff)
  1129. yyerror("Action data must be a byte list!");
  1130. $$ = writeByte((char)xtoi($1));
  1131. }
  1132.  
  1133. | hex_list ',' HEX {
  1134. if (xtoi($3)>0xff)
  1135. yyerror("Action data must be a byte list!");
  1136. $$ += writeByte((char)xtoi($3));
  1137. }
  1138. ;
  1139.  
  1140. hexdata_opt
  1141. : /* empty */ { $$ = 0; }
  1142. | HEXDATA hex_list { $$ = $2; }
  1143. ;
  1144.  
  1145. urlmethod
  1146. : /* empty */ { $$ = 0; }
  1147. | GET { $$ = 1; }
  1148. | POST { $$ = 2; }
  1149. ;
  1150.  
  1151. opcodeOptimized
  1152. : PUSHZERO SETVARIABLE { $$ = writeByte(SWFACTION_PUSHZEROSETVAR); --numActions;}
  1153. | PUSHTHIS GETVARIABLE { $$ = writeByte(SWFACTION_PUSHTHISVARIABLE); --numActions;}
  1154. | PUSHGLOBAL GETVARIABLE { $$ = writeByte(SWFACTION_PUSHGLOBALVARIABLE); --numActions;}
  1155. | PUSH INTEGER {
  1156. if ($2 == 0) {
  1157. $$ = writeByte(SWFACTION_PUSH0);
  1158. } else if ($2 == 1) {
  1159. $$ = writeByte(SWFACTION_PUSH1);
  1160. } else {
  1161. int val = $2;
  1162. if (val <= -127 || val >= 127) {
  1163. if (val <= -32767 || val >= 32767) {
  1164. $$ = writeByte(SWFACTION_PUSHDWORD);
  1165. $$ += writeShort(4);
  1166. $$ += writeLongInt($2);
  1167. }
  1168. else
  1169. {
  1170. $$ = writeByte(SWFACTION_PUSHWORD);
  1171. $$ += writeShort(2);
  1172. $$ += writeShort($2);
  1173. }
  1174. }
  1175. else
  1176. {
  1177. $$ = writeByte(SWFACTION_PUSHBYTE);
  1178. $$ += writeShort(1);
  1179. $$ += writeByte($2);
  1180. }
  1181. }
  1182. }
  1183. | PUSH STRING {
  1184. if (!stricmp($2, "this")) {
  1185. $$ = writeByte(SWFACTION_PUSHTHIS);
  1186. } else if (!stricmp($2, "_global")) {
  1187. $$ = writeByte(SWFACTION_PUSHGLOBAL);
  1188. } else if (!stricmp($2, "UNDEF")) {
  1189. $$ = writeByte(SWFACTION_PUSHUNDEFINED);
  1190. } else {
  1191. unsigned int i;
  1192. for (i = 0; i < nConstants; ++i) {
  1193. if (strcmp(constants[i], $2) == 0) {
  1194. break;
  1195. }
  1196. }
  1197. if (i < nConstants) {
  1198. if (i < 256) {
  1199. writeByte(SWFACTION_PUSHSTRINGDICTBYTE);
  1200. writeByte(1);
  1201. writeByte(0);
  1202. writeByte(i);
  1203. $$ = 4;
  1204. } else {
  1205. writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1206. writeByte(2);
  1207. writeByte(0);
  1208. writeShort(i);
  1209. $$ = 5;
  1210. }
  1211. } else {
  1212. unsigned int len = strlen($2) + 1;
  1213. writeByte(SWFACTION_PUSHSTRING);
  1214. writeShort(len);
  1215. writeString($2);
  1216. $$ = len + 3;
  1217. }
  1218. }
  1219. } %dprec 21
  1220. | PUSH STRING GETVARIABLE {
  1221. if (!stricmp($2, "this")) {
  1222. $$ = writeByte(SWFACTION_PUSHTHISVARIABLE); --numActions;
  1223. } else if (!stricmp($2, "_global")) {
  1224. $$ = writeByte(SWFACTION_PUSHGLOBALVARIABLE); --numActions;
  1225. } else if (!stricmp($2, "UNDEF")) {
  1226. $$ = writeByte(SWFACTION_PUSHUNDEFINED);
  1227. $$ += writeByte(SWFACTION_GETVARIABLE);
  1228. } else {
  1229. unsigned int i;
  1230. for (i = 0; i < nConstants; ++i) {
  1231. if (strcmp(constants[i], $2) == 0) {
  1232. break;
  1233. }
  1234. }
  1235. if (i < nConstants) {
  1236. if (i < 256) {
  1237. writeByte(SWFACTION_STRINGDICTBYTEGETVAR);
  1238. writeByte(1);
  1239. writeByte(0);
  1240. writeByte(i);
  1241. --numActions;
  1242. $$ = 4;
  1243. } else {
  1244. writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1245. writeByte(2);
  1246. writeByte(0);
  1247. writeShort(i);
  1248. writeByte(SWFACTION_GETVARIABLE);
  1249. $$ = 6;
  1250. }
  1251. } else {
  1252. unsigned int len = strlen($2) + 1;
  1253. writeByte(SWFACTION_PUSHSTRINGGETVAR);
  1254. writeShort(len);
  1255. writeString($2);
  1256. --numActions;
  1257. $$ = len + 3;
  1258. }
  1259. }
  1260. } %dprec 22
  1261. | PUSH STRING GETMEMBER {
  1262. if (!stricmp($2, "this")) {
  1263. $$ = writeByte(SWFACTION_PUSHTHIS);
  1264. $$ += writeByte(SWFACTION_GETMEMBER);
  1265. } else if (!stricmp($2, "_global")) {
  1266. $$ = writeByte(SWFACTION_PUSHGLOBAL);
  1267. $$ += writeByte(SWFACTION_GETMEMBER);
  1268. } else if (!stricmp($2, "UNDEF")) {
  1269. $$ = writeByte(SWFACTION_PUSHUNDEFINED);
  1270. $$ += writeByte(SWFACTION_GETMEMBER);
  1271. } else {
  1272. unsigned int i;
  1273. for (i = 0; i < nConstants; ++i) {
  1274. if (strcmp(constants[i], $2) == 0) {
  1275. break;
  1276. }
  1277. }
  1278. if (i < nConstants) {
  1279. if (i < 256) {
  1280. writeByte(SWFACTION_STRINGDICTBYTEGETMEMBER);
  1281. writeByte(1);
  1282. writeByte(0);
  1283. writeByte(i);
  1284. --numActions;
  1285. $$ = 4;
  1286. } else {
  1287. writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1288. writeByte(2);
  1289. writeByte(0);
  1290. writeShort(i);
  1291. writeByte(SWFACTION_GETMEMBER);
  1292. $$ = 6;
  1293. }
  1294. } else {
  1295. unsigned int len = strlen($2) + 1;
  1296. writeByte(SWFACTION_PUSHSTRINGGETMEMBER);
  1297. writeShort(len);
  1298. writeString($2);
  1299. --numActions;
  1300. $$ = len + 3;
  1301. }
  1302. }
  1303. } %dprec 22
  1304. | PUSH STRING SETVARIABLE {
  1305. if (!stricmp($2, "this")) {
  1306. $$ = writeByte(SWFACTION_PUSHTHIS);
  1307. $$ += writeByte(SWFACTION_SETVARIABLE);
  1308. } else if (!stricmp($2, "_global")) {
  1309. $$ = writeByte(SWFACTION_PUSHGLOBAL);
  1310. $$ += writeByte(SWFACTION_SETVARIABLE);
  1311. } else if (!stricmp($2, "UNDEF")) {
  1312. $$ = writeByte(SWFACTION_PUSHUNDEFINED);
  1313. $$ += writeByte(SWFACTION_SETVARIABLE);
  1314. } else {
  1315. unsigned int i;
  1316. for (i = 0; i < nConstants; ++i) {
  1317. if (strcmp(constants[i], $2) == 0) {
  1318. break;
  1319. }
  1320. }
  1321. if (i < nConstants) {
  1322. if (i < 256) {
  1323. writeByte(SWFACTION_PUSHSTRINGDICTBYTE);
  1324. writeByte(1);
  1325. writeByte(0);
  1326. writeByte(i);
  1327. writeByte(SWFACTION_SETVARIABLE);
  1328. $$ = 5;
  1329. } else {
  1330. writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1331. writeByte(2);
  1332. writeByte(0);
  1333. writeShort(i);
  1334. writeByte(SWFACTION_SETVARIABLE);
  1335. $$ = 6;
  1336. }
  1337. } else {
  1338. unsigned int len = strlen($2) + 1;
  1339. writeByte(SWFACTION_PUSHSTRINGSETVAR);
  1340. writeShort(len);
  1341. writeString($2);
  1342. --numActions;
  1343. $$ = len + 3;
  1344. }
  1345. }
  1346. } %dprec 22
  1347. | PUSH STRING SETMEMBER {
  1348. if (!stricmp($2, "this")) {
  1349. $$ = writeByte(SWFACTION_PUSHTHIS);
  1350. $$ += writeByte(SWFACTION_SETMEMBER);
  1351. } else if (!stricmp($2, "_global")) {
  1352. $$ = writeByte(SWFACTION_PUSHGLOBAL);
  1353. $$ += writeByte(SWFACTION_SETMEMBER);
  1354. } else if (!stricmp($2, "UNDEF")) {
  1355. $$ = writeByte(SWFACTION_PUSHUNDEFINED);
  1356. $$ += writeByte(SWFACTION_SETMEMBER);
  1357. } else {
  1358. unsigned int i;
  1359. for (i = 0; i < nConstants; ++i) {
  1360. if (strcmp(constants[i], $2) == 0) {
  1361. break;
  1362. }
  1363. }
  1364. if (i < nConstants) {
  1365. if (i < 256) {
  1366. writeByte(SWFACTION_PUSHSTRINGDICTBYTE);
  1367. writeByte(1);
  1368. writeByte(0);
  1369. writeByte(i);
  1370. writeByte(SWFACTION_SETMEMBER);
  1371. $$ = 5;
  1372. } else {
  1373. writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1374. writeByte(2);
  1375. writeByte(0);
  1376. writeShort(i);
  1377. writeByte(SWFACTION_SETMEMBER);
  1378. $$ = 6;
  1379. }
  1380. } else {
  1381. unsigned int len = strlen($2) + 1;
  1382. writeByte(SWFACTION_PUSHSTRINGSETMEMBER);
  1383. writeShort(len);
  1384. writeString($2);
  1385. --numActions;
  1386. $$ = len + 3;
  1387. }
  1388. }
  1389. } %dprec 22
  1390. | PUSH STRING CALLFUNCTION POP {
  1391. if (!stricmp($2, "this")) {
  1392. $$ = writeByte(SWFACTION_PUSHTHIS);
  1393. $$ += writeByte(SWFACTION_CALLFUNCTION);
  1394. $$ += writeByte(SWFACTION_POP);
  1395. } else if (!stricmp($2, "_global")) {
  1396. $$ = writeByte(SWFACTION_PUSHGLOBAL);
  1397. $$ += writeByte(SWFACTION_CALLFUNCTION);
  1398. $$ += writeByte(SWFACTION_POP);
  1399. } else if (!stricmp($2, "UNDEF")) {
  1400. $$ = writeByte(SWFACTION_PUSHUNDEFINED);
  1401. $$ += writeByte(SWFACTION_CALLFUNCTION);
  1402. $$ += writeByte(SWFACTION_POP);
  1403. } else {
  1404. unsigned int i;
  1405. for (i = 0; i < nConstants; ++i) {
  1406. if (strcmp(constants[i], $2) == 0) {
  1407. break;
  1408. }
  1409. }
  1410. if (i < nConstants) {
  1411. if (i < 256) {
  1412. writeByte(SWFACTION_DICTCALLFUNCPOP);
  1413. writeByte(1);
  1414. writeByte(0);
  1415. writeByte(i);
  1416. --numActions;
  1417. --numActions;
  1418. $$ = 4;
  1419. } else {
  1420. writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1421. writeByte(2);
  1422. writeByte(0);
  1423. writeShort(i);
  1424. $$ += writeByte(SWFACTION_CALLFUNCTION);
  1425. $$ += writeByte(SWFACTION_POP);
  1426. $$ = 7;
  1427. }
  1428. } else {
  1429. unsigned int len = strlen($2) + 1;
  1430. writeByte(SWFACTION_PUSHSTRING);
  1431. writeShort(len);
  1432. writeString($2);
  1433. writeByte(SWFACTION_CALLFUNCTION);
  1434. writeByte(SWFACTION_POP);
  1435. $$ = len + 5;
  1436. }
  1437. }
  1438. } %dprec 23
  1439. | PUSH STRING CALLMETHOD POP {
  1440. if (!stricmp($2, "this")) {
  1441. $$ = writeByte(SWFACTION_PUSHTHIS);
  1442. $$ += writeByte(SWFACTION_CALLMETHOD);
  1443. $$ += writeByte(SWFACTION_POP);
  1444. } else if (!stricmp($2, "_global")) {
  1445. $$ = writeByte(SWFACTION_PUSHGLOBAL);
  1446. $$ += writeByte(SWFACTION_CALLMETHOD);
  1447. $$ += writeByte(SWFACTION_POP);
  1448. } else if (!stricmp($2, "UNDEF")) {
  1449. $$ = writeByte(SWFACTION_PUSHUNDEFINED);
  1450. $$ += writeByte(SWFACTION_CALLMETHOD);
  1451. $$ += writeByte(SWFACTION_POP);
  1452. } else {
  1453. unsigned int i;
  1454. for (i = 0; i < nConstants; ++i) {
  1455. if (strcmp(constants[i], $2) == 0) {
  1456. break;
  1457. }
  1458. }
  1459. if (i < nConstants) {
  1460. if (i < 256) {
  1461. writeByte(SWFACTION_DICTCALLMETHODPOP);
  1462. writeByte(1);
  1463. writeByte(0);
  1464. writeByte(i);
  1465. --numActions;
  1466. --numActions;
  1467. $$ = 4;
  1468. } else {
  1469. writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1470. writeByte(2);
  1471. writeByte(0);
  1472. writeShort(i);
  1473. $$ += writeByte(SWFACTION_CALLMETHOD);
  1474. $$ += writeByte(SWFACTION_POP);
  1475. $$ = 7;
  1476. }
  1477. } else {
  1478. unsigned int len = strlen($2) + 1;
  1479. writeByte(SWFACTION_PUSHSTRING);
  1480. writeShort(len);
  1481. writeString($2);
  1482. writeByte(SWFACTION_CALLMETHOD);
  1483. writeByte(SWFACTION_POP);
  1484. $$ = len + 5;
  1485. }
  1486. }
  1487. } %dprec 23
  1488. | PUSH STRING CALLFUNCTION SETVARIABLE {
  1489. if (!stricmp($2, "this")) {
  1490. $$ = writeByte(SWFACTION_PUSHTHIS);
  1491. $$ += writeByte(SWFACTION_CALLFUNCTION);
  1492. $$ += writeByte(SWFACTION_SETVARIABLE);
  1493. } else if (!stricmp($2, "_global")) {
  1494. $$ = writeByte(SWFACTION_PUSHGLOBAL);
  1495. $$ += writeByte(SWFACTION_CALLFUNCTION);
  1496. $$ += writeByte(SWFACTION_SETVARIABLE);
  1497. } else if (!stricmp($2, "UNDEF")) {
  1498. $$ = writeByte(SWFACTION_PUSHUNDEFINED);
  1499. $$ += writeByte(SWFACTION_CALLFUNCTION);
  1500. $$ += writeByte(SWFACTION_SETVARIABLE);
  1501. } else {
  1502. unsigned int i;
  1503. for (i = 0; i < nConstants; ++i) {
  1504. if (strcmp(constants[i], $2) == 0) {
  1505. break;
  1506. }
  1507. }
  1508. if (i < nConstants) {
  1509. if (i < 256) {
  1510. writeByte(SWFACTION_DICTCALLFUNCSETVAR);
  1511. writeByte(1);
  1512. writeByte(0);
  1513. writeByte(i);
  1514. --numActions;
  1515. --numActions;
  1516. $$ = 4;
  1517. } else {
  1518. writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1519. writeByte(2);
  1520. writeByte(0);
  1521. writeShort(i);
  1522. $$ += writeByte(SWFACTION_CALLFUNCTION);
  1523. $$ += writeByte(SWFACTION_SETVARIABLE);
  1524. $$ = 7;
  1525. }
  1526. } else {
  1527. unsigned int len = strlen($2) + 1;
  1528. writeByte(SWFACTION_PUSHSTRING);
  1529. writeShort(len);
  1530. writeString($2);
  1531. writeByte(SWFACTION_CALLFUNCTION);
  1532. writeByte(SWFACTION_SETVARIABLE);
  1533. $$ = len + 5;
  1534. }
  1535. }
  1536. } %dprec 23
  1537. | PUSH STRING CALLMETHOD SETVARIABLE {
  1538. if (!stricmp($2, "this")) {
  1539. $$ = writeByte(SWFACTION_PUSHTHIS);
  1540. $$ += writeByte(SWFACTION_CALLMETHOD);
  1541. $$ += writeByte(SWFACTION_SETVARIABLE);
  1542. } else if (!stricmp($2, "_global")) {
  1543. $$ = writeByte(SWFACTION_PUSHGLOBAL);
  1544. $$ += writeByte(SWFACTION_CALLMETHOD);
  1545. $$ += writeByte(SWFACTION_SETVARIABLE);
  1546. } else if (!stricmp($2, "UNDEF")) {
  1547. $$ = writeByte(SWFACTION_PUSHUNDEFINED);
  1548. $$ += writeByte(SWFACTION_CALLMETHOD);
  1549. $$ += writeByte(SWFACTION_SETVARIABLE);
  1550. } else {
  1551. unsigned int i;
  1552. for (i = 0; i < nConstants; ++i) {
  1553. if (strcmp(constants[i], $2) == 0) {
  1554. break;
  1555. }
  1556. }
  1557. if (i < nConstants) {
  1558. if (i < 256) {
  1559. writeByte(SWFACTION_DICTCALLMETHODSETVAR);
  1560. writeByte(1);
  1561. writeByte(0);
  1562. writeByte(i);
  1563. --numActions;
  1564. --numActions;
  1565. $$ = 4;
  1566. } else {
  1567. writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1568. writeByte(2);
  1569. writeByte(0);
  1570. writeShort(i);
  1571. $$ += writeByte(SWFACTION_CALLMETHOD);
  1572. $$ += writeByte(SWFACTION_SETVARIABLE);
  1573. $$ = 7;
  1574. }
  1575. } else {
  1576. unsigned int len = strlen($2) + 1;
  1577. writeByte(SWFACTION_PUSHSTRING);
  1578. writeShort(len);
  1579. writeString($2);
  1580. writeByte(SWFACTION_CALLMETHOD);
  1581. writeByte(SWFACTION_SETVARIABLE);
  1582. $$ = len + 5;
  1583. }
  1584. }
  1585. } %dprec 23
  1586. | PUSH FLOAT {
  1587. float val;
  1588. sscanf($2, "%f", &val);
  1589. if (val == 0.0f) {
  1590. $$ = writeByte(SWFACTION_PUSH0);
  1591. } else if (val == 1.0f) {
  1592. $$ = writeByte(SWFACTION_PUSH1);
  1593. } else {
  1594. $$ = writeByte(SWFACTION_PUSHFLOAT);
  1595. $$ += writeShort(4);
  1596. $$ += writeFloat(val);
  1597. }
  1598. }
  1599. | PUSH DOUBLE {
  1600. float val;
  1601. sscanf($2, "%f", &val);
  1602. if (val == 0.0f) {
  1603. $$ = writeByte(SWFACTION_PUSH0);
  1604. } else if (val == 1.0f) {
  1605. $$ = writeByte(SWFACTION_PUSH1);
  1606. } else {
  1607. $$ = writeByte(SWFACTION_PUSHFLOAT);
  1608. $$ += writeShort(4);
  1609. $$ += writeFloat(val);
  1610. }
  1611. }
  1612. | PUSHS STRING GETVARIABLE { $$ = writePushStringOpcodes($2, SWFACTION_PUSHSTRINGGETVAR, SWFACTION_GETVARIABLE, &numActions); }
  1613. | PUSHS STRING GETMEMBER { $$ = writePushStringOpcodes($2, SWFACTION_PUSHSTRINGGETMEMBER, SWFACTION_GETMEMBER, &numActions); }
  1614. | PUSHS STRING SETVARIABLE { $$ = writePushStringOpcodes($2, SWFACTION_PUSHSTRINGSETVAR, SWFACTION_SETVARIABLE, &numActions); }
  1615. | PUSHS STRING SETMEMBER { $$ = writePushStringOpcodes($2, SWFACTION_PUSHSTRINGSETMEMBER, SWFACTION_SETMEMBER, &numActions); }
  1616. | PUSHSDW INTEGER {
  1617. $$ = writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1618. $$ += writeShort(2);
  1619. $$ += writeShort($2);
  1620. } %dprec 21
  1621. | PUSHSDB INTEGER {
  1622. $$ = writeByte(SWFACTION_PUSHSTRINGDICTBYTE);
  1623. $$ += writeShort(1);
  1624. $$ += writeByte($2);
  1625. } %dprec 21
  1626. | PUSHSDB INTEGER GETVARIABLE {
  1627. $$ = writeByte(SWFACTION_STRINGDICTBYTEGETVAR);
  1628. $$ += writeShort(1);
  1629. $$ += writeByte($2);
  1630. --numActions;
  1631. } %dprec 22
  1632. | PUSHSDB INTEGER GETMEMBER {
  1633. $$ = writeByte(SWFACTION_STRINGDICTBYTEGETMEMBER);
  1634. $$ += writeShort(1);
  1635. $$ += writeByte($2);
  1636. --numActions;
  1637. } %dprec 22
  1638. | PUSHSDBGV INTEGER {
  1639. if (isConstant($2, "this")) {
  1640. $$ = writeByte(SWFACTION_PUSHTHISVARIABLE);
  1641. } else if (isConstant($2, "_global")) {
  1642. $$ = writeByte(SWFACTION_PUSHGLOBALVARIABLE);
  1643. } else {
  1644. $$ = writeByte(SWFACTION_STRINGDICTBYTEGETVAR);
  1645. $$ += writeShort(1);
  1646. $$ += writeByte($2);
  1647. }
  1648. }
  1649. | CALLFUNCTION POP { $$ = writeByte(SWFACTION_CALLFUNCANDPOP); --numActions; }
  1650. | CALLFUNCTION SETVARIABLE { $$ = writeByte(SWFACTION_CALLFUNCSETVAR); --numActions; }
  1651. | CALLMETHOD POP { $$ = writeByte(SWFACTION_CALLMETHODPOP); --numActions; }
  1652. | CALLMETHOD SETVARIABLE { $$ = writeByte(SWFACTION_CALLMETHODSETVAR); --numActions; }
  1653. | PUSHSDB INTEGER CALLFP {
  1654. if (isConstant($2, "AptTrace")) {
  1655. $$ = writeByte(SWFACTION_TRACESTART);
  1656. --numActions;
  1657. } else {
  1658. $$ = writeByte(SWFACTION_DICTCALLFUNCPOP);
  1659. $$ += writeShort(1);
  1660. $$ += writeByte($2);
  1661. --numActions;
  1662. }
  1663. } %dprec 40
  1664. | PUSHSDW INTEGER CALLFP {
  1665. if (isConstant($2, "AptTrace")) {
  1666. $$ = writeByte(SWFACTION_TRACESTART);
  1667. --numActions;
  1668. } else {
  1669. $$ = writeByte(SWFACTION_PUSHSTRINGDICTWORD);
  1670. $$ += writeShort(2);
  1671. $$ += writeShort($2);
  1672. $$ += writeByte(SWFACTION_CALLFUNCANDPOP);
  1673. }
  1674. } %dprec 21
  1675. | PUSHSDB INTEGER CALLFSV {
  1676. $$ = writeByte(SWFACTION_DICTCALLFUNCSETVAR);
  1677. $$ += writeShort(1);
  1678. $$ += writeByte($2);
  1679. --numActions;
  1680. } %dprec 40
  1681. | PUSHSDB INTEGER CALLMP {
  1682. $$ = writeByte(SWFACTION_DICTCALLMETHODPOP);
  1683. $$ += writeShort(1);
  1684. $$ += writeByte($2);
  1685. --numActions;
  1686. } %dprec 40
  1687. | PUSHSDB INTEGER CALLMSV {
  1688. $$ = writeByte(SWFACTION_DICTCALLMETHODSETVAR);
  1689. $$ += writeShort(1);
  1690. $$ += writeByte($2);
  1691. --numActions;
  1692. } %dprec 40
  1693. | PUSH NULLVAL { $$ = writeByte(SWFACTION_PUSHNULL); }
  1694. | PUSH UNDEFVAL { $$ = writeByte(SWFACTION_PUSHUNDEFINED); }
  1695. | PUSH TRUEVAL { $$ = writeByte(SWFACTION_PUSHTRUE); }
  1696. | PUSH FALSEVAL { $$ = writeByte(SWFACTION_PUSHFALSE); }
  1697. | LOGICALNOT LOGICALNOT {
  1698. if (mode >= MODE_UPDATE) {
  1699. /* strip double nots */
  1700. $$ = 0;
  1701. numActions -= 2;
  1702. }
  1703. else {
  1704. $$ = writeByte(SWFACTION_LOGICALNOT);
  1705. $$ += writeByte(SWFACTION_LOGICALNOT);
  1706. }
  1707. }
  1708. ;
  1709.  
  1710. opcodeScanned
  1711. : PUSHBYTE INTEGER {
  1712. $$ = writeByte(SWFACTION_PUSHBYTE);
  1713. $$ += writeShort(1);
  1714. $$ += writeByte($2);
  1715. }
  1716. | PUSHNULL { $$ = writeByte(SWFACTION_PUSHNULL); }
  1717. | PUSHUNDEF { $$ = writeByte(SWFACTION_PUSHUNDEFINED); }
  1718. | PUSHTRUE { $$ = writeByte(SWFACTION_PUSHTRUE); }
  1719. | PUSHFALSE { $$ = writeByte(SWFACTION_PUSHFALSE); }
  1720. | PUSHZEROSV { $$ = writeByte(SWFACTION_PUSHZEROSETVAR); }
  1721. | PUSHSHORT INTEGER {
  1722. $$ = writeByte(SWFACTION_PUSHWORD);
  1723. $$ += writeShort(2);
  1724. $$ += writeShort($2);
  1725. }
  1726. | PUSHLONG INTEGER {
  1727. $$ = writeByte(SWFACTION_PUSHDWORD);
  1728. $$ += writeShort(4);
  1729. $$ += writeLongInt($2);
  1730. }
  1731. | PUSHFLOAT FLOAT {
  1732. float val;
  1733. sscanf($2, "%f", &val);
  1734. $$ = writeByte(SWFACTION_PUSHFLOAT);
  1735. $$ += writeShort(4);
  1736. $$ += writeFloat(val);
  1737. }
  1738. | PUSHFLOAT DOUBLE {
  1739. float val;
  1740. sscanf($2, "%f", &val);
  1741. $$ = writeByte(SWFACTION_PUSHFLOAT);
  1742. $$ += writeShort(4);
  1743. $$ += writeFloat(val);
  1744. }
  1745. | PUSHS STRING { $$ = writePushStringOpcodes($2, SWFACTION_PUSHSTRING, SWFACTION_INVALID, &numActions); }
  1746. | PUSHONE { $$ = writeByte(SWFACTION_PUSH1); }
  1747. | PUSHZERO { $$ = writeByte(SWFACTION_PUSH0); }
  1748. | PUSHSGV STRING { $$ = writePushStringOpcodes($2, SWFACTION_PUSHSTRINGGETVAR, SWFACTION_GETVARIABLE, &numActions); }
  1749. | PUSHSGM STRING { $$ = writePushStringOpcodes($2, SWFACTION_PUSHSTRINGGETMEMBER, SWFACTION_GETMEMBER, &numActions); }
  1750. | PUSHSSV STRING { $$ = writePushStringOpcodes($2, SWFACTION_PUSHSTRINGSETVAR, SWFACTION_SETVARIABLE, &numActions); }
  1751. | PUSHSSM STRING { $$ = writePushStringOpcodes($2, SWFACTION_PUSHSTRINGSETMEMBER, SWFACTION_SETMEMBER, &numActions); }
  1752. | DCALLFP INTEGER {
  1753. $$ = writeByte(SWFACTION_DICTCALLFUNCPOP);
  1754. $$ += writeShort(1);
  1755. $$ += writeByte($2);
  1756. }
  1757. | DCALLFSV INTEGER {
  1758. $$ = writeByte(SWFACTION_DICTCALLFUNCSETVAR);
  1759. $$ += writeShort(1);
  1760. $$ += writeByte($2);
  1761. }
  1762. | DCALLMP INTEGER {
  1763. if (isConstant($2, "AptTrace")) {
  1764. $$ = writeByte(SWFACTION_TRACESTART);
  1765. --numActions;
  1766. } else {
  1767. $$ = writeByte(SWFACTION_DICTCALLMETHODPOP);
  1768. $$ += writeShort(1);
  1769. $$ += writeByte($2);
  1770. }
  1771. }
  1772. | APTTRACESTART { $$ = writeByte(SWFACTION_TRACESTART); }
  1773. | DCALLMSV INTEGER {
  1774. $$ = writeByte(SWFACTION_DICTCALLMETHODSETVAR);
  1775. $$ += writeShort(1);
  1776. $$ += writeByte($2);
  1777. }
  1778. | CALLFP { $$ = writeByte(SWFACTION_CALLFUNCANDPOP); }
  1779. | PUSHTHISGV { $$ = writeByte(SWFACTION_PUSHTHISVARIABLE); }
  1780. | PUSHGLOBALGV { $$ = writeByte(SWFACTION_PUSHGLOBALVARIABLE); }
  1781. | CALLFSV { $$ = writeByte(SWFACTION_CALLFUNCSETVAR); }
  1782. | CALLMP { $$ = writeByte(SWFACTION_CALLMETHODPOP); }
  1783. | CALLMSV { $$ = writeByte(SWFACTION_CALLMETHODSETVAR); }
  1784. | PUSHTHIS { $$ = writeByte(SWFACTION_PUSHTHIS); }
  1785. | PUSHGLOBAL { $$ = writeByte(SWFACTION_PUSHGLOBAL); }
  1786. | PUSHSDBGM INTEGER {
  1787. $$ = writeByte(SWFACTION_STRINGDICTBYTEGETMEMBER);
  1788. $$ += writeShort(1);
  1789. $$ += writeByte($2);
  1790. }
  1791. | PUSHSDBGV INTEGER {
  1792. $$ = writeByte(SWFACTION_STRINGDICTBYTEGETVAR);
  1793. $$ += writeShort(2);
  1794. $$ += writeShort($2); //needed to match... is this a bug?
  1795. }
  1796. ;
  1797. opcode
  1798. : CONSTANTS { nConstants = 0; }
  1799. constant_list { $$ = writeConstants(); }
  1800.  
  1801. | PUSH {
  1802. $$ = writeByte(SWFACTION_PUSHDATA);
  1803. /* length */
  1804. $$ += writeShort(0);
  1805. }
  1806.  
  1807. push_list {
  1808. $$ = $<num>2 + $3;
  1809. patchLength($3, $3);
  1810. }
  1811.  
  1812. | SWFACTION HEX {
  1813. if (xtoi($2)>0xff)
  1814. yyerror("Action code out of range");
  1815. $$ = writeByte((char)xtoi($2));
  1816. if (xtoi($2)>=0x80)
  1817. /* length */
  1818. $$ += writeShort(0);
  1819. }
  1820.  
  1821. hexdata_opt {
  1822. if (($4>0) && (xtoi($2)>=0x80))
  1823. patchLength($4, $4);
  1824. $$ = $<num>3 + $4;
  1825. }
  1826.  
  1827. | SETREGISTER register {
  1828. $$ = writeByte(SWFACTION_SETREGISTER);
  1829. $$ += writeShort(1);
  1830. $$ += writeByte((byte)$2);
  1831. }
  1832.  
  1833. | STRICTEQUALS { $$ = writeByte(SWFACTION_STRICTEQUALS); }
  1834. | GREATERTHAN { $$ = writeByte(SWFACTION_GREATERTHAN); }
  1835. | ENUMERATEVALUE { $$ = writeByte(SWFACTION_ENUMERATEVALUE); }
  1836. | INSTANCEOF { $$ = writeByte(SWFACTION_INSTANCEOF); }
  1837. | NEXTFRAME { $$ = writeByte(SWFACTION_NEXTFRAME); }
  1838. | PREVFRAME { $$ = writeByte(SWFACTION_PREVFRAME); }
  1839. | PLAY { $$ = writeByte(SWFACTION_PLAY); }
  1840. | STOP { $$ = writeByte(SWFACTION_STOP); }
  1841. | TOGGLEQUALITY { $$ = writeByte(SWFACTION_TOGGLEQUALITY); }
  1842. | STOPSOUNDS { $$ = writeByte(SWFACTION_STOPSOUNDS); }
  1843. | CALLFUNCTION { $$ = writeByte(SWFACTION_CALLFUNCTION); }
  1844. | RETURN { $$ = writeByte(SWFACTION_RETURN); }
  1845. | NEWMETHOD { $$ = writeByte(SWFACTION_NEWMETHOD); }
  1846. | CALLMETHOD { $$ = writeByte(SWFACTION_CALLMETHOD); }
  1847. | BITWISEAND { $$ = writeByte(SWFACTION_BITWISEAND); }
  1848. | BITWISEOR { $$ = writeByte(SWFACTION_BITWISEOR); }
  1849. | BITWISEXOR { $$ = writeByte(SWFACTION_BITWISEXOR); }
  1850. | MODULO { $$ = writeByte(SWFACTION_MODULO); }
  1851. | NEWADD { $$ = writeByte(SWFACTION_NEWADD); }
  1852. | NEWLESSTHAN { $$ = writeByte(SWFACTION_NEWLESSTHAN); }
  1853. | NEWEQUALS { $$ = writeByte(SWFACTION_NEWEQUALS); }
  1854. | TONUMBER { $$ = writeByte(SWFACTION_TONUMBER); }
  1855. | TOSTRING { $$ = writeByte(SWFACTION_TOSTRING); }
  1856. | INCREMENT { $$ = writeByte(SWFACTION_INCREMENT); }
  1857. | DECREMENT { $$ = writeByte(SWFACTION_DECREMENT); }
  1858. | TYPEOF { $$ = writeByte(SWFACTION_TYPEOF); }
  1859. | TARGETPATH { $$ = writeByte(SWFACTION_TARGETPATH); }
  1860. | ENUMERATE { $$ = writeByte(SWFACTION_ENUMERATE); }
  1861. | DELETE { $$ = writeByte(SWFACTION_DELETE); }
  1862. | DELETE2 { $$ = writeByte(SWFACTION_DELETE2); }
  1863. | NEW { $$ = writeByte(SWFACTION_NEW); }
  1864. | INITARRAY { $$ = writeByte(SWFACTION_INITARRAY); }
  1865. | INITOBJECT { $$ = writeByte(SWFACTION_INITOBJECT); }
  1866. | GETMEMBER { $$ = writeByte(SWFACTION_GETMEMBER); }
  1867. | SETMEMBER { $$ = writeByte(SWFACTION_SETMEMBER); }
  1868. | SHIFTLEFT { $$ = writeByte(SWFACTION_SHIFTLEFT); }
  1869. | SHIFTRIGHT { $$ = writeByte(SWFACTION_SHIFTRIGHT); }
  1870. | SHIFTRIGHT2 { $$ = writeByte(SWFACTION_SHIFTRIGHT2); }
  1871. | VAR { $$ = writeByte(SWFACTION_VAR); }
  1872. | VAREQUALS { $$ = writeByte(SWFACTION_VAREQUALS); }
  1873. | OLDADD { $$ = writeByte(SWFACTION_ADD); }
  1874. | SUBTRACT { $$ = writeByte(SWFACTION_SUBTRACT); }
  1875. | MULTIPLY { $$ = writeByte(SWFACTION_MULTIPLY); }
  1876. | DIVIDE { $$ = writeByte(SWFACTION_DIVIDE); }
  1877. | OLDEQUALS { $$ = writeByte(SWFACTION_EQUALS); }
  1878. | OLDLESSTHAN { $$ = writeByte(SWFACTION_LESSTHAN); }
  1879. | LOGICALAND { $$ = writeByte(SWFACTION_LOGICALAND); }
  1880. | LOGICALOR { $$ = writeByte(SWFACTION_LOGICALOR); }
  1881. | LOGICALNOT { $$ = writeByte(SWFACTION_LOGICALNOT); }
  1882. | STRINGEQ { $$ = writeByte(SWFACTION_STRINGEQ); }
  1883. | STRINGLENGTH { $$ = writeByte(SWFACTION_STRINGLENGTH); }
  1884. | SUBSTRING { $$ = writeByte(SWFACTION_SUBSTRING); }
  1885. | INT { $$ = writeByte(SWFACTION_INT); }
  1886. | DUP { $$ = writeByte(SWFACTION_DUP); }
  1887. | SWAP { $$ = writeByte(SWFACTION_SWAP); }
  1888. | POP { $$ = writeByte(SWFACTION_POP); }
  1889. | GETVARIABLE { $$ = writeByte(SWFACTION_GETVARIABLE); }
  1890. | SETVARIABLE { $$ = writeByte(SWFACTION_SETVARIABLE); }
  1891. | STRINGCONCAT { $$ = writeByte(SWFACTION_STRINGCONCAT); }
  1892. | GETPROPERTY { $$ = writeByte(SWFACTION_GETPROPERTY); }
  1893. | SETPROPERTY { $$ = writeByte(SWFACTION_SETPROPERTY); }
  1894. | DUPLICATECLIP { $$ = writeByte(SWFACTION_DUPLICATECLIP); }
  1895. | REMOVECLIP { $$ = writeByte(SWFACTION_REMOVECLIP); }
  1896. | TRACE { $$ = writeByte(SWFACTION_TRACE); }
  1897. | STARTDRAGMOVIE { $$ = writeByte(SWFACTION_STARTDRAGMOVIE); }
  1898. | STOPDRAGMOVIE { $$ = writeByte(SWFACTION_STOPDRAGMOVIE); }
  1899. | STRINGLESSTHAN { $$ = writeByte(SWFACTION_STRINGLESSTHAN); }
  1900. | STRINGGREATERTHAN { $$ = writeByte(SWFACTION_STRINGGREATERTHAN);}
  1901. | RANDOM { $$ = writeByte(SWFACTION_RANDOM); }
  1902. | MBLENGTH { $$ = writeByte(SWFACTION_MBLENGTH); }
  1903. | ORD { $$ = writeByte(SWFACTION_ORD); }
  1904. | CHR { $$ = writeByte(SWFACTION_CHR); }
  1905. | GETTIMER { $$ = writeByte(SWFACTION_GETTIMER); }
  1906. | MBSUBSTRING { $$ = writeByte(SWFACTION_MBSUBSTRING); }
  1907. | MBORD { $$ = writeByte(SWFACTION_MBORD); }
  1908. | MBCHR { $$ = writeByte(SWFACTION_MBCHR); }
  1909. | IMPLEMENTS { $$ = writeByte(SWFACTION_IMPLEMENTS); }
  1910. | EXTENDS { $$ = writeByte(SWFACTION_EXTENDS); }
  1911. | THROW { $$ = writeByte(SWFACTION_THROW); }
  1912. | CAST { $$ = writeByte(SWFACTION_CAST); }
  1913.  
  1914. | CALLFRAME {
  1915. $$ = writeByte(SWFACTION_CALLFRAME);
  1916. $$ += writeShort(0);
  1917. }
  1918.  
  1919. | GOTOANDSTOP {
  1920. $$ = writeByte(SWFACTION_GOTOEXPRESSION);
  1921. $$ += writeShort(1);
  1922. $$ += writeByte(0);
  1923. }
  1924.  
  1925. | GOTOANDSTOP SKIP INTEGER {
  1926. $$ = writeByte(SWFACTION_GOTOEXPRESSION);
  1927. $$ += writeShort(3);
  1928. $$ += writeByte(2);
  1929. $$ += writeShort($3);
  1930. }
  1931.  
  1932. | GOTOANDPLAY {
  1933. $$ = writeByte(SWFACTION_GOTOEXPRESSION);
  1934. $$ += writeShort(1);
  1935. $$ += writeByte(1);
  1936. }
  1937.  
  1938. | GOTOANDPLAY SKIP INTEGER {
  1939. $$ = writeByte(SWFACTION_GOTOEXPRESSION);
  1940. $$ += writeShort(3);
  1941. $$ += writeByte(3);
  1942. $$ += writeShort($3);
  1943. }
  1944.  
  1945. | GOTOLABEL STRING {
  1946. $$ = writeByte(SWFACTION_GOTOLABEL);
  1947. $$ += writeShort(strlen($2)+1);
  1948. $$ += writeString($2);
  1949. }
  1950.  
  1951. | BRANCHALWAYS STRING {
  1952. $$ = writeByte(SWFACTION_BRANCHALWAYS);
  1953. $$ += writeShort(2);
  1954. $$ += branchTarget($2);
  1955. }
  1956.  
  1957. | BRANCHALWAYS INTEGER {
  1958. $$ = writeByte(SWFACTION_BRANCHALWAYS);
  1959. $$ += writeShort(2);
  1960. $$ += addNumLabel($2);
  1961. }
  1962.  
  1963. | BRANCHIFTRUE STRING {
  1964. $$ = writeByte(SWFACTION_BRANCHIFTRUE);
  1965. $$ += writeShort(2);
  1966. $$ += branchTarget($2);
  1967. }
  1968.  
  1969. | BRANCHIFTRUE INTEGER {
  1970. $$ = writeByte(SWFACTION_BRANCHIFTRUE);
  1971. $$ += writeShort(2);
  1972. $$ += addNumLabel($2);
  1973. }
  1974.  
  1975. | BRANCHIFFALSE STRING {
  1976. $$ = writeByte(SWFACTION_BRANCHIFFALSE);
  1977. $$ += writeShort(2);
  1978. $$ += branchTarget($2);
  1979. }
  1980.  
  1981. | BRANCHIFFALSE INTEGER {
  1982. $$ = writeByte(SWFACTION_BRANCHIFFALSE);
  1983. $$ += writeShort(2);
  1984. $$ += addNumLabel($2);
  1985. }
  1986.  
  1987. | GOTOFRAME INTEGER {
  1988. $$ = writeByte(SWFACTION_GOTOFRAME);
  1989. $$ += writeShort(2);
  1990. $$ += writeShort($2);
  1991. }
  1992.  
  1993. | GETURL STRING STRING {
  1994. $$ = writeByte(SWFACTION_GETURL);
  1995. $$ += writeShort(strlen($2)+strlen($3)+2);
  1996. $$ += writeString($2);
  1997. $$ += writeString($3);
  1998. }
  1999.  
  2000. | GETURL2 urlmethod {
  2001. $$ = writeByte(SWFACTION_GETURL2);
  2002. $$ += writeShort(1);
  2003. $$ += writeByte($2);
  2004. }
  2005.  
  2006. | LOADVARIABLES urlmethod {
  2007. $$ = writeByte(SWFACTION_GETURL2);
  2008. $$ += writeShort(1);
  2009. $$ += writeByte(0xc0 + $2);
  2010. }
  2011.  
  2012. | LOADVARIABLESNUM urlmethod {
  2013. $$ = writeByte(SWFACTION_GETURL2);
  2014. $$ += writeShort(1);
  2015. $$ += writeByte(0x80 + $2);
  2016. }
  2017.  
  2018. | LOADMOVIE urlmethod {
  2019. $$ = writeByte(SWFACTION_GETURL2);
  2020. $$ += writeShort(1);
  2021. $$ += writeByte(0x40 + $2);
  2022. }
  2023.  
  2024. | LOADMOVIENUM urlmethod {
  2025. $$ = writeByte(SWFACTION_GETURL2);
  2026. $$ += writeShort(1);
  2027. $$ += writeByte($2);
  2028. }
  2029.  
  2030. | STRICTMODE ON {
  2031. $$ = writeByte(SWFACTION_STRICTMODE);
  2032. $$ += writeShort(1);
  2033. $$ += writeByte(1);
  2034. }
  2035.  
  2036. | STRICTMODE OFF {
  2037. $$ = writeByte(SWFACTION_STRICTMODE);
  2038. $$ += writeShort(1);
  2039. $$ += writeByte(0);
  2040. }
  2041.  
  2042. | MOVIE STRING { yyerror("Movie declaration inside of the action block"); }
  2043. ;
  2044.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement