Represents a try block with any number of catch clauses, any number of filter clauses and, optionally, a finally or fault block.
Inheritance: Statement, ITryCatchFinallyStatement
コード例 #1
0
 public override IStatement Rewrite(ITryCatchFinallyStatement operation)
 {
     _log.Info("Rewriting ITryCatchFinallyStatement: " + operation + " Pass: "******"Finally")
     {
         tryCatch.FinallyBody = null;
     }
     else
     {
         tryCatch.CatchClauses.RemoveAt(int.Parse(MutationTarget.PassInfo));
     }
     return tryCatch;
 }
コード例 #2
0
            public override IStatement Rewrite(ITryCatchFinallyStatement operation)
            {
                _log.Info("Rewriting ITryCatchFinallyStatement: " + operation + " Pass: " + MutationTarget.PassInfo);
                var systemException = CurrentMethod.ContainingTypeDefinition.PlatformType.SystemException;
                var tryCatch = new TryCatchFinallyStatement(operation);

                tryCatch.CatchClauses.Add(new CatchClause
                {
                    ExceptionType = systemException,
                    Body = new BlockStatement()
                    {
                        Statements = new List<IStatement>{ new EmptyStatement()},
                    }
                });
                return tryCatch;
            }
コード例 #3
0
    internal TryCatchReplacer(SourceMethodBody sourceMethodBody, DecompiledBlock block) {
      Contract.Requires(sourceMethodBody != null);
      Contract.Requires(block != null);
      this.host = sourceMethodBody.host; Contract.Assume(sourceMethodBody.host != null);
      this.gotosThatTarget = sourceMethodBody.gotosThatTarget; Contract.Assume(this.gotosThatTarget != null);
      this.unconditionalBranchRemover.gotosThatTarget = sourceMethodBody.gotosThatTarget;

      Contract.Assume(sourceMethodBody.ilMethodBody != null);
      foreach (var exInfo in sourceMethodBody.ilMethodBody.OperationExceptionInformation) {
        var tryCatchF = this.tryCatchFinallyMap.Find(exInfo.TryStartOffset, exInfo.TryEndOffset);
        if (tryCatchF == null) {
          tryCatchF = new TryCatchFinallyStatement();
          this.tryCatchFinallyMap.Add(exInfo.TryStartOffset, exInfo.TryEndOffset, tryCatchF);
        }        
        if (exInfo.HandlerKind == HandlerKind.Filter) {
          this.tryCatchFinallyMap.Add(exInfo.FilterDecisionStartOffset, exInfo.HandlerEndOffset, tryCatchF); 
          this.handlerMap.Add(exInfo.FilterDecisionStartOffset, exInfo.HandlerEndOffset, exInfo); 
        }
        this.tryCatchFinallyMap.Add(exInfo.HandlerStartOffset, exInfo.HandlerEndOffset, tryCatchF);
        this.handlerMap.Add(exInfo.HandlerStartOffset, exInfo.HandlerEndOffset, exInfo); 
      }
    }
コード例 #4
0
ファイル: Copier.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Visits the specified try catch filter finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement">The try catch filter finally statement.</param>
 public override void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     TryCatchFinallyStatement mutableTryCatchFinallyStatement = new TryCatchFinallyStatement(tryCatchFilterFinallyStatement);
     this.resultStatement = this.myCodeCopier.DeepCopy(mutableTryCatchFinallyStatement);
 }
コード例 #5
0
ファイル: Copier.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Visits the specified try catch filter finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement">The try catch filter finally statement.</param>
 /// <returns></returns>
 protected virtual IStatement DeepCopy(TryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     tryCatchFilterFinallyStatement.TryBody = (IBlockStatement)Substitute(tryCatchFilterFinallyStatement.TryBody);
       tryCatchFilterFinallyStatement.CatchClauses = this.DeepCopy(tryCatchFilterFinallyStatement.CatchClauses);
       if (tryCatchFilterFinallyStatement.FinallyBody != null)
     tryCatchFilterFinallyStatement.FinallyBody = (IBlockStatement)Substitute(tryCatchFilterFinallyStatement.FinallyBody);
       return tryCatchFilterFinallyStatement;
 }
