private bool TryMakeLoop(IntervalConstruct interval, DominatorTree dominatorTree)
 {
     V_0 = DFSTBuilder.BuildTree(interval);
     if (V_0.get_BackEdges().get_Count() == 0)
     {
         return(false);
     }
     V_2 = this.BuildLoop(V_0, out V_1);
     V_4 = this.DetermineLoopType(V_1, V_2, interval, dominatorTree, out V_3);
     if (V_1.get_Count() > 0)
     {
         V_5 = new LoopLogicalConstruct(interval.get_Entry() as ILogicalConstruct, V_1, V_4, V_3, this.typeSystem);
         this.CleanUpEdges(V_5);
         this.UpdateDominatorTree(dominatorTree, V_5);
         return(true);
     }
     V_6 = V_0.get_BackEdges().GetEnumerator();
     try
     {
         while (V_6.MoveNext())
         {
             V_7 = V_6.get_Current();
             this.MarkAsGotoEdge(V_7.get_Start().get_Construct() as ILogicalConstruct, V_7.get_End().get_Construct() as ILogicalConstruct);
         }
     }
     finally
     {
         ((IDisposable)V_6).Dispose();
     }
     return(false);
 }
 private Dictionary <ILogicalConstruct, HashSet <ISingleEntrySubGraph> > GetValidCases(DominatorTree dominatorTree, ILogicalConstruct switchCFGBlock)
 {
     V_0 = new SwitchBuilder.u003cu003ec__DisplayClass9_0();
     V_0.caseEntriesToDominatedNodesMap = new Dictionary <ILogicalConstruct, HashSet <ISingleEntrySubGraph> >();
     V_1       = new HashSet <ISingleEntrySubGraph>();
     dummyVar0 = V_1.Add(switchCFGBlock);
     V_4       = switchCFGBlock.get_SameParentSuccessors().GetEnumerator();
     try
     {
         while (V_4.MoveNext())
         {
             V_5 = (ILogicalConstruct)V_4.get_Current();
             if (V_5 == switchCFGBlock || dominatorTree.GetImmediateDominator(V_5) != switchCFGBlock)
             {
                 continue;
             }
             V_6 = dominatorTree.GetDominatedNodes(V_5);
             V_0.caseEntriesToDominatedNodesMap.Add(V_5, V_6);
             V_1.UnionWith(V_6);
         }
     }
     finally
     {
         ((IDisposable)V_4).Dispose();
     }
     stackVariable34 = DFSTBuilder.BuildTree(switchCFGBlock.get_Parent(), switchCFGBlock).get_ReversePostOrder();
     stackVariable35 = SwitchBuilder.u003cu003ec.u003cu003e9__9_0;
     if (stackVariable35 == null)
     {
         dummyVar1       = stackVariable35;
         stackVariable35 = new Func <DFSTNode, ILogicalConstruct>(SwitchBuilder.u003cu003ec.u003cu003e9.u003cGetValidCasesu003eb__9_0);
         SwitchBuilder.u003cu003ec.u003cu003e9__9_0 = stackVariable35;
     }
     V_2 = new List <ILogicalConstruct>(stackVariable34.Select <DFSTNode, ILogicalConstruct>(stackVariable35).Where <ILogicalConstruct>(new Func <ILogicalConstruct, bool>(V_0.u003cGetValidCasesu003eb__1)));
     do
     {
         V_3 = false;
         V_7 = V_2.GetEnumerator();
         try
         {
             while (V_7.MoveNext())
             {
                 V_8 = V_7.get_Current();
                 if (!V_0.caseEntriesToDominatedNodesMap.TryGetValue(V_8, out V_9) || this.IsCaseValid(V_8, V_1))
                 {
                     continue;
                 }
                 V_1.ExceptWith(V_9);
                 dummyVar2 = V_0.caseEntriesToDominatedNodesMap.Remove(V_8);
                 V_3       = true;
             }
         }
         finally
         {
             ((IDisposable)V_7).Dispose();
         }
     }while (V_3);
     return(V_0.caseEntriesToDominatedNodesMap);
 }
Exemple #3
0
 private bool TryMatchInternal(StatementCollection statements, int startIndex, out Statement result)
 {
     result = null;
     if (statements.get_Count() < startIndex + 2)
     {
         return(false);
     }
     if (statements.get_Item(startIndex).get_CodeNodeType() != 5 || statements.get_Item(startIndex + 1).get_CodeNodeType() != 3)
     {
         return(false);
     }
     if (!String.IsNullOrEmpty(statements.get_Item(startIndex + 1).get_Label()))
     {
         return(false);
     }
     V_3 = (statements.get_Item(startIndex) as ExpressionStatement).get_Expression() as BinaryExpression;
     if (!this.IsAssignToVariableExpression(V_3, out V_0))
     {
         return(false);
     }
     V_1 = V_3.get_Right();
     V_4 = statements.get_Item(startIndex + 1) as IfStatement;
     if (this.ContainsDummyAssignment(V_4.get_Then(), V_0))
     {
         stackVariable50 = 1;
     }
     else
     {
         stackVariable50 = 0;
     }
     V_5 = stackVariable50;
     if (V_4.get_Else() != null || V_4.get_Then().get_Statements().get_Count() != 1 + V_5 || V_4.get_Then().get_Statements().get_Item(V_5).get_CodeNodeType() != 5 || !String.IsNullOrEmpty(V_4.get_Then().get_Statements().get_Item(V_5).get_Label()))
     {
         return(false);
     }
     V_6 = V_4.get_Condition() as BinaryExpression;
     if (V_6 == null || V_6.get_Operator() != 9 || V_6.get_Left().get_CodeNodeType() != 26 || (object)(V_6.get_Left() as VariableReferenceExpression).get_Variable() != (object)V_0 || V_6.get_Right().get_CodeNodeType() != 22 || (V_6.get_Right() as LiteralExpression).get_Value() != null)
     {
         return(false);
     }
     V_7 = (V_4.get_Then().get_Statements().get_Item(V_5) as ExpressionStatement).get_Expression() as BinaryExpression;
     if (V_7 == null || !this.IsAssignToVariableExpression(V_7, out V_8) || (object)V_8 != (object)V_0)
     {
         return(false);
     }
     V_2 = V_7.get_Right();
     if (!V_1.get_HasType() || !V_2.get_HasType() || String.op_Inequality(V_1.get_ExpressionType().get_FullName(), V_2.get_ExpressionType().get_FullName()))
     {
         return(false);
     }
     V_9              = new BinaryExpression(27, V_1, V_2, this.typeSystem, null, false);
     V_10             = new BinaryExpression(26, new VariableReferenceExpression(V_0, null), V_9, this.typeSystem, null, false);
     stackVariable150 = new ExpressionStatement(V_10);
     stackVariable150.set_Parent(statements.get_Item(startIndex).get_Parent());
     result = stackVariable150;
     this.FixContext(V_0.Resolve(), 1, V_5 + 1, result as ExpressionStatement);
     return(true);
 }
 private void AddCastIfNeeded(Expression useExpression, VariableReference variable)
 {
     V_0          = new TypeInferer.u003cu003ec__DisplayClass8_0();
     V_0.variable = variable;
     V_4          = useExpression.get_CodeNodeType();
     if (V_4 == 19)
     {
         V_1 = useExpression as MethodInvocationExpression;
         V_2 = V_1.get_Arguments().FirstOrDefault <Expression>(new Func <Expression, bool>(V_0.u003cAddCastIfNeededu003eb__0));
         if (V_2 == null)
         {
             V_7 = V_1.get_MethodExpression().get_Target();
             if (V_7.get_CodeNodeType() != 26 || (object)(V_7 as VariableReferenceExpression).get_Variable() != (object)V_0.variable)
             {
                 this.AddCastIfNeeded(V_7, V_0.variable);
                 return;
             }
             V_8 = V_1.get_MethodExpression().get_Method().get_DeclaringType();
             if (!this.IsSubtype(V_8, V_0.variable.get_VariableType()))
             {
                 V_1.get_MethodExpression().set_Target(new ExplicitCastExpression(V_7, V_8, null));
                 return;
             }
         }
         else
         {
             V_5 = V_1.get_Arguments().IndexOf(V_2);
             V_6 = V_1.get_MethodExpression().get_Method().get_Parameters().get_Item(V_5).ResolveParameterType(V_1.get_MethodExpression().get_Method());
             if (!this.IsSubtype(V_6, V_0.variable.get_VariableType()))
             {
                 if (V_6.get_IsPrimitive() && V_0.variable.get_VariableType().get_IsPrimitive() && String.op_Equality(ExpressionTypeInferer.GetContainingType(V_6.Resolve(), V_0.variable.get_VariableType().Resolve()).get_FullName(), V_6.get_FullName()))
                 {
                     return;
                 }
                 V_1.get_Arguments().set_Item(V_5, new ExplicitCastExpression(V_2, V_6, null));
                 return;
             }
         }
     }
     else
     {
         if (V_4 != 24)
         {
             return;
         }
         V_3 = useExpression as BinaryExpression;
         if (V_3.get_Operator() == 26 && V_3.get_Right().get_CodeNodeType() == 26 && (object)(V_3.get_Right() as VariableReferenceExpression).get_Variable() == (object)V_0.variable)
         {
             V_9 = V_3.get_Left().get_ExpressionType();
             if (!this.IsSubtype(V_9, V_0.variable.get_VariableType()))
             {
                 V_3.set_Right(new ExplicitCastExpression(V_3.get_Right(), V_9, null));
             }
         }
     }
     return;
 }
