/// <summary> /// /// </summary> /// <param name="expectedLength"></param> protected void ParseCode( uint expectedLength ) { BinaryReader2 br = new BinaryReader2( this._dataStream ); AVM1.AVM1InstructionSequence bytecode = null; Log.Debug(this, "Parsing AVM1 code" ); try { bytecode = Helper.SwfCodeReader.GetCode( expectedLength, br, this.Version ); } catch ( AVM1.AVM1Exception be ) { Log.Error(this, be ); if ( SwfFile.Configuration.AVM1DeleteInvalidBytecode) { bytecode = new AVM1.AVM1InstructionSequence(); } else { SwfFormatException swfe = new SwfFormatException( "Tag with invalid byte code", be ); Log.Error(this, swfe); throw swfe; } } this._code = new Recurity.Swf.AVM1.AVM1Code( bytecode ); //Log.Debug(this, this._code.Count.ToString() + " actions added" ); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="maxSize"></param> public void Parse( Stream input, uint maxSize ) { BinaryReader br = new BinaryReader( input ); // // subtract the OffsetToNextCondAction as well as the Conditions from // the available size // uint maxSizeInternal = maxSize - 4; _OffsetToNextCondAction = br.ReadUInt16(); BitStream bits = new BitStream( input ); _CondIdleToOverDown = ( 0 != bits.GetBits( 1 ) ); _CondOutDownToIdle = ( 0 != bits.GetBits( 1 ) ); _CondOutDownToOverDown = ( 0 != bits.GetBits( 1 ) ); _CondOverDownToOutDown = ( 0 != bits.GetBits( 1 ) ); _CondOverDownToOverUp = ( 0 != bits.GetBits( 1 ) ); _CondOverUpToOverDown = ( 0 != bits.GetBits( 1 ) ); _CondOverUpToIdle = ( 0 != bits.GetBits( 1 ) ); _CondIdleToOverUp = ( 0 != bits.GetBits( 1 ) ); _CondKeyPress = (byte)bits.GetBits( 7 ); if ( ( 0 != _CondKeyPress ) && ( this.Version < 4 ) ) { throw new SwfFormatException( "CondKeyPress != 0 with Swf version " + this.Version.ToString( "d" ) ); } if ( ( ( _CondKeyPress > 19 ) && ( _CondKeyPress < 32 ) ) || ( _CondKeyPress > 126 ) ) { throw new SwfFormatException( "Illegal CondKeyPress " + _CondKeyPress.ToString("d") + " in ButtonCondAction" ); } _CondOverDownToIdle = ( 0 != bits.GetBits( 1 ) ); uint expectedSize; if ( 0 != _OffsetToNextCondAction ) { // // if we have been given an offset, this defines our code // size expecations (minus 4 bytes for the previous data) // expectedSize = (uint)( _OffsetToNextCondAction - 4 ); } else { // // if we have no offset, the caller must tell us how much // we have left // expectedSize = maxSizeInternal; } AVM1.AVM1InstructionSequence bytecode = Helper.SwfCodeReader.GetCode( expectedSize, br, this.Version ); _Code = new AVM1.AVM1Code( bytecode ); }