当前位置: 首页>>代码示例>>C#>>正文


C# MethodDefinition.IsSecurityCritical方法代码示例

本文整理汇总了C#中MethodDefinition.IsSecurityCritical方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDefinition.IsSecurityCritical方法的具体用法?C# MethodDefinition.IsSecurityCritical怎么用?C# MethodDefinition.IsSecurityCritical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MethodDefinition的用法示例。


在下文中一共展示了MethodDefinition.IsSecurityCritical方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessMethod

	static void ProcessMethod (MethodDefinition method)
	{
		// we consider all SafeNativeMethods.* as [SecuritySafeCritical]
		// if not then move them into NativeMethods or UnsafeNativeMethods
		if (method.IsPInvokeImpl && (method.DeclaringType.Name == "SafeNativeMethods")) {
			MarkAsSafeCritical (method);
			return;
		}

		if (!method.HasBody)
			return;

		// SC code can call SC code
		// note: here we use the 'rock' because the [SecurityCritical] attribute 
		// could be located on the type (or nested type)
		if (method.IsSecurityCritical ())
			return;

		// an icall that is part of the visible API is considered as safe critical
		if (method.IsInternalCall && (method.IsVisible () || method.IsVirtual)) {
			MarkAsSafeCritical (method);
			return;
		}

		foreach (Instruction ins in method.Body.Instructions) {
			MethodReference mr = (ins.Operand as MethodReference);
			if (mr == null)
				continue;

			MethodDefinition md = mr.Resolve ();
			if (md == null) {
				// this can occurs for some generated types, like Int[,] where the compiler generates a few methods
				continue;
			}

			// again we use the rock here as we want the final result (not the local attribute)
			if (md.IsSecurityCritical ()) {
				MarkAsSafeCritical (method);
				return;
			}
		}
	}
开发者ID:kangaroo,项目名称:moon,代码行数:42,代码来源:detect-ssc.cs

示例2: ProcessMethod

	static void ProcessMethod (MethodDefinition method)
	{
		string comment = null;

		// p/invoke methods needs to be [SecurityCritical] to be executed, 
		// unless they are inside a type named "SafeNativeMethods"
		bool sc = (method.IsPInvokeImpl && (method.DeclaringType.Name != "SafeNativeMethods"));
		if (sc) {
			comment = "p/invoke declaration";
		}

		if (!sc) {
			comment = CheckVerifiability (method);
			sc = !String.IsNullOrEmpty (comment);
		}

		// skip signature check for visible API (we get them from find-sc)
		if (!sc && method.HasParameters && !method.IsVisible ()) {
			// compilers will add public stuff like: System.Action`1::.ctor(System.Object,System.IntPtr)
			if (!method.IsConstructor || (method.DeclaringType as TypeDefinition).BaseType.FullName != "System.MulticastDelegate") {
				foreach (ParameterDefinition p in method.Parameters) {
					if (!CheckType (p.ParameterType)) {
						sc = true;
						comment = String.Format ("using '{0}' as a parameter type", p.ParameterType.FullName);
						break;
					}
				}
			}
		}

		// skip signature check for visible API (we get them from find-sc)
		if (!sc && !method.IsVisible ()) {
			TypeReference rtype = method.ReturnType;
			if (!CheckType (rtype)) {
				sc = true;
				comment = String.Format ("using '{0}' as return type", rtype.FullName);
			}
		}

		// check if this method implements an interface where the corresponding member
		// is [SecurityCritical]
		TypeDefinition type = method.DeclaringType;
		if (!sc && type.HasInterfaces) {
			foreach (TypeReference intf in type.Interfaces) {
				TypeDefinition td = intf.Resolve ();
				if (td == null || !td.HasMethods)
					continue;
				foreach (MethodDefinition im in td.GetMethods ()) {
					if (im.IsSecurityCritical ()) {
						if (Compare (method, im)) {
							sc = true;
							comment = String.Format ("implements '{0}'.", im);
						}
					}
				}
			}
		}

		// if we're overriding a [SecurityCritical] method then we must be one too! or
		// if we are [SecurityCritical] then the base method needs to be too!
		if (method.IsVirtual && !method.IsAbstract) {
			TypeReference tr = method.DeclaringType.BaseType;
			if (tr != null) {
				TypeDefinition td = tr.Resolve ();
				if (td != null) {
					foreach (MethodDefinition bm in td.GetMethods ()) {
						if (Compare (method, bm)) {
							if (!sc) {
								if (bm.IsSecurityCritical ()) {
									sc = true;
									comment = String.Format ("overrides '{0}'.", bm);
								}
							} else {
								if (!bm.IsSecurityCritical ()) {
									string bms = bm.ToString ();
									if (!methods.ContainsKey (bms)) {
										comment = String.Format ("Promoting {0}base method to [SecurityCritical] because of '{1}'.", 
											bm.IsVisible () ? "[VISIBLE] " : String.Empty, method);
										methods.Add (bms, comment);
									}
								}
							}							
						}
					}
				}
			}
		} else {
			// note: we don't want to break the override rules above (resulting in TypeLoadException)
			// an icall that is NOT part of the visible API is considered as critical (like a p/invoke)
			if (method.IsInternalCall && !method.IsVisible ()) {
				sc = true;
				comment = "internal call";
			}
		}

		if (sc) {
			// note: add a warning on visible API since adding [SecurityCritical]
			// on "new" visible API would introduce incompatibility (so this needs
			// to be reviewed).
			if (method.IsVisible ())
//.........这里部分代码省略.........
开发者ID:snorp,项目名称:moon,代码行数:101,代码来源:detect-sc.cs


注:本文中的MethodDefinition.IsSecurityCritical方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。