public override void Visit(IOperationExceptionInformation operationExceptionInformation)
 {
     if (Process(operationExceptionInformation))
     {
         visitor.Visit(operationExceptionInformation);
     }
     base.Visit(operationExceptionInformation);
 }
Beispiel #2
0
        public override void Visit(IOperationExceptionInformation operationExceptionInformation)
        {
            ITypeReference excepType = operationExceptionInformation.ExceptionType;

            if (excepType == Dummy.TypeReference)
            {
                return;
            }

            base.Visit(operationExceptionInformation);
        }
 private static int CompareHandlers(IOperationExceptionInformation handler1, IOperationExceptionInformation handler2)
 {
     Contract.Requires(handler1 != null);
     Contract.Requires(handler2 != null);
     if (handler1.TryStartOffset < handler2.TryStartOffset)
     {
         return(-1);
     }
     if (handler1.TryStartOffset > handler2.TryStartOffset)
     {
         return(1);
     }
     if (handler1.TryEndOffset > handler2.TryEndOffset)
     {
         return(-1);
     }
     if (handler1.TryEndOffset < handler2.TryEndOffset)
     {
         return(1);
     }
     if (handler1.HandlerStartOffset < handler2.HandlerStartOffset)
     {
         return(-1);
     }
     if (handler2.HandlerStartOffset > handler2.HandlerStartOffset)
     {
         return(1);
     }
     if (handler1.HandlerEndOffset > handler2.HandlerEndOffset)
     {
         return(-1);
     }
     if (handler1.HandlerEndOffset < handler2.HandlerEndOffset)
     {
         return(1);
     }
     return(0);
 }
Beispiel #4
0
 /// <summary>
 /// Visits the specified operation exception information.
 /// </summary>
 /// <param name="operationExceptionInformation">The operation exception information.</param>
 public virtual void Visit(IOperationExceptionInformation operationExceptionInformation)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(operationExceptionInformation);
       this.Visit(operationExceptionInformation.ExceptionType);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count.
       this.path.Pop();
 }