Exemple #5
0
 public List <FileViewModel> GetWebFiles(string folder)
 {
     stackVariable1    = new string[3];
     stackVariable1[0] = "wwwroot";
     stackVariable1[1] = "content";
     stackVariable1[2] = folder;
     V_0 = CommonHelper.GetFullPath(stackVariable1);
     this.CreateDirectoryIfNotExist(V_0);
     V_1 = new List <FileViewModel>();
     V_2 = Directory.GetDirectories(V_0, "*", 1);
     V_3 = 0;
     while (V_3 < (int)V_2.Length)
     {
         V_4             = new DirectoryInfo(V_2[V_3]);
         V_5             = V_4.ToString().Replace("\\", "/").Replace("wwwroot", string.Empty);
         stackVariable34 = V_4.GetFiles();
         stackVariable35 = FileRepository.u003cu003ec.u003cu003e9__31_0;
         if (stackVariable35 == null)
         {
             dummyVar0       = stackVariable35;
             stackVariable35 = new Func <FileInfo, DateTime>(FileRepository.u003cu003ec.u003cu003e9.u003cGetWebFilesu003eb__31_0);
             FileRepository.u003cu003ec.u003cu003e9__31_0 = stackVariable35;
         }
         V_6 = ((IEnumerable <FileInfo>)stackVariable34).OrderByDescending <FileInfo, DateTime>(stackVariable35).GetEnumerator();
         try
         {
             while (V_6.MoveNext())
             {
                 V_7             = V_6.get_Current();
                 stackVariable42 = V_1;
                 stackVariable43 = new FileViewModel();
                 stackVariable43.set_FolderName(V_4.get_Name());
                 stackVariable43.set_FileFolder(V_5);
                 if (V_7.get_Name().LastIndexOf('.') >= 0)
                 {
                     stackVariable59 = V_7.get_Name().Substring(0, V_7.get_Name().LastIndexOf('.'));
                 }
                 else
                 {
                     stackVariable59 = V_7.get_Name();
                 }
                 stackVariable43.set_Filename(stackVariable59);
                 stackVariable43.set_Extension(V_7.get_Extension());
                 stackVariable42.Add(stackVariable43);
             }
         }
         finally
         {
             if (V_6 != null)
             {
                 V_6.Dispose();
             }
         }
         V_3 = V_3 + 1;
     }
     return(V_1);
 }
Exemple #6
0
 public static void LogException(Exception ex)
 {
     stackVariable0 = Environment.get_CurrentDirectory();
     V_2            = DateTime.get_Now();
     V_0            = string.Concat(stackVariable0, "/logs/", V_2.ToString("dd-MM-yyyy"));
     if (!string.IsNullOrEmpty(V_0) && !Directory.Exists(V_0))
     {
         dummyVar0 = Directory.CreateDirectory(V_0);
     }
     V_1 = string.Concat(V_0, "/log_exceptions.json");
     try
     {
         V_3 = new FileInfo(V_1);
         V_4 = "[]";
         if (V_3.get_Exists())
         {
             V_6 = V_3.OpenText();
             try
             {
                 V_4 = V_6.ReadToEnd();
             }
             finally
             {
                 if (V_6 != null)
                 {
                     ((IDisposable)V_6).Dispose();
                 }
             }
             File.Delete(V_1);
         }
         stackVariable18 = JArray.Parse(V_4);
         stackVariable19 = new JObject();
         stackVariable19.Add(new JProperty("CreatedDateTime", (object)DateTime.get_UtcNow()));
         stackVariable19.Add(new JProperty("Details", JObject.FromObject(ex)));
         stackVariable18.Add(stackVariable19);
         V_4 = stackVariable18.ToString();
         V_7 = File.CreateText(V_1);
         try
         {
             V_7.WriteLine(V_4);
         }
         finally
         {
             if (V_7 != null)
             {
                 ((IDisposable)V_7).Dispose();
             }
         }
     }
     catch
     {
         dummyVar1 = exception_0;
         Console.Write(string.Concat("Cannot write log file ", V_1));
     }
     return;
 }
Exemple #7
0
 protected virtual void BuildUpHardNodesHierarchy(IEnumerable <ClassHierarchyNode> hardNodes)
 {
     V_0 = new Queue <ClassHierarchyNode>(hardNodes);
     V_1 = new HashSet <ClassHierarchyNode>();
     while (V_0.get_Count() > 0)
     {
         V_2       = V_0.Dequeue();
         dummyVar0 = V_1.Add(V_2);
         dummyVar1 = this.resultingGraph.Add(V_2);
         V_3       = V_2.get_NodeType().Resolve();
         V_4       = null;
         if (V_3 == null)
         {
             continue;
         }
         V_4 = V_3.get_BaseType();
         if (V_4 != null)
         {
             V_5 = this.GetTypeNode(V_4);
             V_2.AddSupertype(V_5);
             if (!V_1.Contains(V_5))
             {
                 V_0.Enqueue(V_5);
             }
         }
         if (V_3.get_IsInterface())
         {
             V_2.AddSupertype(this.GetTypeNode(this.typeSystem.get_Object()));
         }
         V_7 = V_2.get_NodeType().Resolve().get_Interfaces().GetEnumerator();
         try
         {
             while (V_7.MoveNext())
             {
                 V_8 = V_7.get_Current();
                 V_9 = this.GetTypeNode(V_8);
                 V_2.AddSupertype(V_9);
                 if (V_1.Contains(V_9))
                 {
                     continue;
                 }
                 V_0.Enqueue(V_9);
             }
         }
         finally
         {
             if (V_7 != null)
             {
                 V_7.Dispose();
             }
         }
     }
     this.AddObjectClassNodeIfMIssing();
     return;
 }
		private void GenerateStackData()
		{
			V_0 = new StackUsageData();
			V_1 = this.instructionOffsetToUsedInstructionsMap.GetEnumerator();
			try
			{
				while (V_1.MoveNext())
				{
					V_2 = V_1.get_Current();
					V_3 = new List<VariableDefinition>(V_2.get_Value().Select<int, VariableDefinition>(new Func<int, VariableDefinition>(this.u003cGenerateStackDatau003eb__25_0)));
					V_0.get_InstructionOffsetToUsedStackVariablesMap().set_Item(V_2.get_Key(), V_3);
					V_4 = V_3.GetEnumerator();
					try
					{
						while (V_4.MoveNext())
						{
							V_5 = V_4.get_Current();
							this.GetDefineUseInfo(V_0, V_5).get_UsedAt().Add(V_2.get_Key());
						}
					}
					finally
					{
						((IDisposable)V_4).Dispose();
					}
				}
			}
			finally
			{
				((IDisposable)V_1).Dispose();
			}
			V_6 = this.instructionOffsetToVariableDefinitionMap.GetEnumerator();
			try
			{
				while (V_6.MoveNext())
				{
					V_7 = V_6.get_Current();
					if (V_7.get_Key() >= 0)
					{
						V_0.get_InstructionOffsetToAssignedVariableMap().Add(V_7.get_Key(), V_7.get_Value());
						dummyVar0 = this.GetDefineUseInfo(V_0, V_7.get_Value()).get_DefinedAt().Add(V_7.get_Key());
					}
					else
					{
						V_0.get_ExceptionHandlerStartToExceptionVariableMap().Add(-V_7.get_Key(), V_7.get_Value());
					}
				}
			}
			finally
			{
				((IDisposable)V_6).Dispose();
			}
			this.methodContext.set_StackData(V_0);
			return;
		}
