1 50 51 package org.openlaszlo.iv.flash.api.action; 52 53 import java.io.PrintStream ; 54 55 import org.openlaszlo.iv.flash.util.*; 56 import org.openlaszlo.iv.flash.parser.*; 57 import org.openlaszlo.iv.flash.api.*; 58 import org.openlaszlo.iv.flash.context.Context; 59 60 70 public final class Program extends FlashObject { 71 72 public static final int PROP_X = 0; 74 public static final int PROP_Y = 1; 75 public static final int PROP_XSCALE = 2; 76 public static final int PROP_YSCALE = 3; 77 public static final int PROP_CURRENTFRAME = 4; 78 public static final int PROP_TOTALFRAMES = 5; 79 public static final int PROP_ALPHA = 6; 80 public static final int PROP_VISIBLE = 7; 81 public static final int PROP_WIDTH = 8; 82 public static final int PROP_HEIGHT = 9; 83 public static final int PROP_ROTATION = 10; 84 public static final int PROP_TARGET = 11; 85 public static final int PROP_FRAMESLOADED = 12; 86 public static final int PROP_NAME = 13; 87 public static final int PROP_DROPTARGET = 14; 88 public static final int PROP_URL = 15; 89 public static final int PROP_HIGHQUALITY = 16; 90 public static final int PROP_FOCUSRECT = 17; 91 public static final int PROP_SOUNDBUFTIME = 18; 92 public static final int PROP_QUALITY = 19; 93 public static final int PROP_XMOUSE = 20; 94 public static final int PROP_YMOUSE = 21; 95 96 private FlashBuffer body; 97 98 101 public Program() { 102 body = new FlashBuffer(50); 103 } 104 105 112 public Program( FlashBuffer body ) { 113 this.body = body; 114 } 115 116 125 public Program( byte[] buf, int start, int end ) { 126 int bufLength = end-start; 127 byte[] myBuf = new byte[bufLength]; 128 System.arraycopy(buf, start, myBuf, 0, bufLength); 129 body = new FlashBuffer( myBuf, bufLength ); 130 } 131 132 public int getTag() { 133 return -1; 134 } 135 136 147 public void apply( Context context ) { 148 int[] new_offs = new int[getLength()]; 149 FlashBuffer fob = new FlashBuffer(getLength()+10); 150 151 ForwardRef[] forward_refs = new ForwardRef[] { null }; 152 setPos(0); 153 Loop: 154 for(;;) { 155 int curPos = getPos(); 156 boolean isFRef = new_offs[curPos] == -1; 157 new_offs[curPos] = fob.getPos(); 158 if( isFRef ) resolveForwardReferences(forward_refs, fob); 159 int code = getUByte(); 160 boolean hasLength = (code&0x80) != 0; 161 int length = hasLength? getUWord(): 0; 162 fob.writeByte(code); 163 int nextPos = getPos()+length; 164 165 switch( code ) { 166 case Actions.None: 167 setPos(nextPos); 168 break Loop; 169 case Actions.GotoFrame: 170 fob.writeWord(2); 171 fob.writeWord(getUWord()); 172 break; 173 case Actions.GetURL: { 174 String url = getString(); 175 String target = getString(); 176 url = context.apply(url); 177 target = context.apply(target); 178 fob.writeWord(url.length()+target.length()+2); fob.writeStringZ(url); 180 fob.writeStringZ(target); 181 break; 182 } 183 case Actions.WaitForFrame: 184 fob.writeWord(3); 185 fob.writeWord(getUWord()); 186 fob.writeByte(getUByte()); 187 break; 188 case Actions.SetTarget: { 189 String target = getString(); 190 target = context.apply(target); 191 fob.writeWord(target.length()+1); fob.writeStringZ(target); 193 break; 194 } 195 case Actions.GotoLabel: { 196 String label = getString(); 197 label = context.apply(label); 198 fob.writeWord(label.length()+1); fob.writeStringZ(label); 200 break; 201 } 202 case Actions.PushData: { 203 int start = getPos(); 205 int l = length; 206 while( --l >= 0 ) { 207 if( getUByte() == '{' ) break; 208 } 209 setPos( start ); 211 if( l <= 0 ) { fob.writeWord(length); 213 body.getTo(fob, length); 214 } else { FlashBuffer fb = new FlashBuffer( length+5 ); 216 while( getPos() < nextPos ) { 217 int type = getUByte(); 218 fb.writeByte( type ); 219 switch( type ) { 220 case 0: fb.writeStringZ( context.apply( getString() ) ); 222 break; 223 case 1: fb.writeDWord( getUDWord() ); 225 break; 226 case 2: break; 228 case 3: break; 230 case 4: fb.writeByte( getUByte() ); 232 break; 233 case 5: fb.writeByte( getUByte() ); 235 break; 236 case 6: fb.writeDWord( getUDWord() ); 238 fb.writeDWord( getUDWord() ); 239 break; 240 case 7: fb.writeDWord( getUDWord() ); 242 break; 243 case 8: fb.writeByte( getUByte() ); 245 break; 246 case 9: fb.writeWord( getUWord() ); 248 break; 249 default: 250 body.getTo(fb, nextPos-getPos()); 254 break; 255 } 256 } 257 fob.writeWord( fb.getSize() ); 258 fob.writeFOB( fb ); 259 } 260 break; 261 } 262 case Actions.JumpIfTrue: 263 case Actions.Jump: { 264 fob.writeWord(2); 265 int offset = getWord(); 266 int target_off = getPos()+offset; 267 if( offset <= 0 ) { 268 int new_off = new_offs[target_off] - (fob.getPos()+2); fob.writeWord(new_off); 270 } else { 271 new_offs[target_off] = -1; addForwardRef( forward_refs, new ForwardRef( fob.getPos(), target_off ) ); 273 fob.skip(2); 274 } 275 break; 276 } 277 case Actions.GotoExpression: 278 case Actions.GetURL2: 279 case Actions.WaitForFrameExpression: 280 fob.writeWord(1); 281 fob.writeByte(getUByte()); 282 break; 283 case Actions.CallFrame: 284 fob.writeWord(0); 285 break; 286 case Actions.ConstantPool: { 287 int num = getUWord(); 288 String [] strings = new String [num]; 289 int len = 2; 290 for( int i=0; i<num; i++ ) { 291 String c = getString(); 292 c = context.apply(c); 293 strings[i] = c; 294 len += c.length()+1; 295 } 296 fob.writeWord(len); 297 fob.writeWord(num); 298 for( int i=0; i<num; i++ ) { 299 fob.writeStringZ(strings[i]); 300 } 301 break; 302 } 303 case Actions.With: { 304 String with = getString(); 305 with = context.apply(with); 306 fob.writeWord(with.length()+1); 307 fob.writeStringZ(with); 308 break; 309 } 310 case Actions.DefineFunction: { 313 fob.writeWord(length); fob.writeStringZ(getString()); 315 int num = getUWord(); 316 fob.writeWord(num); 317 for( int i=0; i<num; i++ ) fob.writeStringZ(getString()); 318 int codesize = getUWord(); 319 int target_off = getPos()+codesize; 320 new_offs[target_off] = -1; addForwardRef( forward_refs, new ForwardRef( fob.getPos(), target_off ) ); 322 fob.skip(2); 323 break; 324 } 325 default: 326 if( hasLength ) { 327 fob.writeWord(length); 328 body.getTo(fob, length); 329 } 330 break; 331 } 332 setPos(nextPos); 333 } 334 body = fob; 335 } 336 337 342 public int getLength() { 343 return body.getSize()+1; 344 } 345 346 public void write( FlashOutput fob ) { 347 fob.writeFOB( body ); 348 fob.writeByte(0); } 350 351 public void printContent( PrintStream out, String indent ) { 352 int origPos = getPos(); 353 try { 354 out.println( indent+"Actions: " ); 355 setPos(0); 356 357 String [] cpool = null; 358 359 for(;;) { 360 int offset = getPos(); 361 int code = getUByte(); 362 boolean hasLength = (code&0x80) != 0; 363 int length = hasLength? getUWord(): 0; 364 int nextPos = getPos()+length; 365 366 out.print( indent+" "+Util.w2h(offset)+": "+Actions.getActionName(code)+" " ); 367 switch( code ) { 368 case Actions.None: 369 out.println(); 370 setPos(nextPos); 371 return; 372 case Actions.GotoFrame: 373 out.println( getUWord() ); 374 break; 375 case Actions.GetURL: 376 out.println( "url='"+getString()+"' target='"+getString()+"'" ); 377 break; 378 case Actions.WaitForFrame: 379 out.println( "frame="+getUWord()+" skipcount="+getUByte() ); 380 break; 381 case Actions.SetTarget: 382 out.println( "target='"+getString()+"'" ); 383 break; 384 case Actions.GotoLabel: 385 out.println( "label='"+getString()+"'" ); 386 break; 387 case Actions.PushData: { 388 out.println( "values: " ); 389 for( int l=length; l>0; ) { 390 int type = getUByte(); 391 l--; 392 switch( type ) { 393 case 0: 394 String ss = getString(); 395 out.println( indent+" string='"+ss+"'" ); 396 l-=ss.length()+1; 397 break; 398 case 1: 399 float flt = Float.intBitsToFloat(getUDWord()); 400 out.println( indent+" float="+flt ); 401 l-=4; 402 break; 403 case 2: 404 out.println( indent+" NULL" ); 405 break; 406 case 3: 407 out.println( indent+" undefined" ); 408 break; 409 case 4: 410 out.println( indent+" register="+getUByte() ); 411 l--; 412 break; 413 case 5: 414 out.println( indent+" boolean="+(getUByte()!=0) ); 415 l--; 416 break; 417 case 6: 418 long dbits = ( ((long)getUDWord())<<32 ) | (((long)getUDWord())&0xffffffffL); 419 double dbl = Double.longBitsToDouble(dbits); 420 out.println( indent+" double="+dbl ); 421 l-=8; 422 break; 423 case 7: 424 int ival = getUDWord(); 425 out.println( indent+" int="+ival+" (hex: "+Util.d2h(ival)+")" ); 426 l-=4; 427 break; 428 case 8: { 429 int idx = getUByte(); 430 String val = cpool!=null&&idx<cpool.length? cpool[idx]: "<<<error>>>"; 431 out.println( indent+" pool_index="+idx+" -> "+val ); 432 l--; 433 break; 434 } 435 case 9: { 436 int idx = getUWord(); 437 String val = cpool!=null&&idx<cpool.length? cpool[idx]: "<<<error>>>"; 438 out.println( indent+" pool_index="+idx+" -> "+val ); 439 l-=2; 440 break; 441 } 442 } 443 } 444 break; 445 } 446 case Actions.JumpIfTrue: 447 case Actions.Jump: { 448 int off = getWord(); 449 out.println( "offset="+off+" (goto "+Util.w2h(getPos()+off)+")" ); 450 break; 451 } 452 case Actions.GotoExpression: 453 case Actions.GetURL2: 454 case Actions.WaitForFrameExpression: 455 out.println( "byte="+getUByte() ); 456 break; 457 case Actions.ConstantPool: { 458 int num = getUWord(); 459 cpool = new String [num]; 460 out.println( "constants="+num ); 461 for( int i=0; i<num; i++ ) { 462 out.println( indent+" constpool["+i+"]='"+(cpool[i]=getString())+"'" ); 463 } 464 break; 465 } 466 case Actions.DefineFunction: { 468 String name = getString(); 469 int num = getUWord(); 470 out.print( "function "+name+"( " ); 471 for( int i=0; i<num; i++ ) { 472 out.print( getString() ); 473 if( i != num-1 ) out.print( ", " ); 474 } 475 int codesize = getUWord(); 476 out.println( " ) codesize="+codesize+" (until "+Util.w2h(getPos()+codesize)+")" ); 477 break; 478 } 479 case Actions.With: 480 out.println( "withblock='"+getString()+"'" ); 481 break; 482 default: 483 out.println(); 485 break; 486 } 487 488 if (nextPos >= body.getBuf().length) { 493 return; 494 } 495 496 setPos(nextPos); 497 } 498 } finally { 499 setPos(origPos); 500 } 501 } 502 503 protected boolean _isConstant() { 504 setPos(0); 505 506 for(;;) { 507 int code = getUByte(); 508 boolean hasLength = (code&0x80) != 0; 509 int length = hasLength? getUWord(): 0; 510 int pos = getPos(); 511 512 switch( code ) { 513 case Actions.None: 514 return true; 515 case Actions.GetURL: 516 if( Util.hasVar(getString()) || Util.hasVar(getString()) ) return false; 517 break; 518 case Actions.SetTarget: 519 case Actions.GotoLabel: 520 if( Util.hasVar(getString()) ) return false; 521 break; 522 case Actions.PushData: { 523 int l = length; 525 while( --l >= 0 ) { 526 if( getUByte() == '{' ) return false; 527 } 528 531 break; 532 } 533 case Actions.ConstantPool: { 534 int num = getUWord(); 535 for( int i=0; i<num; i++ ) { 536 if( Util.hasVar(getString()) ) return false; 537 } 538 break; 539 } 540 case Actions.With: 541 if( Util.hasVar(getString()) ) return false; 542 break; 543 } 544 setPos( pos+length ); 545 } 546 } 547 548 public FlashItem getCopy( ScriptCopier copier ) { 549 return new Program( body.getCopy() ); 550 } 551 552 public FlashBuffer body() { 553 return body; 554 } 555 556 560 564 public void none() { 565 body.writeByte( Actions.None ); 566 } 567 568 572 public void nextFrame() { 573 body.writeByte( Actions.NextFrame ); 574 } 575 576 580 public void prevFrame() { 581 body.writeByte( Actions.PrevFrame ); 582 } 583 584 588 public void play() { 589 body.writeByte( Actions.Play ); 590 } 591 592 596 public void stop() { 597 body.writeByte( Actions.Stop ); 598 } 599 600 609 public void eval() { 610 body.writeByte( Actions.Eval ); 611 } 612 613 619 public void getVar() { 620 eval(); 621 } 622 623 636 public void setVar() { 637 body.writeByte( Actions.SetVariable ); 638 } 639 640 644 public void toggleQuality() { 645 body.writeByte( Actions.ToggleQuality ); 646 } 647 648 652 public void stopSounds() { 653 body.writeByte( Actions.StopSounds ); 654 } 655 656 668 public void add() { 669 body.writeByte( Actions.Add ); 670 } 671 672 684 public void subtract() { 685 body.writeByte( Actions.Subtract ); 686 } 687 688 700 public void multiply() { 701 body.writeByte( Actions.Multiply ); 702 } 703 704 718 public void divide() { 719 body.writeByte( Actions.Divide ); 720 } 721 722 737 public void equal() { 738 body.writeByte( Actions.Equal ); 739 } 740 741 755 public void lessThan() { 756 body.writeByte( Actions.LessThan ); 757 } 758 759 772 public void logicalAnd() { 773 body.writeByte( Actions.LogicalAnd ); 774 } 775 788 public void logicalOr() { 789 body.writeByte( Actions.LogicalOr ); 790 } 791 792 811 public void logicalNot() { 812 body.writeByte( Actions.LogicalNot ); 813 } 814 815 829 public void stringEqual() { 830 body.writeByte( Actions.StringEqual ); 831 } 832 833 842 public void stringLength() { 843 body.writeByte( Actions.StringLength ); 844 } 845 846 859 public void stringLessThan() { 860 body.writeByte( Actions.StringLessThan ); 861 } 862 863 877 public void subString() { 878 body.writeByte( Actions.SubString ); 879 } 880 881 891 public void addString() { 892 body.writeByte( Actions.StringConcat ); 893 } 894 895 906 public void mbLength() { 907 body.writeByte( Actions.MBLength ); 908 } 909 910 923 public void mbChr() { 924 body.writeByte( Actions.MBChr ); 925 } 926 927 940 public void mbOrd() { 941 body.writeByte( Actions.MBOrd ); 942 } 943 944 960 public void mbSubString() { 961 body.writeByte( Actions.MBSubString ); 962 } 963 964 975 public void toInt() { 976 body.writeByte( Actions.Int ); 977 } 978 979 989 public void ord() { 990 body.writeByte( Actions.Ord ); 991 } 992 993 1003 public void chr() { 1004 body.writeByte( Actions.Chr ); 1005 } 1006 1007 1018 public void setTarget() { 1019 body.writeByte( Actions.SetTargetExpression ); 1020 } 1021 1022 1033 public void getProperty() { 1034 body.writeByte( Actions.GetProperty ); 1035 } 1036 1037 1049 public void setProperty() { 1050 body.writeByte( Actions.SetProperty ); 1051 } 1052 1053 1065 public void cloneClip() { 1066 body.writeByte( Actions.DuplicateClip ); 1067 } 1068 1069 1078 public void removeClip() { 1079 body.writeByte( Actions.RemoveClip ); 1080 } 1081 1082 1102 public void startDrag() { 1103 body.writeByte( Actions.StartDragMovie ); 1104 } 1105 1106 1114 public void endDrag() { 1115 body.writeByte( Actions.StopDragMovie ); 1116 } 1117 1118 1128 public void random() { 1129 body.writeByte( Actions.Random ); 1130 } 1131 1132 1141 public void getTimer() { 1142 body.writeByte( Actions.GetTimer ); 1143 } 1144 1145 1151 public void gotoFrame( int frame ) { 1152 body.writeByte( Actions.GotoFrame ); 1153 body.writeWord(2); 1154 body.writeWord(frame); 1155 } 1156 1157 1169 public void getURL( String url, String target ) { 1170 body.writeByte( Actions.GetURL ); 1171 body.writeWord((url==null?0:url.length())+(target==null?0:target.length())+2); body.writeStringZ(url==null?"":url); 1173 body.writeStringZ(target==null?"":target); 1174 } 1175 1176 1184 public void waitForFrame( int frame, int skip ) { 1185 body.writeByte( Actions.WaitForFrame ); 1186 body.writeWord(3); 1187 body.writeWord(frame); 1188 body.writeByte(skip); 1189 } 1190 1191 1213 public void setTarget( String target ) { 1214 body.writeByte( Actions.SetTarget ); 1215 body.writeWord(target.length()+1); body.writeStringZ(target); 1217 } 1218 1219 1226 public void gotoLabel( String label ) { 1227 body.writeByte( Actions.GotoLabel ); 1228 body.writeWord(label.length()+1); body.writeStringZ(label); 1230 } 1231 1232 1236 public void pop() { 1237 body.writeByte( Actions.Pop ); 1238 } 1239 1240 1246 public void push( String data ) { 1247 body.writeByte( Actions.PushData ); 1248 body.writeWord(data.length()+1+1); 1249 body.writeByte(0); 1250 body.writeStringZ(data); 1251 } 1252 1253 1259 public void push( float data ) { 1260 body.writeByte( Actions.PushData ); 1261 body.writeWord(4+1); 1262 body.writeByte(1); 1263 body.writeDWord( Float.floatToIntBits(data) ); 1264 } 1265 1266 1272 public void push( int data ) { 1273 body.writeByte( Actions.PushData ); 1274 body.writeWord(4+1); 1275 body.writeByte(7); 1276 body.writeDWord( data ); 1277 } 1278 1279 1284 public void push( Short const_idx ) { 1285 body.writeByte(Actions.PushData); 1286 int idx = const_idx.intValue(); 1287 if( idx > 255 ) { 1288 body.writeWord(3); 1289 body.writeByte(9); 1290 body.writeWord(idx); 1291 } else { 1292 body.writeWord(2); 1293 body.writeByte(8); 1294 body.writeByte(idx); 1295 } 1296 } 1297 1298 1314 public void push( Object [] data ) { 1315 FlashBuffer fb = new FlashBuffer(40); 1316 for( int i=0; i<data.length; i++ ) { 1317 Object o = data[i]; 1318 if( o instanceof String ) { 1319 fb.writeByte(0); 1320 fb.writeStringZ((String )o); 1321 } else if( o instanceof Float ) { 1322 fb.writeByte(1); 1323 fb.writeDWord( Float.floatToIntBits(((Float )o).floatValue()) ); 1324 } else if( o instanceof Boolean ) { 1325 fb.writeByte(5); 1326 fb.writeByte(((Boolean )o).booleanValue()?1:0); 1327 } else if( o instanceof Double ) { 1328 fb.writeByte(6); 1329 long dbits = Double.doubleToLongBits(((Double )o).doubleValue()); 1330 fb.writeDWord((int)(dbits>>>32)); 1331 fb.writeDWord((int)(dbits&0xffffffffL)); 1332 } else if( o instanceof Integer ) { 1333 fb.writeByte(7); 1334 fb.writeDWord(((Integer )o).intValue()); 1335 } else if( o instanceof Short || o instanceof Byte ) { 1336 int idx = ((Number )o).intValue(); 1337 if( idx > 255 ) { 1338 fb.writeByte(9); 1339 fb.writeWord(idx); 1340 } else { 1341 fb.writeByte(8); 1342 fb.writeByte(idx); 1343 } 1344 } else if( o == null ) { 1345 fb.writeByte(2); 1346 } 1347 } 1348 body.writeByte(Actions.PushData); 1349 body.writeWord(fb.getSize()); 1350 body.writeFOB(fb); 1351 } 1352 1353 1369 public void push( Object o ) { 1370 body.writeByte(Actions.PushData); 1371 if( o instanceof String ) { 1372 body.writeWord(((String )o).length()+2); 1373 body.writeByte(0); 1374 body.writeStringZ((String )o); 1375 } else if( o instanceof Float ) { 1376 body.writeWord(4+1); 1377 body.writeByte(1); 1378 body.writeDWord( Float.floatToIntBits(((Float )o).floatValue()) ); 1379 } else if( o instanceof Boolean ) { 1380 body.writeWord(1+1); 1381 body.writeByte(5); 1382 body.writeByte(((Boolean )o).booleanValue()?1:0); 1383 } else if( o instanceof Double ) { 1384 body.writeWord(8+1); 1385 body.writeByte(6); 1386 long dbits = Double.doubleToLongBits(((Double )o).doubleValue()); 1387 body.writeDWord((int)(dbits>>>32)); 1388 body.writeDWord((int)(dbits&0xffffffffL)); 1389 } else if( o instanceof Integer ) { 1390 body.writeWord(4+1); 1391 body.writeByte(7); 1392 body.writeDWord(((Integer )o).intValue()); 1393 } else if( o instanceof Short || o instanceof Byte ) { 1394 int idx = ((Number )o).intValue(); 1395 if( idx > 255 ) { 1396 body.writeWord(2+1); 1397 body.writeByte(9); 1398 body.writeWord(idx); 1399 } else { 1400 body.writeWord(1+1); 1401 body.writeByte(8); 1402 body.writeByte(idx); 1403 } 1404 } else if( o == null ) { 1405 body.writeWord(0+1); 1406 body.writeByte(2); 1407 } 1408 } 1409 1410 1422 public void jump( int offset ) { 1423 body.writeByte( Actions.Jump ); 1424 body.writeWord(2); 1425 body.writeWord(offset); 1426 } 1427 1428 1443 public void jumpIfTrue( int offset ) { 1444 body.writeByte( Actions.JumpIfTrue ); 1445 body.writeWord(2); 1446 body.writeWord(offset); 1447 } 1448 1449 1467 public void callFrame() { 1468 body.writeByte( Actions.CallFrame ); 1469 body.writeWord(0); 1470 } 1471 1472 1494 public void getURL( int method ) { 1495 body.writeByte( Actions.GetURL2 ); 1496 body.writeWord(1); 1497 body.writeByte(method); 1498 } 1499 1500 1512 public void getURL_GET() { 1513 getURL(1); 1514 } 1515 1516 1528 public void getURL_POST() { 1529 getURL(2); 1530 } 1531 1532 1546 public void gotoFrameAndStop() { 1547 body.writeByte( Actions.GotoExpression ); 1548 body.writeWord(1); 1549 body.writeByte(0x00); 1550 } 1551 1552 1566 public void gotoFrameAndPlay() { 1567 body.writeByte( Actions.GotoExpression ); 1568 body.writeWord(1); 1569 body.writeByte(0x80); 1570 } 1571 1572 1585 public void waitForFrameAndSkip( int skip ) { 1586 body.writeByte( Actions.WaitForFrameExpression ); 1587 body.writeWord(1); 1588 body.writeByte(skip); 1589 } 1590 1591 1592 1593 1599 public void addConstantPool( String [] constants ) { 1600 int size = 2; 1601 for( int i=0; i<constants.length; i++ ) { 1602 size += constants[i].length()+1; 1603 } 1604 body.writeByte(Actions.ConstantPool); 1605 body.writeWord(size); 1606 body.writeWord(constants.length); 1607 for( int i=0; i<constants.length; i++ ) { 1608 body.writeStringZ(constants[i]); 1609 } 1610 } 1611 1612 1616 public void newObject() { 1617 body.writeByte(Actions.NewObject); 1618 } 1619 1620 1626 public void callFunction() { 1627 body.writeByte( Actions.CallFunction ); 1628 } 1629 1630 1636 public void callMethod() { 1637 body.writeByte( Actions.CallMethod ); 1638 } 1639 1640 1646 public void getMember() { 1647 body.writeByte( Actions.GetMember ); 1648 } 1649 1650 1656 public void setMember() { 1657 body.writeByte( Actions.SetMember ); 1658 } 1659 1660 1663 static class ForwardRef { 1664 ForwardRef next; 1665 int jumpOffset; 1666 int targetOffset; 1667 ForwardRef( int jumpOffset, int targetOffset ) { 1668 this.jumpOffset = jumpOffset; 1669 this.targetOffset = targetOffset; 1670 } 1671 } 1672 1673 private void addForwardRef( ForwardRef[] forward_refs, ForwardRef fref ) { 1674 fref.next = forward_refs[0]; 1675 forward_refs[0] = fref; 1676 } 1677 1678 private void resolveForwardReferences( ForwardRef[] forward_refs, FlashBuffer fob ) { 1680 ForwardRef pred = null; 1681 ForwardRef cur = forward_refs[0]; 1682 int curPos = getPos(); 1683 while( cur != null ) { 1684 if( cur.targetOffset == curPos ) { 1685 fob.writeWordAt( fob.getPos()-cur.jumpOffset-2, cur.jumpOffset ); 1686 cur = cur.next; 1687 if( pred == null ) { 1688 forward_refs[0] = cur; 1689 } else { 1690 pred.next = cur; 1691 } 1692 continue; 1693 } 1694 pred = cur; 1695 cur = cur.next; 1696 } 1697 } 1698 1699 1703 protected final String getString() { 1704 return body.getString(); 1705 } 1706 protected final int getByte() { 1707 return body.getByte(); 1708 } 1709 protected final int getUByte() { 1710 return body.getUByte(); 1711 } 1712 protected final int getWord() { 1713 return body.getWord(); 1714 } 1715 protected final int getUWord() { 1716 return body.getUWord(); 1717 } 1718 protected final int getDWord() { 1719 return body.getDWord(); 1720 } 1721 protected final int getUDWord() { 1722 return body.getUDWord(); 1723 } 1724 protected final int getPos() { 1725 return body.getPos(); 1726 } 1727 protected final void setPos( int pos ) { 1728 body.setPos(pos); 1729 } 1730 1731} 1732 | Popular Tags |