コード例 #6
0
 private void RemoveUnconditionalBranchesToLabelImmediatelyFollowing(TryCatchFinallyStatement trycf, DecompiledBlock followingBlock) {
   Contract.Requires(trycf != null);
   while (followingBlock != null) {
     if (followingBlock.Statements.Count == 0) return;
     var label = followingBlock.Statements[0] as LabeledStatement;
     if (label != null) {
       this.unconditionalBranchRemover.StopTraversal = false;
       this.unconditionalBranchRemover.targetLabel = label;
       this.unconditionalBranchRemover.Traverse(trycf);
       var gotos = this.gotosThatTarget.Find((uint)label.Label.UniqueKey);
       if (gotos == null || gotos.Count == 0) {
         followingBlock.Statements.RemoveAt(0);
       }
       return;
     }
     followingBlock = followingBlock.Statements[0] as DecompiledBlock;
   }
 }
コード例 #7
0
 private void DecompileTryBody(BasicBlock b, BasicBlock firstHandler, TryCatchFinallyStatement tryStatement)
 {
     tryStatement.TryBody = GetBasicBlockUpto(b, firstHandler.StartOffset);
       BasicBlock tryBody = tryStatement.TryBody as BasicBlock;
       int startPoint = 0;
       if (tryBody != null && tryBody.Statements.Count > 0) {
     ILabeledStatement labeledStatement = tryBody.Statements[0] as ILabeledStatement;
     if (labeledStatement != null) {
       tryBody.Statements.RemoveAt(0);
       b.Statements.Insert(startPoint, labeledStatement);
       startPoint++;
     }
       }
       b.Statements.Insert(startPoint, tryStatement);
 }
コード例 #8
0
 private void ConsolidateScopes(TryCatchFinallyStatement trycf) {
   Contract.Requires(trycf != null);
   ConsolidateScopes((DecompiledBlock)trycf.TryBody);
   if (trycf.FaultBody != null) ConsolidateScopes((DecompiledBlock)trycf.FaultBody);
   if (trycf.FinallyBody != null) ConsolidateScopes((DecompiledBlock)trycf.FinallyBody);
   foreach (var catchClause in trycf.CatchClauses) {
     Contract.Assume(catchClause != null);
     var cb = (DecompiledBlock)catchClause.Body;
     ConsolidateScopes(cb);
   }
 }
コード例 #9
0
 private static void DecompileHandler(BasicBlock containingBlock, BasicBlock handlerBlock, TryCatchFinallyStatement tryStatement)
 {
     if (handlerBlock.ExceptionInformation.HandlerKind == HandlerKind.Finally) {
     tryStatement.FinallyBody = handlerBlock;
       } else if (handlerBlock.ExceptionInformation.HandlerKind == HandlerKind.Fault) {
     tryStatement.FaultBody = handlerBlock;
       } else {
     CatchClause catchClause = new CatchClause();
     catchClause.Body = handlerBlock;
     catchClause.ExceptionType = handlerBlock.ExceptionInformation.ExceptionType;
     if (handlerBlock.ExceptionInformation.HandlerKind == HandlerKind.Catch) {
       catchClause.ExceptionContainer = ExtractExceptionContainer(handlerBlock);
     } else if (handlerBlock.ExceptionInformation.HandlerKind == HandlerKind.Filter) {
       catchClause.FilterCondition = ExtractFilterCondition(handlerBlock);
     }
     tryStatement.CatchClauses.Add(catchClause);
       }
       //Remove handler from statements in containing block
       containingBlock.Statements[containingBlock.Statements.Count-1] = GetBasicBlockStartingAt(handlerBlock, handlerBlock.ExceptionInformation.HandlerEndOffset);
       RemoveEndFinally(handlerBlock);
 }