Exemple #9
0
 private void AddBlocks(List <ILBlock.InstructionPair> allBranches)
 {
     V_0 = allBranches.get_Count() - 1;
     while (V_0 >= 0)
     {
         V_1 = allBranches.get_Item(V_0).get_FirstInstruction().get_Offset() + allBranches.get_Item(V_0).get_FirstInstruction().GetSize();
         V_2 = allBranches.get_Item(V_0).get_SecondInstruction().get_Offset();
         if (V_2 < V_1)
         {
             V_3 = null;
             V_4 = allBranches.get_Item(V_0).get_SecondInstruction().get_Previous();
             if (V_4 != null && !OpCodeInfo.IsUnconditionalBranch(V_4.get_OpCode()))
             {
                 V_3 = allBranches.get_Item(V_0).get_SecondInstruction();
             }
             V_5 = false;
             V_6 = allBranches.GetEnumerator();
             try
             {
                 while (V_6.MoveNext())
                 {
                     V_7 = V_6.get_Current();
                     if (V_7.get_FirstInstruction().get_Offset() >= V_2 && V_7.get_FirstInstruction().get_Offset() < V_1 || V_2 > V_7.get_SecondInstruction().get_Offset() || V_7.get_SecondInstruction().get_Offset() >= V_1)
                     {
                         continue;
                     }
                     if (V_3 != null)
                     {
                         if ((object)V_7.get_SecondInstruction() == (object)V_3)
                         {
                             continue;
                         }
                         V_5 = true;
                     }
                     else
                     {
                         V_3 = V_7.get_SecondInstruction();
                     }
                 }
             }
             finally
             {
                 ((IDisposable)V_6).Dispose();
             }
             if (!V_5)
             {
                 dummyVar0 = this.AddNestedBlock(new ILBlock(1, V_2, V_1, V_3));
             }
         }
         V_0 = V_0 - 1;
     }
     return;
 }
 private void MarkOptimizationAndCaseBlocks(InstructionBlock block, RemoveCompilerOptimizationsStep.SwitchData data)
 {
     V_0 = new Queue <InstructionBlock>();
     V_1 = new HashSet <int>();
     V_2 = block.get_Successors();
     V_3 = 0;
     while (V_3 < (int)V_2.Length)
     {
         V_0.Enqueue(V_2[V_3]);
         V_3 = V_3 + 1;
     }
     while (V_0.get_Count() > 0)
     {
         V_5       = V_0.Dequeue();
         dummyVar0 = V_1.Add(V_5.get_First().get_Offset());
         if (!this.IsOptimizationBlock(this.blockExpressions.get_Item(V_5.get_First().get_Offset()), data.get_OptimizationVariable()))
         {
             if (!this.IsCaseBlock(this.blockExpressions.get_Item(V_5.get_First().get_Offset()), data.get_SwitchExpression()) && !this.IsNullCaseBlock(this.blockExpressions.get_Item(V_5.get_First().get_Offset()), data.get_SwitchExpression()))
             {
                 continue;
             }
             this.switchBlocksToCasesMap.get_Item(block.get_First().get_Offset()).Add(V_5.get_First().get_Offset());
             V_8 = V_5.get_Successors()[1];
             if (this.IsEmptyStringCaseBlock(this.blockExpressions.get_Item(V_8.get_First().get_Offset()), data.get_SwitchExpression()))
             {
                 V_5.set_Last(V_8.get_Last());
                 V_5.set_Successors(V_8.get_Successors());
                 V_9 = this.blockExpressions.get_Item(V_5.get_First().get_Offset()).get_Item(0) as BinaryExpression;
                 V_9.set_Right(new LiteralExpression("", this.methodContext.get_Method().get_Module().get_TypeSystem(), null));
                 V_10 = this.blockExpressions.get_Item(V_8.get_First().get_Offset()).get_Item(0).get_UnderlyingSameMethodInstructions();
                 V_9  = V_9.CloneAndAttachInstructions(V_10) as BinaryExpression;
                 this.blockExpressions.get_Item(V_5.get_First().get_Offset()).set_Item(0, new UnaryExpression(11, V_9, null));
                 this.blocksToBeRemoved.Add(V_8.get_First().get_Offset());
             }
             dummyVar1 = this.MarkSecondSuccessorForRemovalIfItIsUnconditionalJump(V_5);
         }
         else
         {
             V_6 = V_5.get_Successors()[0];
             if (!V_1.Contains(V_6.get_First().get_Offset()))
             {
                 V_0.Enqueue(V_6);
             }
             V_7 = this.MarkSecondSuccessorForRemovalIfItIsUnconditionalJump(V_5);
             if (!V_1.Contains(V_7.get_First().get_Offset()) && this.IsOptimizationBlock(this.blockExpressions.get_Item(V_5.get_First().get_Offset()), data.get_OptimizationVariable()))
             {
                 V_0.Enqueue(V_7);
             }
             this.blocksToBeRemoved.Add(V_5.get_First().get_Offset());
         }
     }
     return;
 }
Exemple #11
0
 protected virtual string ToString(string constructName, HashSet <CFGBlockLogicalConstruct> printedCFGBlocks, LogicalFlowBuilderContext context)
 {
     V_0       = new StringBuilder();
     dummyVar0 = V_0.AppendLine(constructName);
     dummyVar1 = V_0.AppendLine("{");
     V_1       = this.GetSortedArrayFromCollection <CFGBlockLogicalConstruct>(this.get_CFGBlocks());
     V_2       = new Stack <CFGBlockLogicalConstruct>();
     V_4       = 0;
     while (V_4 < (int)V_1.Length)
     {
         V_5 = V_1[V_4] as CFGBlockLogicalConstruct;
         if (!printedCFGBlocks.Contains(V_5))
         {
             V_2.Push(V_5);
             while (V_2.get_Count() > 0)
             {
                 V_6 = V_2.Pop();
                 if (printedCFGBlocks.Contains(V_6) || !LogicalFlowUtilities.TryGetParentConstructWithGivenParent(V_6, this, out V_7))
                 {
                     continue;
                 }
                 stackVariable48    = ((LogicalConstructBase)V_7).ToString(V_7.GetType().get_Name(), printedCFGBlocks, context);
                 stackVariable50    = new String[1];
                 stackVariable50[0] = Environment.get_NewLine();
                 V_9  = stackVariable48.Split(stackVariable50, 1);
                 V_10 = 0;
                 while (V_10 < (int)V_9.Length)
                 {
                     V_11      = V_9[V_10];
                     dummyVar2 = V_0.AppendLine(String.Format("\t{0}", V_11));
                     V_10      = V_10 + 1;
                 }
                 V_8  = this.GetSortedArrayFromCollection <ISingleEntrySubGraph>(V_7.get_SameParentSuccessors());
                 V_12 = (int)V_8.Length - 1;
                 while (V_12 >= 0)
                 {
                     if (!printedCFGBlocks.Contains(V_8[V_12].get_FirstBlock()))
                     {
                         V_2.Push(V_8[V_12].get_FirstBlock());
                     }
                     V_12 = V_12 - 1;
                 }
             }
         }
         V_4 = V_4 + 1;
     }
     V_3       = String.Format("\tFollowNode: {0}", this.NodeILOffset(context, this.get_CFGFollowNode()));
     dummyVar3 = V_0.AppendLine(V_3);
     dummyVar4 = V_0.AppendLine("}");
     return(V_0.ToString());
 }
Exemple #12
0
 private string RemoveLeadingLineWhitespaces(string text)
 {
     V_0 = new StringBuilder();
     V_1 = new List <string>();
     V_2 = 0x7fffffff;
     V_3 = new StringReader(text);
     try
     {
         V_4 = V_3.ReadLine();
         while (V_4 != null)
         {
             V_5 = 0;
             while (V_5 < V_4.get_Length())
             {
                 if (Char.IsWhiteSpace(V_4.get_Chars(V_5)))
                 {
                     V_5 = V_5 + 1;
                 }
                 else
                 {
                     V_2 = Math.Min(V_2, V_5);
                     V_1.Add(V_4);
                     break;
                 }
             }
             V_4 = V_3.ReadLine();
         }
     }
     finally
     {
         if (V_3 != null)
         {
             ((IDisposable)V_3).Dispose();
         }
     }
     V_6 = V_1.GetEnumerator();
     try
     {
         while (V_6.MoveNext())
         {
             V_7       = V_6.get_Current();
             dummyVar0 = V_0.AppendLine(V_7.Substring(V_2));
         }
     }
     finally
     {
         ((IDisposable)V_6).Dispose();
     }
     return(V_0.ToString());
 }
