Esempio n. 1
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;
        }
Esempio n. 2
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;
        }