protected override bool TryMatchInternal(StatementCollection statements, int startIndex, out Statement result, out int replacedStatementsCount) { result = null; replacedStatementsCount = 0; if (!this.TryGetObjectCreation(statements, startIndex, out V_0, out V_1)) { return(false); } V_2 = new ExpressionCollection(); V_3 = new HashSet <string>(); if (V_0.get_Initializer() != null) { if (V_0.get_Initializer().get_InitializerType() != 1) { return(false); } V_4 = V_0.get_Initializer().get_Expressions().GetEnumerator(); try { while (V_4.MoveNext()) { V_5 = V_4.get_Current(); V_6 = this.GetName((V_5 as BinaryExpression).get_Left()); dummyVar0 = V_3.Add(V_6); } } finally { if (V_4 != null) { V_4.Dispose(); } } } V_7 = startIndex + 1; while (V_7 < statements.get_Count() && this.TryGetNextExpression(statements.get_Item(V_7), out V_8)) { V_9 = V_8 as BinaryExpression; if (!this.IsObjectPropertyOrFieldAssignment(V_9, V_1)) { break; } V_10 = null; if (V_9.get_Left().get_CodeNodeType() != 42) { if (V_9.get_Left().get_CodeNodeType() == 30) { V_13 = (V_9.get_Left() as FieldReferenceExpression).get_Field().Resolve(); if (!this.Visit(V_13.get_Name(), V_3)) { break; } V_10 = new FieldInitializerExpression(V_13, V_13.get_FieldType(), V_9.get_Left().get_UnderlyingSameMethodInstructions()); } } else { V_12 = (V_9.get_Left() as PropertyReferenceExpression).get_Property(); if (!this.Visit(V_12.get_Name(), V_3)) { break; } V_10 = new PropertyInitializerExpression(V_12, V_12.get_PropertyType(), V_9.get_Left().get_UnderlyingSameMethodInstructions()); } V_11 = new BinaryExpression(26, V_10, V_9.get_Right().Clone(), this.typeSystem, null, false); V_2.Add(V_11); V_7 = V_7 + 1; } if (V_2.get_Count() == 0) { return(false); } if (V_0.get_Initializer() != null) { V_4 = V_2.GetEnumerator(); try { while (V_4.MoveNext()) { V_15 = V_4.get_Current(); V_0.get_Initializer().get_Expressions().Add(V_15); } } finally { if (V_4 != null) { V_4.Dispose(); } } } else { V_14 = new InitializerExpression(V_2, 1); V_14.set_IsMultiLine(true); V_0.set_Initializer(V_14); } result = statements.get_Item(startIndex); replacedStatementsCount = V_2.get_Count() + 1; return(true); }
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; }
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); }
public override void VisitBinaryExpression(BinaryExpression node) { V_0 = this.GetExpressionTypeName(node.get_Left()); V_1 = this.GetExpressionTypeName(node.get_Right()); this.VisitBinaryExpression(node); if (String.op_Inequality(this.GetExpressionTypeName(node.get_Left()), V_0)) { stackVariable16 = true; } else { stackVariable16 = String.op_Inequality(this.GetExpressionTypeName(node.get_Right()), V_1); } V_2 = stackVariable16; if (node.get_IsAssignmentExpression() || node.get_IsSelfAssign() && !node.get_IsEventHandlerAddOrRemove()) { V_3 = node.get_Left(); V_4 = node.get_Right(); if (V_4.get_HasType() && V_3.get_HasType()) { V_5 = V_3.get_ExpressionType(); V_6 = V_4.get_ExpressionType().Resolve(); if (this.ShouldAddCast(V_6, V_5)) { node.set_Right(new ExplicitCastExpression(V_4, V_5, null)); V_2 = true; } V_7 = V_5.Resolve(); if (V_7 != null && V_6 != null && V_7.get_IsEnum() && V_6.get_IsValueType() && String.op_Inequality(V_7.get_FullName(), V_6.get_FullName())) { node.set_Right(new ExplicitCastExpression(V_4, V_5, null)); V_2 = true; } } } else { if (!this.IsArithmeticOperator(node.get_Operator())) { if (this.IsBitwiseOperator(node.get_Operator()) || node.get_IsComparisonExpression()) { V_10 = node.get_Left(); V_11 = node.get_Right(); if (V_11.get_HasType() && V_10.get_HasType()) { V_12 = V_10.get_ExpressionType(); V_13 = V_11.get_ExpressionType().Resolve(); if (this.ShouldAddCast(V_13, V_12)) { node.set_Right(new ExplicitCastExpression(V_11, V_12, null)); V_2 = true; } V_14 = V_11.get_ExpressionType(); V_15 = V_10.get_ExpressionType().Resolve(); if (this.ShouldAddCast(V_15, V_14)) { node.set_Left(new ExplicitCastExpression(V_10, V_14, null)); V_2 = true; } if (V_15 != null && V_15.get_IsEnum() && V_13 != null && V_13.get_IsEnum() && String.op_Inequality(V_15.get_FullName(), V_13.get_FullName())) { node.set_Left(new ExplicitCastExpression(V_10, this.GetEnumUnderlyingType(V_15), null)); node.set_Right(new ExplicitCastExpression(V_11, this.GetEnumUnderlyingType(V_15), null)); V_2 = true; } } } else { if (this.IsShiftOperator(node.get_Operator())) { if (node.get_Left().get_HasType()) { V_16 = node.get_Left().get_ExpressionType().Resolve(); if (V_16 != null && V_16.get_IsEnum()) { node.set_Left(new ExplicitCastExpression(node.get_Left(), this.GetEnumUnderlyingType(V_16), null)); V_2 = true; } } if (node.get_Right().get_HasType()) { V_17 = node.get_Right().get_ExpressionType().Resolve(); if (V_17 != null && V_17.get_IsEnum()) { node.set_Right(new ExplicitCastExpression(node.get_Right(), this.GetEnumUnderlyingType(V_17), null)); V_2 = true; } } } } } else { if (node.get_Left().get_HasType()) { V_8 = node.get_Left().get_ExpressionType().Resolve(); if (V_8 != null && V_8.get_IsEnum()) { node.set_Left(new ExplicitCastExpression(node.get_Left(), this.GetEnumUnderlyingType(V_8), null)); V_2 = true; } } if (node.get_Right().get_HasType()) { V_9 = node.get_Right().get_ExpressionType().Resolve(); if (V_9 != null && V_9.get_IsEnum()) { node.set_Right(new ExplicitCastExpression(node.get_Right(), this.GetEnumUnderlyingType(V_9), null)); V_2 = true; } } } } if (V_2) { node.UpdateType(); } return; }
private DecompiledType GetDecompiledType(IMemberDefinition member, ILanguage language) { V_0 = Utilities.GetDeclaringTypeOrSelf(member); V_1 = new DecompiledType(V_0); V_2 = new Queue <IMemberDefinition>(); V_2.Enqueue(member); Label0: while (V_2.get_Count() > 0) { V_3 = V_2.Dequeue(); if (V_3 as TypeDefinition != null && (object)V_3 == (object)member) { V_4 = Utilities.GetTypeMembers(V_3 as TypeDefinition, language, true, null, null, null, V_1.get_TypeContext().GetFieldToPropertyMap(language).get_Keys()).GetEnumerator(); try { while (V_4.MoveNext()) { V_5 = V_4.get_Current(); V_2.Enqueue(V_5); } } finally { ((IDisposable)V_4).Dispose(); } } if (V_3 as MethodDefinition != null) { this.DecompileMember(V_3 as MethodDefinition, language, V_1); } if (V_3 as EventDefinition != null) { V_6 = V_3 as EventDefinition; if ((new AutoImplementedEventMatcher(V_6, language)).IsAutoImplemented()) { dummyVar0 = V_1.get_TypeContext().get_AutoImplementedEvents().Add(V_6); } if (V_6.get_AddMethod() != null) { this.DecompileMember(V_6.get_AddMethod(), language, V_1); } if (V_6.get_RemoveMethod() != null) { this.DecompileMember(V_6.get_RemoveMethod(), language, V_1); } if (V_6.get_InvokeMethod() != null) { this.DecompileMember(V_6.get_InvokeMethod(), language, V_1); } } if (V_3 as PropertyDefinition != null) { V_7 = V_3 as PropertyDefinition; stackVariable52 = new PropertyDecompiler(V_7, language, this.renameInvalidMembers, this.cacheService, V_1.get_TypeContext()); stackVariable52.add_ExceptionThrown(new EventHandler <Exception>(this.OnExceptionThrown)); stackVariable52.Decompile(out V_8, out V_9, out V_10); stackVariable52.remove_ExceptionThrown(new EventHandler <Exception>(this.OnExceptionThrown)); if (V_10) { dummyVar1 = V_1.get_TypeContext().get_AutoImplementedProperties().Add(V_7); } if (V_8 != null) { this.AddDecompiledMemberToDecompiledType(V_8, V_1); } if (V_9 != null) { this.AddDecompiledMemberToDecompiledType(V_9, V_1); } V_11 = stackVariable52.get_ExceptionsWhileDecompiling().GetEnumerator(); try { while (V_11.MoveNext()) { V_12 = V_11.get_Current(); this.get_ExceptionsWhileDecompiling().Add(V_12); } } finally { if (V_11 != null) { V_11.Dispose(); } } } if (V_3 as FieldDefinition == null) { continue; } V_13 = V_3 as FieldDefinition; V_14 = V_3.get_DeclaringType().get_Methods().GetEnumerator(); try { while (V_14.MoveNext()) { V_15 = V_14.get_Current(); if (!V_15.get_IsConstructor() || V_13.get_IsStatic() != V_15.get_IsStatic()) { continue; } this.DecompileConstructorChain(V_15, language, V_1); goto Label0; } } finally { V_14.Dispose(); } } V_1.get_TypeContext().set_ExplicitlyImplementedMembers(this.GetExplicitlyImplementedInterfaceMethods(V_0, language)); this.AddGeneratedFilterMethodsToDecompiledType(V_1, V_1.get_TypeContext(), language); return(V_1); }
public static int CompareToSecurityAttribute(this SecurityAttribute first, SecurityAttribute second, SecurityDeclaration firstDeclaration, SecurityDeclaration secondDeclaration) { if ((object)first == (object)second) { return(0); } V_0 = firstDeclaration.get_Action().ToString(); V_1 = secondDeclaration.get_Action().ToString(); if (String.op_Inequality(V_0, V_1)) { return(V_0.CompareTo(V_1)); } V_2 = Math.Max(first.get_Properties().get_Count(), second.get_Properties().get_Count()); V_5 = 0; while (V_5 < V_2) { if (V_5 >= first.get_Properties().get_Count()) { return(1); } if (V_5 >= second.get_Properties().get_Count()) { return(-1); } V_6 = first.get_Properties().get_Item(V_5); V_7 = second.get_Properties().get_Item(V_5); if (!String.op_Equality(V_6.get_Name(), V_7.get_Name())) { return(V_6.get_Name().CompareTo(V_7.get_Name())); } V_10 = V_6.get_Argument(); V_8 = V_10.get_Value().ToString(); V_10 = V_7.get_Argument(); V_9 = V_10.get_Value().ToString(); if (String.op_Inequality(V_8, V_9)) { return(V_8.CompareTo(V_9)); } V_5 = V_5 + 1; } V_3 = Math.Max(first.get_Fields().get_Count(), second.get_Fields().get_Count()); V_11 = 0; while (V_11 < V_3) { if (V_11 >= first.get_Fields().get_Count()) { return(1); } if (V_11 >= second.get_Fields().get_Count()) { return(-1); } V_12 = first.get_Fields().get_Item(V_11); V_13 = second.get_Fields().get_Item(V_11); if (!String.op_Equality(V_12.get_Name(), V_13.get_Name())) { return(V_12.get_Name().CompareTo(V_13.get_Name())); } V_10 = V_12.get_Argument(); V_14 = V_10.get_Value().ToString(); V_10 = V_13.get_Argument(); V_15 = V_10.get_Value().ToString(); if (String.op_Inequality(V_14, V_15)) { return(V_14.CompareTo(V_15)); } V_11 = V_11 + 1; } return(0); }
private void RedirectConstraints() { V_0 = new List <KeyValuePair <ClassHierarchyNode, ClassHierarchyNode> >(); V_1 = this.get_ContainedNodes().GetEnumerator(); try { while (V_1.MoveNext()) { V_2 = V_1.get_Current(); V_3 = V_2.get_CanAssignTo().GetEnumerator(); try { while (V_3.MoveNext()) { V_4 = V_3.get_Current(); if (this.get_ContainedNodes().Contains(V_4)) { continue; } if (!V_4.get_IsHardNode() || !V_4.get_NodeType().get_IsPrimitive() || !V_2.get_IsHardNode() || this.IsAssignable(V_2.get_NodeType(), V_4.get_NodeType())) { V_0.Add(new KeyValuePair <ClassHierarchyNode, ClassHierarchyNode>(V_2, V_4)); } else { dummyVar0 = V_4.get_SubTypes().Remove(V_2); } } } finally { if (V_3 != null) { V_3.Dispose(); } } } } finally { if (V_1 != null) { V_1.Dispose(); } } V_5 = V_0.GetEnumerator(); try { while (V_5.MoveNext()) { V_6 = V_5.get_Current(); V_7 = V_6.get_Key(); V_8 = V_6.get_Value(); this.get_CanAssignTo().Add(V_8); dummyVar1 = V_7.get_CanAssignTo().Remove(V_8); dummyVar2 = V_8.get_SubTypes().Remove(V_7); if (V_8.get_SubTypes().Contains(this)) { continue; } V_8.get_SubTypes().Add(this); } } finally { ((IDisposable)V_5).Dispose(); } V_0 = new List <KeyValuePair <ClassHierarchyNode, ClassHierarchyNode> >(); V_1 = this.get_ContainedNodes().GetEnumerator(); try { while (V_1.MoveNext()) { V_9 = V_1.get_Current(); V_3 = V_9.get_SubTypes().GetEnumerator(); try { while (V_3.MoveNext()) { V_10 = V_3.get_Current(); if (this.get_ContainedNodes().Contains(V_10)) { continue; } if (!V_10.get_IsHardNode() || !V_10.get_NodeType().get_IsPrimitive() || !V_9.get_IsHardNode() || this.IsAssignable(V_10.get_NodeType(), V_9.get_NodeType())) { V_0.Add(new KeyValuePair <ClassHierarchyNode, ClassHierarchyNode>(V_9, V_10)); } else { dummyVar3 = V_10.get_CanAssignTo().Remove(V_9); } } } finally { if (V_3 != null) { V_3.Dispose(); } } } } finally { if (V_1 != null) { V_1.Dispose(); } } V_5 = V_0.GetEnumerator(); try { while (V_5.MoveNext()) { V_11 = V_5.get_Current(); V_12 = V_11.get_Key(); V_13 = V_11.get_Value(); this.get_SubTypes().Add(V_13); dummyVar4 = V_12.get_SubTypes().Remove(V_13); dummyVar5 = V_13.get_CanAssignTo().Remove(V_12); if (V_13.get_CanAssignTo().Contains(this)) { continue; } V_13.get_CanAssignTo().Add(this); } } finally { ((IDisposable)V_5).Dispose(); } return; }
private void InlineAssignmentInSameBlock() { V_0 = this.methodContext.get_Expressions().get_BlockExpressions().GetEnumerator(); try { while (V_0.MoveNext()) { V_1 = V_0.get_Current(); V_2 = V_1.get_Value(); V_3 = 0; while (V_3 < V_2.get_Count() - 1) { V_4 = V_2.get_Item(V_3) as BinaryExpression; if (V_4 != null && V_4.get_IsAssignmentExpression() && V_4.get_Left().get_CodeNodeType() == 26) { V_5 = (V_4.get_Left() as VariableReferenceExpression).get_Variable().Resolve(); if (this.variablesToInline.Contains(V_5)) { V_6 = V_4.get_Right(); V_7 = new SideEffectsFinder(); V_8 = V_7.HasSideEffectsRecursive(V_6); V_9 = new StackVariablesInliner.VariablesArgumentsAndFieldsFinder(); V_9.Visit(V_6); V_10 = new StackVariablesInliner.VariableReferenceFinder(V_9.get_Variables(), V_9.get_Parameters()); V_11 = V_3 + 1; while (V_11 < V_2.get_Count()) { if (!this.inliner.TryInlineVariable(V_5, V_6, V_2.get_Item(V_11), true, out V_12)) { if (V_8 && V_7.HasSideEffectsRecursive(V_2.get_Item(V_11)) || V_10.ContainsReference(V_2.get_Item(V_11))) { break; } if (V_2.get_Item(V_11).get_CodeNodeType() == 24 && (V_2.get_Item(V_11) as BinaryExpression).get_IsAssignmentExpression()) { V_13 = (V_2.get_Item(V_11) as BinaryExpression).get_Left(); if (V_13.get_CodeNodeType() == 25 && V_9.get_Parameters().Contains((V_13 as ArgumentReferenceExpression).get_Parameter().Resolve()) || V_13.get_CodeNodeType() == 26 && V_9.get_Variables().Contains((V_13 as VariableReferenceExpression).get_Variable().Resolve()) || V_13.get_CodeNodeType() == 30 && V_9.get_Fields().Contains((V_13 as FieldReferenceExpression).get_Field().Resolve())) { break; } } V_11 = V_11 + 1; } else { this.FixContextAfterInlining(V_5); dummyVar0 = this.variablesToInline.Remove(V_5); V_2.set_Item(V_11, (Expression)V_12); V_2.RemoveAt(V_3); stackVariable141 = V_3; if (V_3 > 0) { stackVariable144 = 2; } else { stackVariable144 = 1; } V_3 = stackVariable141 - stackVariable144; break; } } } } V_3 = V_3 + 1; } } } finally { ((IDisposable)V_0).Dispose(); } return; }