Exemple #13
0
 protected override void OnPhiVariableUsed(int instructionOffset, ClassHierarchyNode variableNode)
 {
     V_0 = this.offsetToInstruction.get_Item(instructionOffset);
     if (V_0.get_OpCode().get_Code() == 36 || V_0.get_OpCode().get_Code() == 37)
     {
         return;
     }
     V_1 = this.GetUseExpressionTypeNode(V_0, variableNode.get_Variable());
     if (V_0.get_OpCode().get_Code() == 68)
     {
         variableNode.AddSupertype(V_1);
         dummyVar0 = this.resultingGraph.Add(V_1);
         return;
     }
     if (!String.op_Equality(V_1.get_NodeType().get_FullName(), "System.Int32") || !this.OnlyPhiVariablesUsed(this.offsetToExpression.get_Item(V_0.get_Offset())))
     {
         variableNode.AddSupertype(V_1);
         dummyVar2 = this.resultingGraph.Add(V_1);
         return;
     }
     V_3 = this.GetUsedPhiVariableNodes(V_0.get_Offset());
     V_4 = 0;
     while (V_4 < V_3.get_Count())
     {
         V_5 = V_4 + 1;
         while (V_5 < V_3.get_Count())
         {
             V_3.get_Item(V_4).AddSupertype(V_3.get_Item(V_5));
             V_3.get_Item(V_5).AddSupertype(V_3.get_Item(V_4));
             V_5 = V_5 + 1;
         }
         V_4 = V_4 + 1;
     }
     if (this.IsArithmeticOperation(V_0.get_OpCode().get_Code()))
     {
         V_6 = 0;
         while (V_6 < V_3.get_Count())
         {
             dummyVar1 = this.notPossibleBooleanNodes.Add(V_3.get_Item(V_6));
             V_7       = this.GetTypeNode(this.typeSystem.get_Int32());
             if (!V_7.get_CanAssignTo().Contains(V_3.get_Item(V_6)))
             {
                 V_7.get_CanAssignTo().Add(V_3.get_Item(V_6));
                 V_3.get_Item(V_6).get_SubTypes().Add(V_7);
             }
             V_6 = V_6 + 1;
         }
     }
     return;
 }
 private Dictionary <string, List <string> > GetModuleCollisionTypesData(ModuleDefinition module, ILanguage language)
 {
     V_0 = new Dictionary <string, List <string> >(language.get_IdentifierComparer());
     V_1 = new Dictionary <string, string>(language.get_IdentifierComparer());
     this.UpdateCollisionTypesDataWithTypes(V_0, V_1, module.get_Types());
     V_2 = this.GetModuleDependsOnAnalysis(module);
     if (Mono.Cecil.AssemblyResolver.Extensions.IsReferenceAssembly(module))
     {
         stackVariable16 = 1;
     }
     else
     {
         stackVariable16 = 0;
     }
     V_3 = stackVariable16;
     V_4 = V_2.get_Keys().GetEnumerator();
     try
     {
         while (V_4.MoveNext())
         {
             V_5 = V_4.get_Current();
             V_6 = module.get_AssemblyResolver().Resolve(V_5, "", ModuleDefinitionExtensions.GetModuleArchitecture(module), V_3, true);
             if (V_6 == null)
             {
                 this.UpdateCollisionTypesDataWithTypes(V_0, V_1, V_2.get_Item(V_5));
             }
             else
             {
                 V_7 = V_6.get_Modules().GetEnumerator();
                 try
                 {
                     while (V_7.MoveNext())
                     {
                         V_8 = V_7.get_Current();
                         this.UpdateCollisionTypesDataWithTypes(V_0, V_1, V_8.get_Types());
                     }
                 }
                 finally
                 {
                     V_7.Dispose();
                 }
             }
         }
     }
     finally
     {
         ((IDisposable)V_4).Dispose();
     }
     return(V_0);
 }
 public ICodeNode VisitMethodInvocationExpression(MethodInvocationExpression node)
 {
     if (node.get_MethodExpression() == null)
     {
         return(null);
     }
     V_0 = node.get_MethodExpression();
     V_1 = V_0.get_Method();
     if (V_1.get_Name() == null)
     {
         return(null);
     }
     V_2 = this.GetEventMethodPrefix(V_1.get_Name());
     if (String.IsNullOrEmpty(V_2))
     {
         return(null);
     }
     if (V_1.get_Parameters().get_Count() != 1)
     {
         return(null);
     }
     V_3 = V_1.get_DeclaringType();
     V_4 = null;
     do
     {
         V_6 = new RebuildEventsStep.u003cu003ec__DisplayClass2_0();
         if (V_3 == null)
         {
             break;
         }
         V_7 = V_3.Resolve();
         if (V_7 == null)
         {
             break;
         }
         V_6.eventName = V_1.get_Name().Substring(V_2.get_Length());
         V_4           = V_7.get_Events().FirstOrDefault <EventDefinition>(new Func <EventDefinition, bool>(V_6.u003cVisitMethodInvocationExpressionu003eb__0));
         if (V_4 != null)
         {
             continue;
         }
         V_3 = V_7.get_BaseType();
     }while (V_3 != null && V_4 == null);
     if (V_4 == null)
     {
         return(null);
     }
     V_5 = new EventReferenceExpression(V_0.get_Target(), V_4, null);
     return(this.GetEventAssignExpression(V_5, node.get_Arguments().get_Item(0), V_2, node.get_InvocationInstructions()));
 }
Exemple #16
0
 private bool SubtreeEndsInInstructionCode(InstructionBlock entryBlock, IEnumerable <Code> operationCodes)
 {
     V_0 = true;
     V_1 = new Queue <InstructionBlock>();
     V_2 = new HashSet <int>();
     V_1.Enqueue(entryBlock);
     while (V_1.get_Count() > 0 & V_0)
     {
         V_3 = V_1.Dequeue();
         if (V_2.Contains(V_3.get_First().get_Offset()))
         {
             continue;
         }
         dummyVar0 = V_2.Add(V_3.get_First().get_Offset());
         if (V_3.get_Successors().Length != 0)
         {
             V_8 = V_3.get_Successors();
             V_9 = 0;
             while (V_9 < (int)V_8.Length)
             {
                 V_1.Enqueue(V_8[V_9]);
                 V_9 = V_9 + 1;
             }
         }
         else
         {
             V_4 = false;
             V_5 = operationCodes.GetEnumerator();
             try
             {
                 while (V_5.MoveNext())
                 {
                     V_6 = V_5.get_Current();
                     V_7 = V_3.get_Last().get_OpCode();
                     V_4 = V_4 | V_7.get_Code() == V_6;
                 }
             }
             finally
             {
                 if (V_5 != null)
                 {
                     V_5.Dispose();
                 }
             }
             V_0 = V_0 & V_4;
         }
     }
     return(V_0);
 }
 private HashSet <ILogicalConstruct> BuildLoop(DFSTree tree, out HashSet <ILogicalConstruct> loopBody)
 {
     loopBody = new HashSet <ILogicalConstruct>();
     V_0      = new HashSet <ILogicalConstruct>();
     V_1      = tree.get_BackEdges().GetEnumerator();
     try
     {
         while (V_1.MoveNext())
         {
             V_2 = V_1.get_Current();
             V_3 = V_2.get_End().get_Construct() as ILogicalConstruct;
             V_4 = V_2.get_Start().get_Construct() as ILogicalConstruct;
             if (this.removedEdges.ContainsKey(V_4) && this.removedEdges.get_Item(V_4).Contains(V_3))
             {
                 continue;
             }
             V_5 = tree.GetPath(V_2.get_End(), V_2.get_Start());
             V_6 = this.ExpandLoopBodyWithCrossEdges(V_5);
             V_7 = this.GetConstructsCollection(V_6);
             if (!this.CanBeLoop(V_3, V_4, V_6))
             {
                 continue;
             }
             dummyVar0 = V_0.Add(V_4);
             V_8       = V_7.GetEnumerator();
             try
             {
                 while (V_8.MoveNext())
                 {
                     V_9       = V_8.get_Current();
                     dummyVar1 = loopBody.Add(V_9);
                 }
             }
             finally
             {
                 if (V_8 != null)
                 {
                     V_8.Dispose();
                 }
             }
         }
     }
     finally
     {
         ((IDisposable)V_1).Dispose();
     }
     return(V_0);
 }
Exemple #18
0
 private void RemoveUnreachableBlocks()
 {
     V_0 = new HashSet <InstructionBlock>();
     V_1 = this.theCFG.get_Blocks();
     V_2 = 0;
     while (V_2 < (int)V_1.Length)
     {
         V_3 = V_1[V_2];
         if (!this.reachableBlocks.Contains(V_3))
         {
             V_3.set_Successors(new InstructionBlock[0]);
             dummyVar0 = V_0.Add(V_3);
         }
         V_2 = V_2 + 1;
     }
     if (V_0.get_Count() > 0)
     {
         this.decompilationContext.get_MethodContext().set_IsMethodBodyChanged(true);
     }
     V_4 = 0;
     while (V_4 < this.theCFG.get_RawExceptionHandlers().get_Count())
     {
         V_5 = this.theCFG.get_RawExceptionHandlers().get_Item(V_4);
         if (V_0.Contains(this.theCFG.get_InstructionToBlockMapping().get_Item(V_5.get_TryStart().get_Offset())))
         {
             stackVariable54 = V_4;
             V_4             = stackVariable54 - 1;
             this.theCFG.get_RawExceptionHandlers().RemoveAt(stackVariable54);
         }
         V_4 = V_4 + 1;
     }
     V_6 = V_0.GetEnumerator();
     try
     {
         while (V_6.MoveNext())
         {
             V_7 = V_6.get_Current();
             this.theCFG.RemoveBlockAt(V_7.get_Index());
         }
     }
     finally
     {
         ((IDisposable)V_6).Dispose();
     }
     return;
 }
