Ejemplo n.º 1
0
 private void DetermineExceptionHandlingStatesFromCFGBlocks()
 {
     V_0 = this.theDisposeCFG.get_Blocks();
     V_1 = 0;
     while (V_1 < (int)V_0.Length)
     {
         V_2 = V_0[V_1];
         if (this.IsBeqInstruction(V_2.get_Last()) || this.IsBneUnInstruction(V_2.get_Last()) && StateMachineUtilities.TryGetOperandOfLdc(V_2.get_Last().get_Previous(), out V_3))
         {
             V_4 = null;
             if (!this.IsBeqInstruction(V_2.get_Last()))
             {
                 V_4 = V_2.get_Last().get_Next();
             }
             else
             {
                 V_4 = V_2.get_Last().get_Operand() as Instruction;
             }
             if (V_4 == null)
             {
                 throw new Exception("branchTargetInstruction cannot be null.");
             }
             if (this.TryGetExceptionHandler(StateMachineDisposeAnalyzer.SkipSingleNopInstructionBlock(this.theDisposeCFG.get_InstructionToBlockMapping().get_Item(V_4.get_Offset())), out V_6))
             {
                 if (!this.handlerToStatesMap.ContainsKey(V_6))
                 {
                     this.handlerToStatesMap.Add(V_6, new HashSet <int>());
                 }
                 dummyVar0 = this.handlerToStatesMap.get_Item(V_6).Add(V_3);
             }
         }
         V_1 = V_1 + 1;
     }
     return;
 }
        protected override bool ProcessCFG()
        {
            StateMachineDisposeAnalyzer disposeAnalyzer = new StateMachineDisposeAnalyzer(moveNextMethodContext.Method);
            StateControllerRemover controllerRemover;
            YieldStateMachineVersion machineVersion = disposeAnalyzer.ProcessDisposeMethod();
            if (machineVersion == YieldStateMachineVersion.V1)
            {
                controllerRemover = new StateControllerRemover(moveNextMethodContext);
            }
            else if (machineVersion == YieldStateMachineVersion.V2)
            {
                controllerRemover = new DisposingStateControllerRemover(moveNextMethodContext, disposeAnalyzer.StateField, disposeAnalyzer.DisposingField);
                StateMachineDoFinallyCheckRemover doFinallyCheckRemover = new StateMachineDoFinallyCheckRemover(moveNextMethodContext);
                if (!doFinallyCheckRemover.MarkFinallyConditionsForRemoval())
                {
                    return false;
                }
                toBeRemoved.UnionWith(doFinallyCheckRemover.BlocksMarkedForRemoval);
            }
            else
            {
                return false;
            }

            if (!controllerRemover.RemoveStateMachineController())
            {
                return false;
            }

            toBeRemoved.UnionWith(controllerRemover.BlocksMarkedForRemoval);

            SwitchData switchData = controllerRemover.SwitchData;
            YieldStateMachineControlFlowRebuilder controlFlowRebuilder =
                new YieldStateMachineControlFlowRebuilder(moveNextMethodContext, switchData, controllerRemover.StateField);

            if (!controlFlowRebuilder.ProcessEndBlocks())
            {
                return false;
            }

            toBeRemoved.UnionWith(controlFlowRebuilder.BlocksMarkedForRemoval);
            StateMachineCFGCleaner cfgCleaner = new StateMachineCFGCleaner(theCFG, switchData, switchData.OrderedCasesArray[0]);

            if (!cfgCleaner.CleanUpTheCFG(toBeRemoved))
            {
                return false;
            }

            YieldFieldsInformation fieldsInfo = new YieldFieldsInformation(controllerRemover.StateField,
                    controlFlowRebuilder.CurrentItemField, controlFlowRebuilder.ReturnFlagVariable);

            this.moveNextMethodContext.YieldData =
                new YieldData(machineVersion, controlFlowRebuilder.YieldReturnBlocks,
                    controlFlowRebuilder.YieldBreakBlocks, fieldsInfo, disposeAnalyzer.YieldsExceptionData);
            return true;
        }
Ejemplo n.º 3
0
 private InstructionBlock GetActualCase(InstructionBlock theBlock)
 {
     while ((object)theBlock.get_First() == (object)theBlock.get_Last() && theBlock.get_First().get_OpCode().get_Code() == 55 || theBlock.get_First().get_OpCode().get_Code() == 42)
     {
         V_0      = theBlock.get_First().get_Operand() as Instruction;
         theBlock = this.theDisposeCFG.get_InstructionToBlockMapping().get_Item(V_0.get_Offset());
     }
     theBlock = StateMachineDisposeAnalyzer.SkipSingleNopInstructionBlock(theBlock);
     return(theBlock);
 }