Recurity.Swf.AVM1.AbstractAction.Read C# (CSharp) Method

Read() public method

public Read ( BinaryReader sourceStream, byte sourceVersion ) : void
sourceStream System.IO.BinaryReader
sourceVersion byte
return void
        public void Read( BinaryReader sourceStream, byte sourceVersion )
        {
            _SwfVersion = sourceVersion;

            _actionCode = sourceStream.ReadByte();

            //
            // Verify that the ActionCode can be used legally in this version of a Swf file
            //
            if ( sourceVersion < MinimumVersionRequired )
            {
                string msg = "Action " + _actionCode.ToString( "X02" ) +
                    " version mismatch (action:" + MinimumVersionRequired.ToString() +
                    " file:" + sourceVersion.ToString() +
                    ") - Stream Offset 0x" + sourceStream.BaseStream.Position.ToString( "X08" );

                Log.Warn(this,  msg );
            }

            // determine length, if any
            if ( ( 0x80 & _actionCode ) == 0x80 )
            {
                _length = sourceStream.ReadUInt16();
            }
            else
            {
                _length = 0;
            }

            // only parse if there is anything to parse
            if ( 0 != _length )
            {
                // safety net: remember the stream positon before
                // parsing and later compare it to the _length declared
                long before = sourceStream.BaseStream.Position;

                Parse( sourceStream, sourceVersion );

                // safety net: now checking (see above)
                if ( sourceStream.BaseStream.Position != ( before + _length ) )
                {
                    string msg = "AbstractAction (for code " + _actionCode.ToString( "X02" ) +
                        " - " + ( AVM1Factory.ActionName( ( AVM1Actions )_actionCode ) == null ? "UNKNOWN" : AVM1Factory.ActionName( ( AVM1Actions )_actionCode ) ) +
                        ") consumed more/less than the Action's length (" +
                        ( ( long )( sourceStream.BaseStream.Position - before ) ).ToString() + " consumed, " +
                        _length.ToString() + " declared as length)";

                    throw new AVM1ExceptionByteCodeFormat( msg );
                }
            }
        }