Exemple #19
0
 private bool IsThreadSafeAutoImplOperation(MethodDefinition methodDef, string operationName)
 {
     if (!this.CheckMethodAndDecompile(methodDef, out V_0) || V_0.get_Statements().get_Count() != 3)
     {
         return(false);
     }
     V_1 = null;
     V_2 = null;
     if (!V_0.get_Statements().get_Item(0).IsAssignmentStatement())
     {
         return(false);
     }
     V_3 = (V_0.get_Statements().get_Item(0) as ExpressionStatement).get_Expression() as BinaryExpression;
     if (V_3.get_Left().get_CodeNodeType() != 26 || V_3.get_Right().get_CodeNodeType() != 30 || (object)(V_3.get_Right() as FieldReferenceExpression).get_Field().Resolve() != (object)this.eventField)
     {
         return(false);
     }
     V_1 = (V_3.get_Left() as VariableReferenceExpression).get_Variable();
     if (V_0.get_Statements().get_Item(1).get_CodeNodeType() != 8 || V_0.get_Statements().get_Item(2).get_CodeNodeType() != 5 || (V_0.get_Statements().get_Item(2) as ExpressionStatement).get_Expression().get_CodeNodeType() != 57)
     {
         return(false);
     }
     V_4 = V_0.get_Statements().get_Item(1) as DoWhileStatement;
     V_5 = V_4.get_Condition();
     if (V_5.get_CodeNodeType() == 23 && (V_5 as UnaryExpression).get_Operator() == 11)
     {
         V_5 = (V_5 as UnaryExpression).get_Operand();
     }
     if (V_5.get_CodeNodeType() != 24)
     {
         return(false);
     }
     stackVariable78 = V_5 as BinaryExpression;
     V_6             = stackVariable78.get_Left() as ExplicitCastExpression;
     V_7             = stackVariable78.get_Right() as ExplicitCastExpression;
     if (stackVariable78.get_Operator() != 10 || V_6 == null || String.op_Inequality(V_6.get_TargetType().get_Name(), "Object") || V_6.get_Expression().get_CodeNodeType() != 26 || V_7 == null || V_7.get_Expression().get_CodeNodeType() != 26 || String.op_Inequality(V_7.get_TargetType().get_Name(), "Object"))
     {
         return(false);
     }
     if ((object)(V_6.get_Expression() as VariableReferenceExpression).get_Variable() != (object)V_1)
     {
         return(false);
     }
     V_2 = (V_7.get_Expression() as VariableReferenceExpression).get_Variable();
     return(this.CheckLoopBody(V_4.get_Body(), V_1, V_2, operationName));
 }
Exemple #20
0
 public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
 {
     if (member as TypeDefinition == null || member != Utilities.GetOuterMostDeclaringType(member))
     {
         V_1 = this.GetDecompiledType(member, language);
         V_0 = this.GetTypeContext(V_1, language);
     }
     else
     {
         V_7 = member as TypeDefinition;
         V_8 = this.GetNestedDecompiledTypes(V_7, language);
         V_0 = this.GetTypeContext(V_7, language, V_8);
         this.AddTypeContextsToCache(V_8, V_7, language);
         if (!V_8.TryGetValue(V_7.get_FullName(), out V_1))
         {
             throw new Exception("Decompiled type not found in decompiled types cache.");
         }
     }
     V_2 = new TypeSpecificContext(V_0.get_CurrentType(), V_0.get_MethodDefinitionToNameMap(), V_0.get_BackingFieldToNameMap(), V_0.get_UsedNamespaces(), new HashSet <string>(), V_0.get_AssignmentData(), V_0.get_AutoImplementedProperties(), V_0.get_AutoImplementedEvents(), V_0.get_ExplicitlyImplementedMembers(), V_0.get_ExceptionWhileDecompiling(), V_0.get_GeneratedFilterMethods(), V_0.get_GeneratedMethodDefinitionToNameMap());
     if (V_2.get_GeneratedFilterMethods().get_Count() > 0)
     {
         this.AddGeneratedFilterMethodsToDecompiledType(V_1, V_2, language);
     }
     V_3 = new Dictionary <string, MethodSpecificContext>();
     V_4 = new Dictionary <string, Statement>();
     V_9 = V_1.get_DecompiledMembers().GetEnumerator();
     try
     {
         while (V_9.MoveNext())
         {
             V_10 = V_9.get_Current();
             V_3.Add(V_10.get_Key(), V_10.get_Value().get_Context());
             V_4.Add(V_10.get_Key(), V_10.get_Value().get_Statement());
         }
     }
     finally
     {
         ((IDisposable)V_9).Dispose();
     }
     V_5             = Utilities.GetDeclaringTypeOrSelf(member);
     stackVariable66 = this.GetAssemblyContext(V_5.get_Module().get_Assembly(), language);
     V_6             = this.GetModuleContext(V_5.get_Module(), language);
     return(new WriterContext(stackVariable66, V_6, V_2, V_3, V_4));
 }
 private WriterContext GetWriterContextForType(TypeDefinition type, ILanguage language)
 {
     V_0 = Utilities.GetOuterMostDeclaringType(type);
     if (!this.cacheService.AreNestedDecompiledTypesInCache(V_0, language, this.renameInvalidMembers))
     {
         V_1 = this.GetNestedDecompiledTypes(V_0, language);
         this.cacheService.AddNestedDecompiledTypesToCache(V_0, language, this.renameInvalidMembers, V_1);
     }
     else
     {
         V_1 = this.cacheService.GetNestedDecompiledTypesFromCache(V_0, language, this.renameInvalidMembers);
     }
     V_2 = this.GetTypeContext(V_0, language, V_1);
     this.AddTypeContextsToCache(V_1, V_0, language);
     V_3 = new Dictionary <string, MethodSpecificContext>();
     V_4 = new Dictionary <string, Statement>();
     if (!V_1.TryGetValue(type.get_FullName(), out V_5))
     {
         throw new Exception("Decompiled type missing from DecompiledTypes cache.");
     }
     if (V_2.get_GeneratedFilterMethods().get_Count() > 0)
     {
         this.AddGeneratedFilterMethodsToDecompiledType(V_5, V_2, language);
     }
     V_7 = V_5.get_DecompiledMembers().get_Values().GetEnumerator();
     try
     {
         while (V_7.MoveNext())
         {
             V_8 = V_7.get_Current();
             V_3.Add(V_8.get_MemberFullName(), V_8.get_Context());
             V_4.Add(V_8.get_MemberFullName(), V_8.get_Statement());
         }
     }
     finally
     {
         ((IDisposable)V_7).Dispose();
     }
     stackVariable63 = this.GetAssemblyContext(V_0.get_Module().get_Assembly(), language);
     V_6             = this.GetModuleContext(V_0.get_Module(), language);
     return(new WriterContext(stackVariable63, V_6, V_2, V_3, V_4));
 }
Exemple #22
0
 private void MoveIn(IfStatement gotoStatement, Statement targetStatement, string label)
 {
     V_0 = gotoStatement.get_Parent() as BlockStatement;
     V_1 = new VariableReferenceExpression(this.GetLabelVariable(label), null);
     this.ExtractConditionIntoVariable(V_1.CloneExpressionOnly() as VariableReferenceExpression, gotoStatement, V_0);
     V_2 = V_0.get_Statements().IndexOf(gotoStatement);
     V_3 = V_0.get_Statements().IndexOf(targetStatement);
     V_4 = this.CollectStatements(V_2 + 1, V_3, V_0);
     V_5 = new IfStatement(new UnaryExpression(1, V_1.CloneExpressionOnly(), null), V_4, null);
     if (V_5.get_Then().get_Statements().get_Count() > 0)
     {
         V_0.AddStatementAt(V_2, V_5);
     }
     dummyVar0 = V_0.get_Statements().Remove(gotoStatement);
     if (targetStatement as DoWhileStatement != null)
     {
         (targetStatement as DoWhileStatement).get_Body().AddStatementAt(0, gotoStatement);
         return;
     }
     if (targetStatement as IfStatement != null)
     {
         V_6 = targetStatement as IfStatement;
         V_6.set_Condition(this.UpdateCondition(V_6.get_Condition(), V_1.CloneExpressionOnly() as VariableReferenceExpression));
         V_6.get_Then().AddStatementAt(0, gotoStatement);
         return;
     }
     if (targetStatement as SwitchCase != null)
     {
         this.MoveInCase(gotoStatement, targetStatement as SwitchCase, label);
         return;
     }
     if (targetStatement as WhileStatement == null)
     {
         throw new NotSupportedException("Unsupported target statement for goto jump.");
     }
     V_7 = targetStatement as WhileStatement;
     V_7.get_Body().AddStatementAt(0, gotoStatement);
     V_7.set_Condition(this.UpdateCondition(V_7.get_Condition(), V_1.CloneExpressionOnly() as VariableReferenceExpression));
     return;
 }
