Beispiel #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inList"></param>
        /// <returns></returns>
        public static UInt32 CodeLength( AVM1InstructionSequence inList )
        {
            UInt32 sum = 0;

            for ( int i = 0; i < inList.Count; i++ )
            {
                sum += inList[ i ].ActionLength;
            }

            return sum;
        }
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="size"></param>
        /// <param name="sourceStream"></param>
        /// <param name="sourceVersion"></param>
        /// <returns></returns>
        public static AVM1InstructionSequence GetCode( UInt32 size, BinaryReader sourceStream, byte sourceVersion )
        {
            AVM1InstructionSequence retVal = new AVM1InstructionSequence();

            using ( MemoryStream memStream = new MemoryStream( sourceStream.ReadBytes( (int)size ) ) )
            {
                BinaryReader2 brInner = new BinaryReader2( memStream );
                while ( brInner.BaseStream.Position < size )
                {
                    if ( 0 == brInner.PeekByte() )
                    {
                        //
                        // ActionEndFlag found
                        //
                        AbstractAction innerAction = AVM1Factory.Create( brInner, sourceVersion );
                        retVal.Add( innerAction );

                        //
                        // Verify that the entire MemoryStream (i.e. "size" bytes) were consumed
                        //
                        if ( brInner.BaseStream.Position != size )
                        {
                            Log.Warn(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Code reading for size " + size.ToString("d") +
                                " terminated prematurely at position 0x" + brInner.BaseStream.Position.ToString( "X08" )
                            );
                        }

                        break;
                    }
                    else
                    {
                        AbstractAction innerAction = AVM1Factory.Create( brInner, sourceVersion );
                        retVal.Add( innerAction );
                    }
                }
            }

            return retVal;
        }
Beispiel #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="id"></param>
 public AVM1BasicBlock( UInt32 id )
 {
     _ID = id;
     _Instructions = new AVM1InstructionSequence();
     _Blocks = new List<AVM1BasicBlockEdge>();
 }
        /// <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;
        }
Beispiel #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private bool Load()
        {
            bool result;

            RemoveComments();
            result = Populate();

            AVM1InstructionSequence bytecode;
            //
            // Now fill the _Code list for quick access
            //
            if ( result )
            {
                bytecode = new AVM1InstructionSequence();
                for ( int i = 0; i < _InnerCode.Count; i++ )
                {
                    bytecode.Add( _InnerCode[ i ].Code );
                }

                _Code = new AVM1Code( bytecode );

                String s = String.Format("Modification with {0:d} instructions loaded", _Code.Count );
                //Log.Debug(this, s);
            }
            else
            {
               //Log.Debug(this,  "Error loading modification" );
            }

            return result;
        }