Esempio n. 1
0
File: detect.cs Progetto: dfr0/moon
	static bool Annotate (MemberReference member, string note)
	{
		if (String.IsNullOrWhiteSpace (note))
			return true;

		note = note.Trim ();

		List<string> list;
		string entry = member.GetFullName ();
		if (!annotations.TryGetValue (entry, out list)) {
			list = new List<string> ();
			annotations.Add (entry, list);
			list.Add (note);
		} else if (!list.Contains (note)) {
			list.Add (note);
		}
		return true;
	}
Esempio n. 2
0
File: detect.cs Progetto: dfr0/moon
	public void MarkAsCritical (MemberReference member)
	{
		string entry = member.GetFullName ();
		if (remove_critical.Contains (entry))
			return;

		if (!critical.Contains (entry))
			critical.Add (entry);

		if (safe_critical.Contains (entry))
			safe_critical.Remove (entry);
	}
Esempio n. 3
0
File: detect.cs Progetto: dfr0/moon
	public void RemoveCritical (MemberReference member)
	{
		string entry = member.GetFullName ();
		remove_critical.Add (entry);
	}
Esempio n. 4
0
File: detect.cs Progetto: dfr0/moon
	public void MarkAsSafeCritical (MemberReference member)
	{
		string entry = member.GetFullName ();
		if (!safe_critical.Contains (entry))
			safe_critical.Add (entry);
	}
		private static bool IsNewException (MemberReference method)
		{
			switch (method.GetFullName ()) {
			// supplying a callback is enough to make the Timer creation worthwhile
			case "System.Void System.Threading.Timer::.ctor(System.Threading.TimerCallback,System.Object,System.Int32,System.Int32)":
				return true;
			default:
				return false;
			}
		}
		private void CheckIfBaseDisposeIsCalled (MethodDefinition method, MemberReference baseMethod)
		{
			bool found = false;

			if (method.HasBody) {
				OpCodeBitmask bitmask = OpCodeEngine.GetBitmask (method);
				if (bitmask.Get (Code.Ldarg_0) && (OpCodeBitmask.Calls.Intersect (bitmask))) {

					//Check for a call to base.Dispose();
					foreach (Instruction ins in method.Body.Instructions) {
						if (ins.OpCode.Code != Code.Ldarg_0) //ldarg_0 (this)
							continue;

						Instruction call = ins.Next; //call baseMethod
						if (call == null)
							continue;
						if (call.OpCode.Code != Code.Call && call.OpCode.Code != Code.Callvirt)
							continue;
						MethodReference calledMethod = (MethodReference) call.Operand;
						if (calledMethod.GetFullName () != baseMethod.GetFullName ())
							continue;
						found = true;
					}
				}
			}

			if (!found) {
				string s = String.Format (CultureInfo.InvariantCulture, "{0} should call base.Dispose().", method.GetFullName ());
				Runner.Report (method, Severity.Medium, Confidence.High, s);
			}
		}
		private void ResolveMethod (MemberReference method)
		{
			HashSet<string> rules;

			string m = method.GetFullName ();
			m = m.Substring (m.IndexOf (' ') + 1);

			if (targets.TryGetValue (m, out rules))
				Add (method, rules);
		}