Exemple #23
0
 internal ICollection <ClassHierarchyNode> BuildHierarchy(HashSet <VariableReference> resolvedVariables)
 {
     V_1 = this.methodContext.get_StackData().get_VariableToDefineUseInfo().GetEnumerator();
     try
     {
         while (V_1.MoveNext())
         {
             V_2 = V_1.get_Current();
             V_3 = V_2.get_Key();
             if (resolvedVariables.Contains(V_3) || !this.ShouldConsiderVariable(V_3))
             {
                 continue;
             }
             V_4       = this.GetVariableNode(V_3);
             dummyVar0 = this.resultingGraph.Add(V_4);
             V_5       = V_2.get_Value().get_DefinedAt().GetEnumerator();
             try
             {
                 while (V_5.MoveNext())
                 {
                     V_6 = V_5.get_Current();
                     this.OnPhiVariableAssigned(V_6, V_4);
                 }
             }
             finally
             {
                 ((IDisposable)V_5).Dispose();
             }
             V_7 = V_2.get_Value().get_UsedAt().GetEnumerator();
             try
             {
                 while (V_7.MoveNext())
                 {
                     V_8 = V_7.get_Current();
                     this.OnPhiVariableUsed(V_8, V_4);
                 }
             }
             finally
             {
                 ((IDisposable)V_7).Dispose();
             }
         }
     }
     finally
     {
         ((IDisposable)V_1).Dispose();
     }
     this.RemoveImpossibleEdges();
     V_0 = new HashSet <ClassHierarchyNode>();
     V_9 = this.resultingGraph.GetEnumerator();
     try
     {
         while (V_9.MoveNext())
         {
             V_10 = V_9.get_Current();
             if (!V_10.get_IsHardNode())
             {
                 continue;
             }
             dummyVar1 = V_0.Add(V_10);
         }
     }
     finally
     {
         ((IDisposable)V_9).Dispose();
     }
     this.BuildUpHardNodesHierarchy(V_0);
     return(this.resultingGraph);
 }
		public static ICollection<TypeReference> GetAssemblyAttributesUsedTypes(AssemblyDefinition assembly)
		{
			V_0 = new List<TypeReference>();
			V_1 = new List<ICustomAttribute>();
			V_1.Add(AttributesUtilities.GetAssemblyVersionAttribute(assembly));
			V_3 = assembly.get_CustomAttributes().GetEnumerator();
			try
			{
				while (V_3.MoveNext())
				{
					V_4 = V_3.get_Current();
					V_4.Resolve();
					V_1.Add(V_4);
				}
			}
			finally
			{
				V_3.Dispose();
			}
			if (assembly.get_HasSecurityDeclarations())
			{
				V_5 = assembly.get_SecurityDeclarations().GetEnumerator();
				try
				{
					while (V_5.MoveNext())
					{
						V_6 = V_5.get_Current();
						if (!V_6.get_HasSecurityAttributes())
						{
							continue;
						}
						V_7 = V_6.get_SecurityAttributes().GetEnumerator();
						try
						{
							while (V_7.MoveNext())
							{
								V_8 = V_7.get_Current();
								V_1.Add(V_8);
							}
						}
						finally
						{
							V_7.Dispose();
						}
					}
				}
				finally
				{
					V_5.Dispose();
				}
			}
			if (assembly.get_MainModule().get_HasExportedTypes())
			{
				V_9 = assembly.get_MainModule().get_ExportedTypes().GetEnumerator();
				try
				{
					while (V_9.MoveNext())
					{
						V_10 = V_9.get_Current();
						if (V_10.get_Scope() as ModuleReference != null)
						{
							continue;
						}
						V_1.Add(AttributesUtilities.GetExportedTypeAttribute(V_10, assembly.get_MainModule()));
					}
				}
				finally
				{
					V_9.Dispose();
				}
			}
			V_11 = V_1.GetEnumerator();
			try
			{
				while (V_11.MoveNext())
				{
					V_12 = V_11.get_Current();
					if (V_12 as CustomAttribute == null)
					{
						if (V_12 as SecurityAttribute == null)
						{
							continue;
						}
						V_13 = AttributesUtilities.GetSecurityAttributeUsedTypes(V_12 as SecurityAttribute).GetEnumerator();
						try
						{
							while (V_13.MoveNext())
							{
								V_15 = V_13.get_Current();
								V_0.Add(V_15);
							}
						}
						finally
						{
							if (V_13 != null)
							{
								V_13.Dispose();
							}
						}
					}
					else
					{
						V_13 = AttributesUtilities.GetCustomAttributeUsedTypes(V_12 as CustomAttribute).GetEnumerator();
						try
						{
							while (V_13.MoveNext())
							{
								V_14 = V_13.get_Current();
								V_0.Add(V_14);
							}
						}
						finally
						{
							if (V_13 != null)
							{
								V_13.Dispose();
							}
						}
					}
				}
			}
			finally
			{
				((IDisposable)V_11).Dispose();
			}
			return V_0;
		}
Exemple #25
0
 private void EliminateViaDoWhile(IfStatement gotoStatement, Statement labeledStatement)
 {
     V_0 = new List <BreakStatement>();
     V_1 = new List <ContinueStatement>();
     V_2 = this.GetOuterBlock(labeledStatement);
     V_3 = V_2.get_Statements().IndexOf(labeledStatement);
     V_4 = V_2.get_Statements().IndexOf(gotoStatement);
     V_5 = this.CollectStatements(V_3, V_4, V_2);
     if (this.ShouldCheck(gotoStatement))
     {
         stackVariable127 = new ContinueAndBreakFinder();
         stackVariable127.Visit(V_5);
         V_0 = stackVariable127.get_Breaks();
         V_1 = stackVariable127.get_Continues();
     }
     V_7 = V_0.GetEnumerator();
     try
     {
         while (V_7.MoveNext())
         {
             V_8                    = V_7.get_Current();
             stackVariable29        = this.GetOuterBlock(V_8);
             V_9                    = stackVariable29.get_Statements().IndexOf(V_8);
             this.usedBreakVariable = true;
             V_10                   = new ExpressionStatement(new BinaryExpression(26, new VariableReferenceExpression(this.breakVariable, null), this.GetLiteralExpression(true), this.typeSystem, null, false));
             stackVariable29.AddStatementAt(V_9, V_10);
         }
     }
     finally
     {
         if (V_7 != null)
         {
             V_7.Dispose();
         }
     }
     V_11 = V_1.GetEnumerator();
     try
     {
         while (V_11.MoveNext())
         {
             V_12                      = V_11.get_Current();
             stackVariable60           = this.GetOuterBlock(V_12);
             V_13                      = stackVariable60.get_Statements().IndexOf(V_12);
             this.usedContinueVariable = true;
             V_14                      = new ExpressionStatement(new BinaryExpression(26, new VariableReferenceExpression(this.continueVariable, null), this.GetLiteralExpression(true), this.typeSystem, null, false));
             stackVariable60.get_Statements().RemoveAt(V_13);
             stackVariable60.AddStatementAt(V_13, new BreakStatement(null));
             stackVariable60.AddStatementAt(V_13, V_14);
         }
     }
     finally
     {
         if (V_11 != null)
         {
             V_11.Dispose();
         }
     }
     V_6 = new DoWhileStatement(gotoStatement.get_Condition(), V_5);
     V_4 = V_2.get_Statements().IndexOf(gotoStatement);
     V_2.AddStatementAt(V_4, V_6);
     dummyVar0 = V_2.get_Statements().Remove(gotoStatement);
     if (V_0.get_Count() > 0)
     {
         this.AddBreakContinueConditional(V_4 + 1, V_2, new BreakStatement(null), this.breakVariable);
     }
     if (V_1.get_Count() > 0)
     {
         this.AddBreakContinueConditional(V_4 + 1, V_2, new ContinueStatement(null), this.continueVariable);
     }
     return;
 }
