Recurity.Swf.ClipEventFlags.Parse C# (CSharp) Method

Parse() public method

public Parse ( Stream input ) : void
input Stream
return void
        public void Parse( Stream input )
        {
            BitStream bits = new BitStream( input );

            ClipEventKeyUp = ( 1 == bits.GetBits( 1 ) );            // 0
            ClipEventKeyDown = ( 1 == bits.GetBits( 1 ) );          // 1
            ClipEventMouseUp = ( 1 == bits.GetBits( 1 ) );          // 2
            ClipEventMouseDown = ( 1 == bits.GetBits( 1 ) );        // 3
            ClipEventMouseMove = ( 1 == bits.GetBits( 1 ) );        // 4
            ClipEventUnload = ( 1 == bits.GetBits( 1 ) );           // 5
            ClipEventEnterFrame = ( 1 == bits.GetBits( 1 ) );       // 6
            ClipEventLoad = ( 1 == bits.GetBits( 1 ) );             // 7
            if ( this.Version >= 6 )
            {
                // Swf6 and following
                ClipEventDragOver = ( 1 == bits.GetBits( 1 ) );
                ClipEventRollOut = ( 1 == bits.GetBits( 1 ) );
                ClipEventRollOver = ( 1 == bits.GetBits( 1 ) );
                ClipEventReleaseOutside = ( 1 == bits.GetBits( 1 ) );
                ClipEventRelease = ( 1 == bits.GetBits( 1 ) );
                ClipEventPress = ( 1 == bits.GetBits( 1 ) );
                ClipEventInitialize = ( 1 == bits.GetBits( 1 ) );
                ClipEventData = ( 1 == bits.GetBits( 1 ) );

                uint reserved = bits.GetBits( 5 );
                if ( 0 != reserved )
                {
                    throw new SwfFormatException( "Reserved flags (following ClipEventData) used in ClipEventFlags" );
                }

                // Swf6, used in Swf7
                if ( ( ClipEventConstruct = ( 1 == bits.GetBits( 1 ) ) ) && ( this.Version < 7 ) )
                {
                    throw new SwfFormatException( "ClipEventConstruct in Swf with Version < 7" );
                }
                ClipEventKeyPress = ( 1 == bits.GetBits( 1 ) );
                ClipEventDragOut = ( 1 == bits.GetBits( 1 ) );

                uint reserved2 = bits.GetBits( 8 );
                if ( 0 != reserved2 )
                {
                    throw new SwfFormatException( "Reserved flags (following ClipEventDragOut) used in ClipEventFlags" );
                }
            }
            else
            {
                //
                // Swf spec mentiones that CLIPEVENTFLAGS is 2 Bytes in
                // Swf.Version < 6, but doesn't specify a Reserved 8-Bit field
                // explicitly. So we handle it like one.
                //
                uint reservedB46 = bits.GetBits( 8 );
                if ( 0 != reservedB46 )
                {
                    throw new SwfFormatException( "Reserved flags (following ClipEventLoad) used in ClipEventFlags" );
                }
            }
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public bool Parse( Stream input )
        {
            AVM1InstructionSequence bytecode;
            _ParsingFailures = false;

            _ClipEventFlags = new ClipEventFlags( this.Version );
            _ClipEventFlags.Parse( input );

            BinaryReader br = new BinaryReader( input );
            _length = br.ReadUInt32();
            _codeSize = _length;

            if ( _ClipEventFlags.ClipEventKeyPress )
            {
                if ( 1 > _length )
                {
                    throw new SwfFormatException( "ClipActionRecord length=0 but KeyCode indicated by ClipEventKeyPress" );
                }
                _KeyCode = br.ReadByte();
                _codeSize--;
            }

            long before = br.BaseStream.Position;

            try
            {
                bytecode = Helper.SwfCodeReader.GetCode( _codeSize, br, this.Version );

                if ( br.BaseStream.Position != ( before + _codeSize ) )
                {
                    throw new SwfFormatException( "ClipActionRecord code reader consumed more than length indicated (" +
                        ( ( uint )( br.BaseStream.Position - before ) ).ToString() + " consumed, " +
                        _codeSize + " length)" );
                }
            }
            catch ( AVM1ExceptionByteCodeFormat ave )
            {
               Log.Error(this,  ave );
                _ParsingFailures = true;

                if (SwfFile.Configuration.AVM1DeleteInvalidBytecode)
                {
                    bytecode = new AVM1InstructionSequence();
                }
                else
                {
                    SwfFormatException swfe = new SwfFormatException( "ClipActionRecord parsing error", ave );
                    throw swfe;
                }
            }
            finally
            {
                //
                // make sure that the input stream is at the right position
                // it would have if code reading would have been successful
                //
                long diff = ( before + _codeSize ) - br.BaseStream.Position;
                if ( 0 != diff )
                    br.BaseStream.Seek( diff, SeekOrigin.Current );
            }

            _Code = new AVM1Code( bytecode );

            return _ParsingFailures;
        }
All Usage Examples Of Recurity.Swf.ClipEventFlags::Parse