Beispiel #5
0
 /// <summary>
 /// Traverses the specified operation exception information.
 /// </summary>
 public void Traverse(IOperationExceptionInformation operationExceptionInformation)
 {
     Contract.Requires(operationExceptionInformation != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(operationExceptionInformation);
       if (this.stopTraversal) return;
       this.TraverseChildren(operationExceptionInformation);
       if (this.stopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(operationExceptionInformation);
 }
Beispiel #6
0
 public void Visit(IOperationExceptionInformation operationExceptionInformation)
 {
     throw new NotImplementedException();
 }
    private void EmitCatchFilter(uint offset, IOperationExceptionInformation expInfo) {
      Contract.Requires(expInfo != null);

      this.sourceEmitter.EmitString("expSwitchVal" + expInfo.TryStartOffset + " = " + this.exceptionSwitchTables.NumberOfEntries(expInfo.TryStartOffset) + ";");
      this.sourceEmitter.EmitNewLine();
      this.sourceEmitter.EmitString("goto lcatch_filter_" + expInfo.HandlerStartOffset + ";");
      this.sourceEmitter.EmitNewLine();
      string label = "l" + offset.ToString("x4") + "_" + expInfo.HandlerStartOffset.ToString("x4") + "_" + labelCounter++;
      this.exceptionSwitchTables.Add(expInfo.TryStartOffset, label);
      this.sourceEmitter.EmitLabel(label + ":");
      this.sourceEmitter.EmitNewLine();

      this.sourceEmitter.EmitString("if (canHandleExp > 0) ");
      this.sourceEmitter.EmitBlockOpeningDelimiter("{");
      this.sourceEmitter.EmitNewLine();
      this.sourceEmitter.EmitString("canHandleExp = 0;");
      this.sourceEmitter.EmitNewLine();
      this.sourceEmitter.EmitString("goto lrun_finallies_for_catch_" + expInfo.HandlerStartOffset + ";");
      this.sourceEmitter.EmitNewLine();
      this.sourceEmitter.EmitBlockClosingDelimiter("}");
      this.sourceEmitter.EmitNewLine();
    }
    bool PopulateExceptionInformation() {
      SEHTableEntry[]/*?*/ sehTable = this.MethodIL.SEHTable;
      if (sehTable != null) {
        int n = sehTable.Length;
        var exceptions = new IOperationExceptionInformation[n];
        for (int i = 0; i < n; i++) {
          SEHTableEntry sehTableEntry = sehTable[i];
          int sehFlag = (int)sehTableEntry.SEHFlags;
          int handlerKindIndex = sehFlag >= ILReader.HandlerKindMap.Length ? ILReader.HandlerKindMap.Length - 1 : sehFlag;
          ITypeReference exceptionType = Dummy.TypeReference;
          uint filterDecisionStart = 0;
          HandlerKind handlerKind = ILReader.HandlerKindMap[handlerKindIndex];
          uint tryStart = sehTableEntry.TryOffset;
          uint tryEnd = sehTableEntry.TryOffset + sehTableEntry.TryLength;
          uint handlerStart = sehTableEntry.HandlerOffset;
          uint handlerEnd = sehTableEntry.HandlerOffset + sehTableEntry.HandlerLength;

          if (sehTableEntry.SEHFlags == SEHFlags.Catch) {
            ITypeReference/*?*/ typeRef = this.PEFileToObjectModel.GetTypeReferenceForToken(this.MethodDefinition, sehTableEntry.ClassTokenOrFilterOffset);
            if (typeRef == null) {
              //  Error
              return false;
            } else {
              exceptionType = typeRef;
            }
          } else if (sehTableEntry.SEHFlags == SEHFlags.Filter) {
            exceptionType = this.PEFileToObjectModel.PlatformType.SystemObject;
            filterDecisionStart = sehTableEntry.ClassTokenOrFilterOffset;
          }
          exceptions[i] = new CilExceptionInformation(handlerKind, exceptionType, tryStart, tryEnd, filterDecisionStart, handlerStart, handlerEnd);
        }
        this.MethodBody.SetExceptionInformation(exceptions);
      }
      return true;
    }
 public override void Visit(IOperationExceptionInformation operationExceptionInformation)
 {
     if(Process(operationExceptionInformation)){visitor.Visit(operationExceptionInformation);}
     base.Visit(operationExceptionInformation);
 }
Beispiel #10
0
 /// <summary>
 /// Performs some computation with the given IL operation exception information instance.
 /// </summary>
 public void Visit(IOperationExceptionInformation operationExceptionInformation)
 {
 }
        public override void Visit(IOperationExceptionInformation operationExceptionInformation)
        {
            ITypeReference excepType = operationExceptionInformation.ExceptionType;
            if (excepType == Dummy.TypeReference)
                return;

            base.Visit(operationExceptionInformation);
        }
        public override void TraverseChildren(IBlockStatement block)
        {
            Contract.Assume(block is BlockStatement);
            var decompiledBlock             = (BlockStatement)block;
            var statements                  = decompiledBlock.Statements;
            List <IStatement> newStatements = null;

            for (int i = 0, n = statements.Count; i < n; i++)
            {
                LabeledStatement outerLabel = null;
                Contract.Assume(i < statements.Count);
                var statement = statements[i];
                Contract.Assume(statement != null);
                var nestedBlock = statement as DecompiledBlock;
                if (nestedBlock != null)
                {
                    var trycf = this.tryCatchFinallyMap.Find(nestedBlock.StartOffset, nestedBlock.EndOffset);
                    if (trycf != null)
                    {
                        statements[i] = trycf;
                        if (newStatements == null)
                        {
                            newStatements = CopyStatements(statements, i);
                        }
                        IOperationExceptionInformation handlerInfo = this.handlerMap.Find(nestedBlock.StartOffset, nestedBlock.EndOffset);
                        if (handlerInfo == null)
                        {
                            outerLabel = nestedBlock.ReturnInitialLabel();
                            if (outerLabel != null)
                            {
                                newStatements.Add(outerLabel);
                                var innerLabel = new LabeledStatement(outerLabel);
                                innerLabel.Label = this.host.NameTable.GetNameFor(outerLabel.Label.Value + "#inner");
                                nestedBlock.ReplaceInitialLabel(innerLabel);
                                this.trystartOutsideLabels.Add(outerLabel);
                                this.insideLabelFor[(uint)outerLabel.Label.UniqueKey] = innerLabel;
                            }
                            trycf.TryBody = nestedBlock;
                            statement     = trycf;
                        }
                        else
                        {
                            switch (handlerInfo.HandlerKind)
                            {
                            case HandlerKind.Catch:
                                ILocalDefinition exceptionContainer = this.ExtractExceptionContainer(nestedBlock, handlerInfo.ExceptionType);
                                if (!(exceptionContainer is Dummy))
                                {
                                    this.RemoveLocalDeclarationOf(exceptionContainer, nestedBlock);
                                }
                                trycf.CatchClauses.Add(new CatchClause()
                                {
                                    Body = nestedBlock, ExceptionType = handlerInfo.ExceptionType, ExceptionContainer = exceptionContainer
                                });
                                break;

                            case HandlerKind.Fault:
                                trycf.FaultBody = nestedBlock;
                                break;

                            case HandlerKind.Filter:
                                var filterCondition = this.GetFilterCondition(nestedBlock);
                                if (filterCondition != null)
                                {
                                    this.RemovedFilterCondition(nestedBlock);
                                }
                                trycf.CatchClauses.Add(new CatchClause()
                                {
                                    Body = nestedBlock, ExceptionType = this.host.PlatformType.SystemObject, FilterCondition = filterCondition
                                });
                                break;

                            case HandlerKind.Finally:
                                this.RemoveEndFinallyFrom(nestedBlock);
                                trycf.FinallyBody = nestedBlock;
                                break;
                            }
                            this.Traverse(nestedBlock);
                            if (outerLabel != null)
                            {
                                this.trystartOutsideLabels.Remove(outerLabel);
                            }
                            continue;
                        }
                    }
                }
                if (newStatements != null)
                {
                    newStatements.Add(statement);
                }
                this.Traverse(statement);
            }
            if (newStatements != null)
            {
                decompiledBlock.Statements = newStatements;
                for (int i = 0, n = newStatements.Count - 1; i < n; i++)
                {
                    var trycf = newStatements[i] as TryCatchFinallyStatement;
                    if (trycf == null)
                    {
                        continue;
                    }
                    var followingBlock = newStatements[i + 1] as DecompiledBlock;
                    if (followingBlock != null)
                    {
                        this.RemoveUnconditionalBranchesToLabelImmediatelyFollowing(trycf, followingBlock);
                    }
                    this.ConsolidateScopes(trycf);
                }
            }
        }
 /// <summary>
 /// Performs some computation with the given IL operation exception information instance.
 /// </summary>
 public virtual void Visit(IOperationExceptionInformation operationExceptionInformation)
 {
 }
 /// <summary>
 /// Rewrites the specified operation exception information.
 /// </summary>
 public virtual IOperationExceptionInformation Rewrite(
     IOperationExceptionInformation operationExceptionInformation)
 {
     return operationExceptionInformation;
 }
Beispiel #15
0
 public override void Visit(IOperationExceptionInformation operationExceptionInformation)
 {
     allElements.Add(new InvokInfo(Traverser, "IOperationExceptionInformation", operationExceptionInformation));
 }
 private static int CompareHandlers(IOperationExceptionInformation handler1, IOperationExceptionInformation handler2) {
   Contract.Requires(handler1 != null);
   Contract.Requires(handler2 != null);
   if (handler1.TryStartOffset < handler2.TryStartOffset) return -1;
   if (handler1.TryStartOffset > handler2.TryStartOffset) return 1;
   if (handler1.TryEndOffset > handler2.TryEndOffset) return -1;
   if (handler1.TryEndOffset < handler2.TryEndOffset) return 1;
   if (handler1.HandlerStartOffset < handler2.HandlerStartOffset) return -1;
   if (handler2.HandlerStartOffset > handler2.HandlerStartOffset) return 1;
   if (handler1.HandlerEndOffset > handler2.HandlerEndOffset) return -1;
   if (handler1.HandlerEndOffset < handler2.HandlerEndOffset) return 1;
   return 0;
 }
Beispiel #17
0
 /// <summary>
 /// Traverses the specified operation exception information.
 /// </summary>
 public virtual void TraverseChildren(IOperationExceptionInformation operationExceptionInformation)
 {
     Contract.Requires(operationExceptionInformation != null);
       if (operationExceptionInformation.HandlerKind == HandlerKind.Catch || operationExceptionInformation.HandlerKind == HandlerKind.Filter)
     this.Traverse(operationExceptionInformation.ExceptionType);
 }
 public virtual void onMetadataElement(IOperationExceptionInformation operationExceptionInformation) { }
Beispiel #19
0
 public void Visit(IOperationExceptionInformation operationExceptionInformation)
 {
     Contract.Assume(false);
 }
Beispiel #20
0
 /// <summary>
 /// Is the target operation in the try block of the test?
 /// </summary>
 /// <param name="operation">
 /// The operation to test.
 /// </param>
 /// <param name="handlerBounds">
 /// The handler bounds to test against. Presumably a set of bounds that exist in the same method from
 /// whence the operation came.
 /// </param>
 /// <returns>
 /// True if the operation is in the test try block, false otherwise.
 /// </returns>
 public static bool IsOperationInTryBlock(this IOperation operation, IOperationExceptionInformation handlerBounds)
 {
     return operation.Offset >= handlerBounds.TryStartOffset &&
         operation.Offset <= handlerBounds.TryEndOffset;
 }
 public override void TraverseChildren(IOperationExceptionInformation operationExceptionInformation) {
   base.TraverseChildren(operationExceptionInformation);
 }
Beispiel #22
0
 public virtual void onMetadataElement(IOperationExceptionInformation operationExceptionInformation)
 {
 }
Beispiel #23
0
 public override void TraverseChildren(IOperationExceptionInformation operationExceptionInformation)
 {
     MethodEnter(operationExceptionInformation);
     base.TraverseChildren(operationExceptionInformation);
     MethodExit();
 }
        public override void TraverseChildren(IOperationExceptionInformation operationExceptionInformation)
{ MethodEnter(operationExceptionInformation);
            base.TraverseChildren(operationExceptionInformation);
     MethodExit();   }
 internal void SetExceptionInformation(IOperationExceptionInformation[] cilExceptionInformation) {
   this.cilExceptionInformation = IteratorHelper.GetReadonly(cilExceptionInformation);
 }
Beispiel #26
0
 /// <summary>
 /// Traverses the specified operation exception information.
 /// </summary>
 public virtual void TraverseChildren(IOperationExceptionInformation operationExceptionInformation)
 {
     if (operationExceptionInformation.HandlerKind == HandlerKind.Catch || operationExceptionInformation.HandlerKind == HandlerKind.Filter)
     this.Traverse(operationExceptionInformation.ExceptionType);
 }