Exemple #26
0
 internal static CFGBlockLogicalConstruct FindGuardedBlockCFGFollowNode(ExceptionHandlingLogicalConstruct construct, HashSet <CFGBlockLogicalConstruct> outOfconsideration)
 {
     V_0 = new Dictionary <CFGBlockLogicalConstruct, uint>();
     GuardedBlocksFollowNodesFinder.AddSuccessorsToCount(construct.get_Try(), V_0);
     V_1 = 1;
     if (construct as TryCatchFilterLogicalConstruct == null)
     {
         if (construct as TryFaultLogicalConstruct == null)
         {
             if (construct as TryFinallyLogicalConstruct != null)
             {
                 GuardedBlocksFollowNodesFinder.AddSuccessorsToCount((construct as TryFinallyLogicalConstruct).get_Finally(), V_0);
                 V_1 = V_1 + 1;
             }
         }
         else
         {
             GuardedBlocksFollowNodesFinder.AddSuccessorsToCount((construct as TryFaultLogicalConstruct).get_Fault(), V_0);
             V_1 = V_1 + 1;
         }
     }
     else
     {
         V_5 = (construct as TryCatchFilterLogicalConstruct).get_Handlers();
         V_6 = 0;
         while (V_6 < (int)V_5.Length)
         {
             GuardedBlocksFollowNodesFinder.AddSuccessorsToCount(V_5[V_6], V_0);
             V_1 = V_1 + 1;
             V_6 = V_6 + 1;
         }
     }
     V_7 = outOfconsideration.GetEnumerator();
     try
     {
         while (V_7.MoveNext())
         {
             V_8 = V_7.get_Current();
             if (!V_0.ContainsKey(V_8))
             {
                 continue;
             }
             dummyVar0 = V_0.Remove(V_8);
         }
     }
     finally
     {
         ((IDisposable)V_7).Dispose();
     }
     if (V_0.get_Count() == 0)
     {
         return(null);
     }
     V_2       = new HashSet <CFGBlockLogicalConstruct>();
     V_3       = V_0.get_Keys().FirstOrDefault <CFGBlockLogicalConstruct>();
     dummyVar1 = V_2.Add(V_3);
     V_4       = V_0.get_Item(V_3);
     V_9       = V_0.get_Keys().GetEnumerator();
     try
     {
         while (V_9.MoveNext())
         {
             V_10 = V_9.get_Current();
             if (V_0.get_Item(V_10) <= V_4)
             {
                 if (V_0.get_Item(V_10) != V_4)
                 {
                     continue;
                 }
                 dummyVar3 = V_2.Add(V_10);
             }
             else
             {
                 V_4 = V_0.get_Item(V_10);
                 V_2.Clear();
                 dummyVar2 = V_2.Add(V_10);
             }
         }
     }
     finally
     {
         ((IDisposable)V_9).Dispose();
     }
     if (V_2.get_Count() == 1)
     {
         return(V_2.FirstOrDefault <CFGBlockLogicalConstruct>());
     }
     V_11 = new HashSet <CFGBlockLogicalConstruct>();
     V_12 = 0;
     V_7  = V_2.GetEnumerator();
     try
     {
         while (V_7.MoveNext())
         {
             V_14 = V_7.get_Current();
             V_15 = 0;
             V_16 = construct.get_CFGBlocks();
             V_17 = V_14.get_CFGPredecessors().GetEnumerator();
             try
             {
                 while (V_17.MoveNext())
                 {
                     V_18 = V_17.get_Current();
                     if (!V_16.Contains(V_18))
                     {
                         continue;
                     }
                     V_15 = V_15 + 1;
                 }
             }
             finally
             {
                 ((IDisposable)V_17).Dispose();
             }
             if (V_15 < V_12)
             {
                 continue;
             }
             if (V_15 > V_12)
             {
                 V_12 = V_15;
                 V_11.Clear();
             }
             dummyVar4 = V_11.Add(V_14);
         }
     }
     finally
     {
         ((IDisposable)V_7).Dispose();
     }
     V_13 = V_11.FirstOrDefault <CFGBlockLogicalConstruct>();
     if (V_13.get_Index() < construct.get_Entry().get_Index())
     {
         V_19 = null;
         V_7  = V_11.GetEnumerator();
         try
         {
             while (V_7.MoveNext())
             {
                 V_20 = V_7.get_Current();
                 if (V_20.get_Index() <= construct.get_Entry().get_Index() || V_19 != null && V_19.get_Index() < V_20.get_Index())
                 {
                     continue;
                 }
                 V_19 = V_20;
             }
         }
         finally
         {
             ((IDisposable)V_7).Dispose();
         }
         if (V_19 != null)
         {
             V_13 = V_19;
         }
     }
     return(V_13);
 }