コード例 #10
0
 protected override void Traverse(BasicBlock b)
 {
     if (b.NumberOfTryBlocksStartingHere > 0) {
     BasicBlock firstHandler = null;
     TryCatchFinallyStatement/*?*/ tryStatement = new TryCatchFinallyStatement();
     BasicBlock bb = b;
     while (b.NumberOfTryBlocksStartingHere-- > 0) {
       if (bb.Statements.Count > 0) {
     BasicBlock bbb = bb.Statements[bb.Statements.Count-1] as BasicBlock;
     while (bbb != null) {
       if (bbb.ExceptionInformation != null) {
         if (firstHandler == null) firstHandler = bbb;
         if (firstHandler.ExceptionInformation.TryEndOffset < bbb.ExceptionInformation.TryEndOffset) {
           DecompileTryBody(b, firstHandler, tryStatement);
           tryStatement = new TryCatchFinallyStatement();
           firstHandler = bbb;
         }
         DecompileHandler(bb, bbb, tryStatement);
         break;
       }
       if (bbb.Statements.Count == 0) break;
       bb = bbb;
       bbb = bbb.Statements[bbb.Statements.Count-1] as BasicBlock;
     }
       }
     }
     DecompileTryBody(b, firstHandler, tryStatement);
       }
 }
コード例 #11
0
ファイル: Mutator.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Rewrites the children of the try-catch-filter-finally statement.
 /// </summary>
 public virtual void RewriteChildren(TryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     this.RewriteChildren((Statement)tryCatchFilterFinallyStatement);
       tryCatchFilterFinallyStatement.TryBody = this.Rewrite((BlockStatement)tryCatchFilterFinallyStatement.TryBody);
       tryCatchFilterFinallyStatement.CatchClauses = this.Rewrite(tryCatchFilterFinallyStatement.CatchClauses);
       if (tryCatchFilterFinallyStatement.FaultBody != null)
     tryCatchFilterFinallyStatement.FaultBody = this.Rewrite((BlockStatement)tryCatchFilterFinallyStatement.FaultBody);
       if (tryCatchFilterFinallyStatement.FinallyBody != null)
     tryCatchFilterFinallyStatement.FinallyBody = this.Rewrite((BlockStatement)tryCatchFilterFinallyStatement.FinallyBody);
 }
コード例 #12
0
ファイル: Mutator.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Visits the specified try catch filter finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement">The try catch filter finally statement.</param>
 public override void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     TryCatchFinallyStatement mutableTryCatchFinallyStatement = tryCatchFilterFinallyStatement as TryCatchFinallyStatement;
     if (alwaysMakeACopy || mutableTryCatchFinallyStatement == null) mutableTryCatchFinallyStatement = new TryCatchFinallyStatement(tryCatchFilterFinallyStatement);
     this.resultStatement = this.myCodeMutator.Visit(mutableTryCatchFinallyStatement);
 }
コード例 #13
0
ファイル: Mutator.cs プロジェクト: riverar/devtools
 /// <summary>
 /// Visits the specified try catch filter finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement">The try catch filter finally statement.</param>
 /// <returns></returns>
 public virtual IStatement Visit(TryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     tryCatchFilterFinallyStatement.TryBody = Visit(tryCatchFilterFinallyStatement.TryBody);
       tryCatchFilterFinallyStatement.CatchClauses = Visit(tryCatchFilterFinallyStatement.CatchClauses);
       if (tryCatchFilterFinallyStatement.FinallyBody != null)
     tryCatchFilterFinallyStatement.FinallyBody = Visit(tryCatchFilterFinallyStatement.FinallyBody);
       if (tryCatchFilterFinallyStatement.FaultBody != null)
     tryCatchFilterFinallyStatement.FaultBody = Visit(tryCatchFilterFinallyStatement.FaultBody);
       return tryCatchFilterFinallyStatement;
 }