public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);		
			
			m_offset = DoHasBadDemand(begin.Info.Method) ? 0 : -1;
		}
Beispiel #2
0
		public void VisitMethod(BeginMethod begin)
		{						
			foreach (ParameterDefinition p in begin.Info.Method.Parameters)
			{
				DoAdd(p.Name);
			}
		}
		public void VisitBegin(BeginMethod method)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", method.Info.Instructions);				

			// Loop through each try block,
			int offset = -1;
			for (int i = 0; i < method.Info.Instructions.TryCatchCollection.Length && offset < 0; ++i)
			{
				TryCatch tc = method.Info.Instructions.TryCatchCollection[i];

				// and the associated catch blocks,
				for (int j = 0; j < tc.Catchers.Count && offset < 0; ++j)
				{
					CatchBlock cb = tc.Catchers[j];
					
					// if the first instruction in a catch is a store local then the code
					// is storing a reference to the exception object and we need to check
					// to see if it's being rethrown.				
					StoreLocal store = method.Info.Instructions[cb.Index] as StoreLocal;
					if (store != null)
						offset = DoCheckCatch(method.Info.Instructions, cb, store.Variable);
				}
			}			
			
			if (offset >= 0)
				Reporter.MethodFailed(method.Info.Method, CheckID, offset, string.Empty);
		}
		public void VisitMethodBegin(BeginMethod begin)	
		{
			m_inDispose = false;
			
			if (m_disposable)
			{
				Log.DebugLine(this, "{0:F}", begin.Info.Instructions);			

				MethodDefinition method = begin.Info.Method;
				if (method.Name == "Finalize")
				{	
					MethodDefinition previous = method.GetBasestMethod(Cache);
					if (previous != null && previous != method)
					{
						Log.DebugLine(this, "finalizer overrides {0}", previous);
						m_hasFinalizer = true;
					}
				}
				
				if (method.Matches("System.Void", "Dispose"))
				{
					Log.DebugLine(this, "has Dispose()");				
					m_hasDispose = true;
				}

				if (method.Matches("System.Void", "Dispose", "System.Boolean"))
				{
					Log.DebugLine(this, "has Dispose(bool)");				
					m_disposeMethod = method;
					m_inDispose = true;
				}
			}
		}	
		public void VisitBeginMethod(BeginMethod begin)
		{
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_info = begin.Info;
			m_offset = -1;
		}
Beispiel #6
0
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_numVirtuals = 0.0f;
			m_needsCheck = false;
			m_type = begin.Info.Type;
			m_virtuals.Clear();

			MethodDefinition method = begin.Info.Method;	
			if (method.IsVirtual && !method.IsFinal && method.IsNewSlot)
				if (!m_type.IsSealed && !m_type.IsNestedPrivate)
					if (method.Body != null)
						if (method.Body.Instructions.Count >= m_limit/4)
							m_needsCheck = true;
			
			if (m_needsCheck)
				foreach (MethodDefinition m in m_type.Methods)
					if (m.IsVirtual && !m.IsFinal)
						m_virtuals.Add(m.MetadataToken);

			if (method.Body != null)
				Log.DebugLine(this, "numInstructions: {0}", method.Body.Instructions.Count);				
		}
		public void VisitBegin(BeginMethod begin)
		{
			if (m_needsCheck)
			{
				m_failed = DoHasAssert(begin.Info.Method.SecurityDeclarations);
			}
		}
		public void VisitMethod(BeginMethod begin)
		{
			Log.DebugLine(this, "++++++++++++++++++++++++"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_type = begin.Info.Type;
		}		
Beispiel #9
0
		public void VisitBegin(BeginMethod method)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", method.Info.Instructions);				

			m_offset = -1;
		}
Beispiel #10
0
		public void VisitBegin(BeginMethod begin)	
		{
			m_offset = -1;
			m_info = begin.Info;
			m_badArg = null;
			m_needsCheck = OnNeedsCheck(m_info.Type) && OnNeedsCheck(m_info.Type, m_info.Method);
			m_table.Clear();
			
			if (m_needsCheck)
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "{0:F}", begin.Info.Instructions);	
				
				foreach (ParameterDefinition p in m_info.Method.Parameters)
				{
					if (!p.ParameterType.IsValueType)
					{
						Log.DebugLine(this, "{0} is a reference type", p.Name); 
						m_table.Add(p.Name, false);
					}
				}
			}
			
			if (m_table.Count == 0)
				m_needsCheck = false;
		}
