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

Parse() public method

public Parse ( Stream input ) : bool
input Stream
return bool
        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;
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public bool Parse( Stream input )
        {
            BinaryReader2 br = new BinaryReader2( input );
            bool parsingSuccess = true;

            UInt16 uselessButFiddelingWithBitsThanksAdobe = br.ReadUInt16();
            if ( 0 != uselessButFiddelingWithBitsThanksAdobe )
            {
                SwfFormatException sfe = new SwfFormatException( "Reserved 16Bit Field in CLIPACTION used" );
               Log.Error(this,  sfe );
                throw sfe;
            }

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

            _ClipActionRecords = new List<ClipActionRecord>();
            //
            // The ClipActionEndFlag is Version dependent!
            //
            while ( 0 != ( this.Version <= 5 ? br.PeekUInt16() : br.PeekUInt32() ) )
            {
                ClipActionRecord record = new ClipActionRecord( this.Version );
                bool recordParsingResult = record.Parse( input );
                _ClipActionRecords.Add( record );
                parsingSuccess = recordParsingResult & parsingSuccess;
            }
            //
            // Get the EndRecord (Version dependent) and ignore
            //
            UInt32 endRecord = this.Version <= 5 ? br.ReadUInt16() : br.ReadUInt32();

            if ( 0 != endRecord )
            {
                SwfFormatException sfe = new SwfFormatException( "endRecord is not 0x00/0x0000" );
               Log.Error(this,  sfe );
                throw sfe;
            }

               //Log.Debug(this,  _ClipActionRecords.Count + " ClipActionRecords added" );

            return parsingSuccess;
        }