Exemple #27
0
 private bool TryMatchInternal(StatementCollection statements, int startIndex, out Statement result)
 {
     result = null;
     if (startIndex + 1 >= statements.get_Count())
     {
         return(false);
     }
     if (statements.get_Item(startIndex).get_CodeNodeType() != 5 || statements.get_Item(startIndex + 1).get_CodeNodeType() != 3)
     {
         return(false);
     }
     V_0 = statements.get_Item(startIndex) as ExpressionStatement;
     if (V_0.get_Expression().get_CodeNodeType() != 24)
     {
         return(false);
     }
     V_1 = V_0.get_Expression() as BinaryExpression;
     if (V_1.get_Left().get_CodeNodeType() != 26 || V_1.get_Right().get_CodeNodeType() != 48)
     {
         return(false);
     }
     V_2 = V_1.get_Left() as VariableReferenceExpression;
     V_3 = V_1.get_Right() as EventReferenceExpression;
     V_4 = statements.get_Item(startIndex + 1) as IfStatement;
     if (V_4.get_Then() == null || V_4.get_Else() != null || V_4.get_Condition().get_CodeNodeType() != 24)
     {
         return(false);
     }
     V_5 = V_4.get_Condition() as BinaryExpression;
     if (V_5.get_Left().get_CodeNodeType() != 26 || V_5.get_Right().get_CodeNodeType() != 22 || V_5.get_Operator() != 10)
     {
         return(false);
     }
     V_6 = V_5.get_Left() as VariableReferenceExpression;
     if ((object)V_2.get_Variable() != (object)V_6.get_Variable())
     {
         return(false);
     }
     if ((V_5.get_Right() as LiteralExpression).get_Value() != null)
     {
         return(false);
     }
     V_7 = V_4.get_Then().get_Statements();
     if (V_7.get_Count() != 1 || V_7.get_Item(0).get_CodeNodeType() != 5)
     {
         return(false);
     }
     V_8 = V_7.get_Item(0) as ExpressionStatement;
     if (V_8.get_Expression().get_CodeNodeType() != 51)
     {
         return(false);
     }
     V_9 = V_8.get_Expression() as DelegateInvokeExpression;
     if (V_9.get_Target() == null || V_9.get_Target().get_CodeNodeType() != 26)
     {
         return(false);
     }
     V_10 = V_9.get_Target() as VariableReferenceExpression;
     if ((object)V_10.get_Variable() != (object)V_2.get_Variable())
     {
         return(false);
     }
     V_11 = new List <Instruction>();
     V_11.AddRange(V_0.get_UnderlyingSameMethodInstructions());
     V_11.AddRange(V_5.get_UnderlyingSameMethodInstructions());
     V_11.AddRange(V_9.get_MappedInstructions());
     V_11.AddRange(V_10.get_UnderlyingSameMethodInstructions());
     result = new ExpressionStatement(new RaiseEventExpression(V_3.get_Event(), V_9.get_InvokeMethodReference(), V_9.get_Arguments(), V_11));
     return(true);
 }
        public static Expression GetEnumExpression(TypeDefinition enumDefinition, LiteralExpression targetedValue, TypeSystem typeSystem)
        {
            V_0 = EnumHelper.GetEnumBitSize(enumDefinition);
            V_1 = (long)0;
            V_4 = targetedValue.get_Value().GetType().get_FullName();
            if (V_4 != null)
            {
                if (String.op_Equality(V_4, "System.Int32"))
                {
                    if (V_0 != 32)
                    {
                        V_1 = (long)((Int32)targetedValue.get_Value());
                    }
                    else
                    {
                        V_1 = (ulong)((Int32)targetedValue.get_Value());
                    }
                }
                else
                {
                    if (String.op_Equality(V_4, "System.Int64"))
                    {
                        V_1 = (Int64)targetedValue.get_Value();
                    }
                    else
                    {
                        if (String.op_Equality(V_4, "System.UInt32"))
                        {
                            V_1 = (ulong)((UInt32)targetedValue.get_Value());
                        }
                        else
                        {
                            if (String.op_Equality(V_4, "System.UInt64"))
                            {
                                V_1 = (UInt64)targetedValue.get_Value();
                            }
                            else
                            {
                                if (String.op_Equality(V_4, "System.Byte"))
                                {
                                    V_1 = (ulong)((Byte)targetedValue.get_Value());
                                }
                                else
                                {
                                    if (String.op_Equality(V_4, "System.SByte"))
                                    {
                                        V_1 = (long)((SByte)targetedValue.get_Value());
                                    }
                                    else
                                    {
                                        if (String.op_Equality(V_4, "System.Int16"))
                                        {
                                            V_1 = (long)((Int16)targetedValue.get_Value());
                                        }
                                        else
                                        {
                                            if (String.op_Equality(V_4, "System.UInt16"))
                                            {
                                                V_1 = (ulong)((UInt16)targetedValue.get_Value());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            stackVariable10 = enumDefinition.get_Fields();
            V_2             = new List <FieldDefinition>();
            V_6             = stackVariable10.GetEnumerator();
            try
            {
                while (V_6.MoveNext())
                {
                    V_7 = V_6.get_Current();
                    if (V_7.get_Constant() == null || V_7.get_Constant().get_Value() == null)
                    {
                        continue;
                    }
                    V_8 = (long)0;
                    V_4 = V_7.get_Constant().get_Value().GetType().get_FullName();
                    if (V_4 != null)
                    {
                        if (String.op_Equality(V_4, "System.Int32"))
                        {
                            V_8 = (ulong)((Int32)V_7.get_Constant().get_Value());
                        }
                        else
                        {
                            if (String.op_Equality(V_4, "System.UInt32"))
                            {
                                V_8 = (ulong)((UInt32)V_7.get_Constant().get_Value());
                            }
                            else
                            {
                                if (String.op_Equality(V_4, "System.Byte"))
                                {
                                    V_8 = (ulong)((Byte)V_7.get_Constant().get_Value());
                                }
                                else
                                {
                                    if (String.op_Equality(V_4, "System.SByte"))
                                    {
                                        V_8 = (ulong)((byte)((SByte)V_7.get_Constant().get_Value()));
                                    }
                                    else
                                    {
                                        if (String.op_Equality(V_4, "System.Int16"))
                                        {
                                            V_8 = (ulong)((ushort)((Int16)V_7.get_Constant().get_Value()));
                                        }
                                        else
                                        {
                                            if (String.op_Equality(V_4, "System.UInt16"))
                                            {
                                                V_8 = (ulong)((UInt16)V_7.get_Constant().get_Value());
                                            }
                                            else
                                            {
                                                if (String.op_Equality(V_4, "System.Int64"))
                                                {
                                                    V_8 = (Int64)V_7.get_Constant().get_Value();
                                                }
                                                else
                                                {
                                                    if (String.op_Equality(V_4, "System.UInt64"))
                                                    {
                                                        V_8 = (UInt64)V_7.get_Constant().get_Value();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (V_8 != V_1)
                    {
                        if (V_8 == 0 || V_8 | V_1 != V_1)
                        {
                            continue;
                        }
                        V_2.Add(V_7);
                    }
                    else
                    {
                        V_9 = new EnumExpression(V_7, targetedValue.get_UnderlyingSameMethodInstructions());
                        goto Label1;
                    }
                }
                goto Label0;
            }
            finally
            {
                V_6.Dispose();
            }
Label1:
            return(V_9);

Label0:
            if (V_2.get_Count() < 2)
            {
                return(targetedValue);
            }
            V_3 = new BinaryExpression(21, new EnumExpression(V_2.get_Item(0), null), new EnumExpression(V_2.get_Item(1), null), typeSystem, null, false);
            V_3.set_ExpressionType(enumDefinition);
            V_10 = 2;
            while (V_10 < V_2.get_Count())
            {
                V_3 = new BinaryExpression(21, V_3, new EnumExpression(V_2.get_Item(V_10), null), typeSystem, null, false);
                V_3.set_ExpressionType(enumDefinition);
                V_10 = V_10 + 1;
            }
            return(V_3.CloneAndAttachInstructions(targetedValue.get_UnderlyingSameMethodInstructions()));
        }
 private void ManageIsEventOperations(HashSet <Statement> statementsToRemove)
 {
     V_0 = this.isEventIfStatements.GetEnumerator();
     try
     {
         while (V_0.MoveNext())
         {
             V_1 = V_0.get_Current();
             V_2 = V_1.get_Key();
             V_3 = V_1.get_Value();
             if (V_2.get_Condition().get_CodeNodeType() != 23 || (V_2.get_Condition() as UnaryExpression).get_Operator() != 11 || (V_2.get_Condition() as UnaryExpression).get_Operand() != V_3)
             {
                 if (V_2.get_Condition().get_CodeNodeType() != 23 || (V_2.get_Condition() as UnaryExpression).get_Operator() != UnaryOperator.Negate || (V_2.get_Condition() as UnaryExpression).get_Operand() != V_3)
                 {
                     throw new Exception("Invalid invocation of IsEvent operation.");
                 }
                 this.ReplaceIfWith(V_2, V_2.get_Else());
             }
             else
             {
                 V_4 = V_2.get_Then().get_Statements().get_Item(V_2.get_Then().get_Statements().get_Count() - 1);
                 if (V_4.get_CodeNodeType() == 5 && ((ExpressionStatement)V_4).get_Expression().get_CodeNodeType() == 57)
                 {
                     V_5 = (BlockStatement)V_2.get_Parent();
                     V_6 = V_5.get_Statements().IndexOf(V_2) + 1;
                     while (V_6 < V_5.get_Statements().get_Count())
                     {
                         dummyVar0 = statementsToRemove.Add(V_5.get_Statements().get_Item(V_6));
                         V_6       = V_6 + 1;
                     }
                 }
                 this.ReplaceIfWith(V_2, V_2.get_Then());
             }
             V_7 = V_2.get_Then().get_Statements().GetEnumerator();
             try
             {
                 while (V_7.MoveNext())
                 {
                     V_8       = V_7.get_Current();
                     dummyVar1 = statementsToRemove.Remove(V_8);
                 }
             }
             finally
             {
                 if (V_7 != null)
                 {
                     V_7.Dispose();
                 }
             }
             if (V_2.get_Else() == null)
             {
                 continue;
             }
             V_7 = V_2.get_Else().get_Statements().GetEnumerator();
             try
             {
                 while (V_7.MoveNext())
                 {
                     V_9       = V_7.get_Current();
                     dummyVar2 = statementsToRemove.Remove(V_9);
                 }
             }
             finally
             {
                 if (V_7 != null)
                 {
                     V_7.Dispose();
                 }
             }
         }
     }
     finally
     {
         ((IDisposable)V_0).Dispose();
     }
     return;
 }
 private void WriteCustomAttributeFields(CustomAttribute attribute)
 {
     V_0 = attribute.get_Fields().GetEnumerator();
     try
     {
         while (V_0.MoveNext())
         {
             V_1       = new IntermediateLanguageAttributeWriter.u003cu003ec__DisplayClass19_0();
             V_1.field = V_0.get_Current();
             this.WriteKeyword("field");
             this.WriteSpace();
             V_7 = V_1.field.get_Argument();
             V_2 = V_7.get_Type().Resolve();
             if (V_1.field.get_Argument().get_Type().get_IsPrimitive() || String.op_Equality(V_1.field.get_Argument().get_Type().get_FullName(), "System.String"))
             {
                 V_3 = 3;
             }
             else
             {
                 V_3 = 2;
             }
             V_7 = V_1.field.get_Argument();
             V_4 = V_7.get_Type();
             if (V_2 == null)
             {
                 V_7             = V_1.field.get_Argument();
                 stackVariable39 = V_7.get_Type().GetFriendlyFullName(this.get_Language());
                 V_7             = V_1.field.get_Argument();
                 this.WriteNotResolvedReference(stackVariable39, V_7.get_Type(), "Enum keyword might be missing. Please, locate the assembly where the type is defined.");
             }
             else
             {
                 if (!V_2.get_IsEnum())
                 {
                     V_7 = V_1.field.get_Argument();
                     this.WriteType(V_7.get_Type(), V_3);
                 }
                 else
                 {
                     V_4 = this.GetEnumerationUnderlayingType(V_2);
                     this.WriteKeyword("enum");
                     this.WriteSpace();
                     V_7 = V_1.field.get_Argument();
                     this.WriteType(V_7.get_Type(), V_3);
                     V_3 = 3;
                 }
             }
             this.WriteSpace();
             V_5 = null;
             V_6 = attribute.get_AttributeType().Resolve();
             if (V_6 != null)
             {
                 V_5 = V_6.get_Fields().First <FieldDefinition>(new Func <FieldDefinition, bool>(V_1.u003cWriteCustomAttributeFieldsu003eb__0));
             }
             this.WriteReference(V_1.field.get_Name(), V_5);
             this.WriteSpace();
             this.Write("=");
             this.WriteSpace();
             this.WriteType(V_4, V_3);
             this.Write("(");
             V_7 = V_1.field.get_Argument();
             this.Write(V_7.get_Value().ToString());
             this.Write(")");
             this.WriteLine();
         }
     }
     finally
     {
         V_0.Dispose();
     }
     return;
 }