Beispiel #11
0
        internal void Dispatch(MethodInfo info)
        {
            DoSetExcluding(info.Method.ToString());

            BeginMethod begin = new BeginMethod();

            begin.Info = info;
            DoVisit(begin);

            m_visited.Clear();
            if (info.Method.Body != null)
            {
                for (int i = 0; i < info.Graph.Roots.Length; ++i)
                {
                    if (m_visited.IndexOf(info.Graph.Roots[i]) < 0)
                    {
                        DoVisit(info.Instructions, info.Graph.Roots[i], info.Instructions.Length - 1, 0, int.MinValue);
                    }
                }
            }

            EndMethod end = new EndMethod();

            end.Info = info;
            DoVisit(end);

            info.Reset();                               // free up large objects we won't use again
        }
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "checking {0}", begin.Info.Method);

			TypeReference type = begin.Info.Method.GetDeclaredIn(Cache);
			if (type != null)
			{
				TypeDefinition td = Cache.FindType(type);
				if (td != null && td.IsInterface && !td.IsPublic && !td.IsNestedPublic)
				{
					Log.DebugLine(this, "   implements {0}", type);
					
					if (begin.Info.Type.ExternallyVisible(Cache))
					{
						Log.DebugLine(this, "   declaring type is externally visible");
						
						if (begin.Info.Method.IsVirtual && !begin.Info.Method.IsFinal)
						{
							Log.DebugLine(this, "   is virtual");
							
							if (DoHasPublicCtor(begin.Info.Type))
							{
								Log.DebugLine(this, "   has public ctor");
								
								string details = "Interface: " + type.FullName;
								Reporter.MethodFailed(begin.Info.Method, CheckID, 0, details);
							}
						}
					}
				}
			}
		}
		public void VisitBegin(BeginMethod begin)
		{
			m_needsCheck = false;
			m_missingBaseCall = true;
			
			m_type = begin.Info.Type;
			m_method = begin.Info.Method;
			
			if (m_method.IsConstructor)
			{		
				if (m_type.ExternallyVisible(Cache))
				{
					if (m_type.BaseImplements("System.Runtime.Serialization.ISerializable", Cache))
					{
						if (m_method.Parameters.Count == 2)
						{
							if (m_method.Parameters[0].ParameterType.FullName == "System.Runtime.Serialization.SerializationInfo" &&
								m_method.Parameters[1].ParameterType.FullName == "System.Runtime.Serialization.StreamingContext")
							{
								Log.DebugLine(this, "-----------------------------------"); 
								Log.DebugLine(this, "{0:F}", begin.Info.Instructions);			
								
								m_needsCheck = true;
							}
						}	
					}
				}
			}
		}	
Beispiel #14
0
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "---------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_info = begin.Info;
		}
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_offset = -1;
			m_info = begin.Info;

			m_args.Clear();
			bool badNames = false;
			for (int i = 0; i < begin.Info.Method.Parameters.Count; ++i)
			{
				ParameterReference p = begin.Info.Method.Parameters[i];
				if (!p.Name.StartsWith("A_"))
				{
					Log.DebugLine(this, "adding {0}", p.Name);				
					m_args.Add(p.Name);
				}
				else
				{
					Log.DebugLine(this, "skipping {0}", p.Name);	
					badNames = true;
				}
			}
			
			if (begin.Info.Method.Name.StartsWith("set_"))
			{
				m_args.Add(begin.Info.Method.Name.Substring(4));
				m_args.Add("value");
				Log.DebugLine(this, "added value and {0}", begin.Info.Method.Name.Substring(4));				
			}
			
			if (badNames)
				m_args.Clear();
		}
