Example #1
0
 private static int DumpNextBytecodes(StreamWriter writer, UnBytecodeOwner function, byte[] bytes, int startOffset, int nextBytecodes)
 {
     using (var stream = new MemoryStream(bytes))
     {
         stream.Position = startOffset;
         using (var reader = new BinaryReader(stream))
         {
             var bytecodeReader = new BytecodeReader(function.Package, reader);
             for (int i = 0; i < nextBytecodes; i++)
             {
                 try
                 {
                     var bytecodeToken = bytecodeReader.ReadNext();
                     writer.WriteLine("      " + bytecodeToken);
                 }
                 catch (Exception)
                 {
                     writer.WriteLine("      error reading next bytecode");
                     break;
                 }
             }
             return((int)reader.BaseStream.Position);
         }
     }
 }
Example #2
0
        protected StatementList ReadBytecode()
        {
            var s          = new MemoryStream(_bytecode);
            var reader     = new BinaryReader(s);
            var bcReader   = new BytecodeReader(_self.Package, reader);
            var statements = new StatementList((Statement)null);

            while (s.Position < s.Length)
            {
                int           startOffset = (int)s.Position;
                BytecodeToken bc;
                try
                {
                    bc = bcReader.ReadNext();
                }
                catch (EndOfStreamException)
                {
                    break;
                }
                if (bc == null || bc is EndOfScriptToken)
                {
                    break;
                }
                statements.Add(new Statement(startOffset, (int)s.Position, bc));
                if (bc is ErrorBytecodeToken)
                {
                    var errorToken = (ErrorBytecodeToken)bc;
                    int bytecode   = errorToken.UnknownBytecode;
                    if (bytecode >= 0)
                    {
                        ProblemRegistry.RegisterUnknownBytecode((byte)bytecode, this, errorToken.SubsequentBytes);
                    }
                    else
                    {
                        ProblemRegistry.RegisterBytecodeError(this, errorToken.ToString());
                    }
                    break;
                }
            }
            return(statements);
        }
Example #3
0
 protected StatementList ReadBytecode()
 {
     var s = new MemoryStream(_bytecode);
     var reader = new BinaryReader(s);
     var bcReader = new BytecodeReader(_self.Package, reader);
     var statements = new StatementList((Statement) null);
     while(s.Position < s.Length)
     {
         int startOffset = (int) s.Position;
         BytecodeToken bc;
         try
         {
             bc = bcReader.ReadNext();
         }
         catch (EndOfStreamException)
         {
             break;
         }
         if (bc == null || bc is EndOfScriptToken) break;
         statements.Add(new Statement(startOffset, (int) s.Position, bc));
         if (bc is ErrorBytecodeToken)
         {
             var errorToken = (ErrorBytecodeToken) bc;
             int bytecode = errorToken.UnknownBytecode;
             if (bytecode >= 0)
             {
                 ProblemRegistry.RegisterUnknownBytecode((byte) bytecode, this, errorToken.SubsequentBytes);
             }
             else
             {
                 ProblemRegistry.RegisterBytecodeError(this, errorToken.ToString());
             }
             break;
         }
     }
     return statements;
 }
Example #4
0
 private static int DumpNextBytecodes(StreamWriter writer, UnBytecodeOwner function, byte[] bytes, int startOffset, int nextBytecodes)
 {
     using (var stream = new MemoryStream(bytes))
     {
         stream.Position = startOffset;
         using (var reader = new BinaryReader(stream))
         {
             var bytecodeReader = new BytecodeReader(function.Package, reader);
             for (int i = 0; i < nextBytecodes; i++ )
             {
                 try
                 {
                     var bytecodeToken = bytecodeReader.ReadNext();
                     writer.WriteLine("      " + bytecodeToken);
                 }
                 catch (Exception)
                 {
                     writer.WriteLine("      error reading next bytecode");
                     break;
                 }
             }
             return (int) reader.BaseStream.Position;
         }
     }
 }