Beispiel #16
0
		public void VisitBegin(BeginMethod begin)
		{	
			if (!begin.Info.Method.IsVirtual)
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "{0}", begin.Info.Instructions);
				
				string details = string.Empty;
				List<MethodDefinition> methods = new List<MethodDefinition>();
				if (begin.Info.Type.BaseType != null)
					DoGetBaseMethods(begin.Info.Type.BaseType, begin.Info.Method, methods);
					
				foreach (MethodDefinition method in methods)
				{
					if (DoLeftHidesRight(begin.Info.Method, method))
						details = string.Format("{0} hides {1}. {2}", begin.Info.Method, method, details);
				}
				
				if (details.Length > 0)
				{
					Log.DebugLine(this, details); 
					Reporter.MethodFailed(begin.Info.Method, CheckID, 0, details);
				}
			}
		}
		public void VisitMethod(BeginMethod begin)
		{			
			if (m_table.TryGetValue(begin.Info.Method, out m_entry))
			{
				Log.DebugLine(this, "{0}", begin.Info.Method);
				Log.DebugLine(this, "{0:F}", begin.Info.Instructions);
			}
		}
Beispiel #18
0
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_offset = -1;
			m_numUnboxes = 0;
		}
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);		
			
			m_needsCheck = !begin.Info.Type.Name.Contains("Permission");
			m_offset = -1;
		}
Beispiel #20
0
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_newOffsets.Clear();
			m_setCount = 0;
		}
Beispiel #21
0
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_offset = -1;
			m_details = string.Empty;
		}
Beispiel #22
0
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_needsCheck = begin.Info.Method.Name.StartsWith("set_");
			m_found1 = false;
			m_found2 = false;
		}
Beispiel #23
0
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_offset = -1;
			m_foundCtor = false;
			m_foundLocale = false;
		}
Beispiel #24
0
		protected virtual bool OnNeedsCheck(BeginMethod begin)
		{		
			bool needs = false;
			
			if (begin.Info.Method.Body != null && begin.Info.Method.Body.ExceptionHandlers.Count == 0)
				if (begin.Info.Method.Reuses("System.Boolean", "Equals", "System.Object"))
					needs = true;
			
			return needs;
		}
Beispiel #25
0
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_offset = -1;
			m_bad = null;
			m_info = begin.Info;
			m_needsCheck = !begin.Info.Method.IsCompilerGenerated();	// TODO: why are we even called for these?
		}
Beispiel #26
0
		public void VisitMethodBegin(BeginMethod begin)
		{			
			if (m_disposable)
			{
				MethodDefinition method = begin.Info.Method;
				
				if (method.Matches("System.Void", "Dispose", "System.Boolean"))
					m_hasUnaryDispose = true;
			}		
		}
		public void VisitBegin(BeginMethod begin)
		{		
			m_needsCheck = true;
			m_offset = -1;
			
			if (m_needsCheck)
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				
			}
		}
Beispiel #28
0
		public void VisitBegin(BeginMethod begin)
		{
			m_needsCheck = m_gui && !begin.Info.Method.CustomAttributes.Has("ConditionalAttribute");
			m_offset = -1;

			if (m_needsCheck)
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				
			}
		}
Beispiel #29
0
		public void VisitBegin(BeginMethod method)
		{
			m_offset = -1;
			m_needsCheck = method.Info.Method.Reuses("System.Int32", "GetHashCode") && !method.Info.Method.IsCompilerGenerated();
			
			if (m_needsCheck)
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "{0:F}", method.Info.Instructions);				
			}
		}
Beispiel #30
0
		public void VisitBegin(BeginMethod begin)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", begin.Info.Instructions);				

			m_offset = -1;
			m_info = begin.Info;
			m_isMain = Cache.Assembly.EntryPoint == begin.Info.Method;
			m_stores.Clear();
			m_candidateLoads.Clear();
		}
Beispiel #31
0
		public void VisitBegin(BeginMethod method)
		{
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0:F}", method.Info.Instructions);				

			m_max = DoIsIFormattableToString(method.Info.Method) ? 1 : 0;
			Log.DebugLine(this, "m_max = {0}", m_max); 
			
			m_offset = -1;
			m_count = 0;
		}