• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# MethodDef类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MethodDef的典型用法代码示例。如果您正苦于以下问题:C# MethodDef类的具体用法?C# MethodDef怎么用?C# MethodDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MethodDef类属于命名空间,在下文中一共展示了MethodDef类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Find

		bool Find(MethodDef methodToCheck) {
			if (methodToCheck == null)
				return false;
			foreach (var method in DotNetUtils.GetCalledMethods(module, methodToCheck)) {
				var type = method.DeclaringType;

				if (!method.IsStatic || !DotNetUtils.IsMethod(method, "System.Void", "()"))
					continue;
				if (DotNetUtils.GetPInvokeMethod(type, "kernel32", "LoadLibrary") == null)
					continue;
				if (DotNetUtils.GetPInvokeMethod(type, "kernel32", "GetProcAddress") == null)
					continue;
				Deobfuscate(method);
				if (!ContainsString(method, "debugger is activ") &&
					!ContainsString(method, "debugger is running") &&
					!ContainsString(method, "Debugger detected") &&
					!ContainsString(method, "Debugger was detected") &&
					!ContainsString(method, "{0} was detected") &&
					!ContainsString(method, "run under") &&
					!ContainsString(method, "run with") &&
					!ContainsString(method, "started under") &&
					!ContainsString(method, "{0} detected") &&
					!ContainsString(method, "{0} found"))
					continue;

				antiDebuggerType = type;
				antiDebuggerMethod = method;
				return true;
			}

			return false;
		}
开发者ID:RafaelRMachado,项目名称:de4dot,代码行数:32,代码来源:AntiDebugger.cs


示例2: CheckMethod

		bool CheckMethod(ISimpleDeobfuscator simpleDeobfuscator, MethodDef method) {
			if (method == null || method.Body == null)
				return false;

			foreach (var instr in method.Body.Instructions) {
				if (instr.OpCode.Code != Code.Call)
					continue;
				var calledMethod = instr.Operand as MethodDef;
				if (calledMethod == null)
					continue;
				if (calledMethod == null || !calledMethod.IsStatic)
					continue;
				if (!DotNetUtils.IsMethod(calledMethod, "System.Void", "()"))
					continue;
				var type = calledMethod.DeclaringType;
				if (type.NestedTypes.Count > 0)
					continue;

				simpleDeobfuscator.Deobfuscate(calledMethod, SimpleDeobfuscatorFlags.Force | SimpleDeobfuscatorFlags.DisableConstantsFolderExtraInstrs);
				if (CheckType(type, calledMethod)) {
					initMethod = calledMethod;
					return true;
				}
			}
			return false;
		}
开发者ID:ximing-kooboo,项目名称:de4dot,代码行数:26,代码来源:AntiDumping.cs


示例3: OnAfterLoadArg

		protected override Instruction OnAfterLoadArg(MethodDef methodToInline, Instruction instr, ref int instrIndex) {
			if (instr.OpCode.Code != Code.Box)
				return instr;
			if (methodToInline.MethodSig.GetGenParamCount() == 0)
				return instr;
			return DotNetUtils.GetInstruction(methodToInline.Body.Instructions, ref instrIndex);
		}
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:7,代码来源:DsMethodCallInliner.cs


示例4: AnalyzedMethodUsesTreeNode

        public AnalyzedMethodUsesTreeNode(MethodDef analyzedMethod)
        {
            if (analyzedMethod == null)
                throw new ArgumentNullException("analyzedMethod");

            this.analyzedMethod = analyzedMethod;
        }
开发者ID:jorik041,项目名称:dnSpy-retired,代码行数:7,代码来源:AnalyzedMethodUsesTreeNode.cs


示例5: Initialize

		void Initialize() {
			var callCounter = new CallCounter();
			int count = 0;
			foreach (var type in module.GetTypes()) {
				if (count >= 40)
					break;
				foreach (var method in type.Methods) {
					if (method.Name != ".ctor" && method.Name != ".cctor" && module.EntryPoint != method)
						continue;
					foreach (var calledMethod in DotNetUtils.GetCalledMethods(module, method)) {
						if (!calledMethod.IsStatic || calledMethod.Body == null)
							continue;
						if (!DotNetUtils.IsMethod(calledMethod, "System.Void", "()"))
							continue;
						if (IsEmptyClass(calledMethod)) {
							callCounter.Add(calledMethod);
							count++;
						}
					}
				}
			}

			int numCalls;
			var theMethod = (MethodDef)callCounter.Most(out numCalls);
			if (numCalls >= 10)
				emptyMethod = theMethod;
		}
开发者ID:RafaelRMachado,项目名称:de4dot,代码行数:27,代码来源:EmptyClass.cs


示例6: Decompile

		public override void Decompile(MethodDef method, IDecompilerOutput output, DecompilationContext ctx) {
			WriteCommentBegin(output, true);
			output.Write("Method: ", BoxedTextColor.Comment);
			output.Write(IdentifierEscaper.Escape(method.FullName), method, DecompilerReferenceFlags.Definition, BoxedTextColor.Comment);
			WriteCommentEnd(output, true);
			output.WriteLine();

			if (!method.HasBody) {
				return;
			}

			StartKeywordBlock(output, ".body", method);

			ILAstBuilder astBuilder = new ILAstBuilder();
			ILBlock ilMethod = new ILBlock();
			DecompilerContext context = new DecompilerContext(method.Module, MetadataTextColorProvider) { CurrentType = method.DeclaringType, CurrentMethod = method };
			ilMethod.Body = astBuilder.Build(method, inlineVariables, context);

			if (abortBeforeStep != null) {
				new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
			}

			if (context.CurrentMethodIsAsync) {
				output.Write("async", BoxedTextColor.Keyword);
				output.Write("/", BoxedTextColor.Punctuation);
				output.WriteLine("await", BoxedTextColor.Keyword);
			}

			var allVariables = ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable)
				.Where(v => v != null && !v.IsParameter).Distinct();
			foreach (ILVariable v in allVariables) {
				output.Write(IdentifierEscaper.Escape(v.Name), v, DecompilerReferenceFlags.Local | DecompilerReferenceFlags.Definition, v.IsParameter ? BoxedTextColor.Parameter : BoxedTextColor.Local);
				if (v.Type != null) {
					output.Write(" ", BoxedTextColor.Text);
					output.Write(":", BoxedTextColor.Punctuation);
					output.Write(" ", BoxedTextColor.Text);
					if (v.IsPinned) {
						output.Write("pinned", BoxedTextColor.Keyword);
						output.Write(" ", BoxedTextColor.Text);
					}
					v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
				}
				if (v.GeneratedByDecompiler) {
					output.Write(" ", BoxedTextColor.Text);
					output.Write("[", BoxedTextColor.Punctuation);
					output.Write("generated", BoxedTextColor.Keyword);
					output.Write("]", BoxedTextColor.Punctuation);
				}
				output.WriteLine();
			}

			var builder = new MethodDebugInfoBuilder(method);
			foreach (ILNode node in ilMethod.Body) {
				node.WriteTo(output, builder);
				if (!node.WritesNewLine)
					output.WriteLine();
			}
			output.AddDebugInfo(builder.Create());
			EndKeywordBlock(output);
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:60,代码来源:ILAstDecompiler.cs


示例7: FindKey

		static short[] FindKey(MethodDef initMethod, FieldDefAndDeclaringTypeDict<bool> fields) {
			var instrs = initMethod.Body.Instructions;
			for (int i = 0; i < instrs.Count - 2; i++) {
				var ldci4 = instrs[i];
				if (!ldci4.IsLdcI4())
					continue;
				var newarr = instrs[i + 1];
				if (newarr.OpCode.Code != Code.Newarr)
					continue;
				if (newarr.Operand.ToString() != "System.Char")
					continue;

				var stloc = instrs[i + 2];
				if (!stloc.IsStloc())
					continue;
				var local = stloc.GetLocal(initMethod.Body.Variables);

				int startInitIndex = i;
				i++;
				var array = ArrayFinder.GetInitializedInt16Array(ldci4.GetLdcI4Value(), initMethod, ref i);
				if (array == null)
					continue;

				var field = GetStoreField(initMethod, startInitIndex, local);
				if (field == null)
					continue;
				if (fields.Find(field))
					return array;
			}

			return null;
		}
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:32,代码来源:StringDecrypter.cs


示例8: Initialize

		public void Initialize(MethodDef method, bool emulateFromFirstInstruction) {
			this.parameterDefs = method.Parameters;
			this.localDefs = method.Body.Variables;
			valueStack.Initialize();
			protectedStackValues.Clear();

			if (method != prev_method) {
				prev_method = method;

				cached_args.Clear();
				for (int i = 0; i < parameterDefs.Count; i++)
					cached_args.Add(GetUnknownValue(parameterDefs[i].Type));

				cached_locals.Clear();
				cached_zeroed_locals.Clear();
				for (int i = 0; i < localDefs.Count; i++) {
					cached_locals.Add(GetUnknownValue(localDefs[i].Type));
					cached_zeroed_locals.Add(GetDefaultValue(localDefs[i].Type));
				}
			}

			args.Clear();
			args.AddRange(cached_args);
			locals.Clear();
			locals.AddRange(method.Body.InitLocals && emulateFromFirstInstruction ? cached_zeroed_locals : cached_locals);
		}
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:26,代码来源:InstructionEmulator.cs


示例9: ILAST

        public ILAST(MethodDef method)
        {
            Method = method;
            Elements = new List<Element>();

            ProcessMethod();
        }
开发者ID:crajeshbe,项目名称:ILAST,代码行数:7,代码来源:ILAST.cs


示例10: canInline

        public static bool canInline(MethodDef method)
        {
            if (method == null || method.Body == null)
                return false;
            if (method.Attributes != (MethodAttributes.Assembly | MethodAttributes.Static))
                return false;
            if (method.Body.ExceptionHandlers.Count > 0)
                return false;

            var parameters = method.MethodSig.GetParams();
            int paramCount = parameters.Count;
            if (paramCount < 2)
                return false;

            if (method.GenericParameters.Count > 0) {
                foreach (var gp in method.GenericParameters) {
                    if (gp.GenericParamConstraints.Count == 0)
                        return false;
                }
            }

            var param1 = parameters[paramCount - 1];
            var param2 = parameters[paramCount - 2];
            if (!isIntType(param1.ElementType))
                return false;
            if (!isIntType(param2.ElementType))
                return false;

            return true;
        }
开发者ID:GodLesZ,项目名称:ConfuserDeobfuscator,代码行数:30,代码来源:DsMethodCallInliner.cs


示例11: CheckMethod

		bool CheckMethod(MethodDef cctor) {
			if (cctor == null || cctor.Body == null)
				return false;
			var localTypes = new LocalTypes(cctor);
			if (!localTypes.Exactly(ilpLocalsV1x) &&
				!localTypes.Exactly(ilpLocalsV2x))
				return false;

			var type = cctor.DeclaringType;
			var methods = GetPinvokeMethods(type, "Protect");
			if (methods.Count == 0)
				methods = GetPinvokeMethods(type, "P0");
			if (methods.Count != 2)
				return false;
			if (type.Fields.Count < 1 || type.Fields.Count > 2)
				return false;

			if (!GetDelegate(type, out invokerInstanceField, out invokerDelegate))
				return false;

			runtimeFileInfos = new List<RuntimeFileInfo>(methods.Count);
			foreach (var method in methods)
				runtimeFileInfos.Add(new RuntimeFileInfo(method));
			return true;
		}
开发者ID:SAD1992,项目名称:justdecompile-plugins,代码行数:25,代码来源:MainType.cs


示例12: Inject

 /// <summary>
 ///     Injects the specified MethodDef to another module.
 /// </summary>
 /// <param name="methodDef">The source MethodDef.</param>
 /// <param name="target">The target module.</param>
 /// <returns>The injected MethodDef.</returns>
 public static MethodDef Inject(MethodDef methodDef, ModuleDef target)
 {
     var ctx = new InjectContext(methodDef.Module, target);
     ctx.Map[methodDef] = Clone(methodDef);
     CopyMethodDef(methodDef, ctx);
     return (MethodDef)ctx.Map[methodDef];
 }
开发者ID:MetSystem,项目名称:ConfuserEx,代码行数:13,代码来源:InjectHelper.cs


示例13: SetParameter

        public override void SetParameter(MethodDef.Param param, object obj, bool bReadonly)
        {
            base.SetParameter(param, obj, bReadonly);

            _resetProperties = false;

            string selectionName = string.Empty;
            VariableDef variable = param.Value as VariableDef;

            if (variable != null) {
                _valueOwner = variable.ValueClass;
                selectionName = (variable.Property != null) ? variable.Property.DisplayName : variable.DisplayName;

            } else {
                RightValueDef variableRV = param.Value as RightValueDef;

                if (variableRV != null)
                {
                    _valueOwner = variableRV.ValueClassReal;
                    selectionName = variableRV.DisplayName;
                }
            }

            Nodes.Behavior behavior = GetBehavior();
            _agentType = (behavior != null) ? behavior.AgentType : null;
            if (_valueOwner != VariableDef.kSelf)
            {
                _agentType = Plugin.GetInstanceAgentType(_valueOwner, behavior, _agentType);
            }

            setComboBox(selectionName);
        }
开发者ID:wuzhen,项目名称:behaviac,代码行数:32,代码来源:DesignerPropertyEnumEditor.cs


示例14: WriteTo

		public static void WriteTo(this ExceptionHandler exceptionHandler, ITextOutput writer, MethodDef method)
		{
			writer.Write("Try", TextTokenType.Keyword);
			writer.WriteSpace();
			WriteOffsetReference(writer, exceptionHandler.TryStart, method);
			writer.Write('-', TextTokenType.Operator);
			WriteOffsetReference(writer, exceptionHandler.TryEnd, method);
			writer.WriteSpace();
			writer.Write(exceptionHandler.HandlerType.ToString(), TextTokenType.Keyword);
			if (exceptionHandler.FilterStart != null) {
				writer.WriteSpace();
				WriteOffsetReference(writer, exceptionHandler.FilterStart, method);
				writer.WriteSpace();
				writer.Write("handler", TextTokenType.Keyword);
				writer.WriteSpace();
			}
			if (exceptionHandler.CatchType != null) {
				writer.WriteSpace();
				exceptionHandler.CatchType.WriteTo(writer);
			}
			writer.WriteSpace();
			WriteOffsetReference(writer, exceptionHandler.HandlerStart, method);
			writer.Write('-', TextTokenType.Operator);
			WriteOffsetReference(writer, exceptionHandler.HandlerEnd, method);
		}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:25,代码来源:DisassemblerHelpers.cs


示例15: CreateMethodBody

		HashSet<ILVariable> localVariablesToDefine = new HashSet<ILVariable>(); // local variables that are missing a definition
		
		/// <summary>
		/// Creates the body for the method definition.
		/// </summary>
		/// <param name="methodDef">Method definition to decompile.</param>
		/// <param name="context">Decompilation context.</param>
		/// <param name="parameters">Parameter declarations of the method being decompiled.
		/// These are used to update the parameter names when the decompiler generates names for the parameters.</param>
		/// <returns>Block for the method body</returns>
		public static BlockStatement CreateMethodBody(MethodDef methodDef,
		                                              DecompilerContext context,
		                                              IEnumerable<ParameterDeclaration> parameters,
													  out MemberMapping mm)
		{
			MethodDef oldCurrentMethod = context.CurrentMethod;
			Debug.Assert(oldCurrentMethod == null || oldCurrentMethod == methodDef);
			context.CurrentMethod = methodDef;
			context.CurrentMethodIsAsync = false;
			try {
				AstMethodBodyBuilder builder = new AstMethodBodyBuilder();
				builder.methodDef = methodDef;
				builder.context = context;
				builder.corLib = methodDef.Module.CorLibTypes;
				if (Debugger.IsAttached) {
					return builder.CreateMethodBody(parameters, out mm);
				} else {
					try {
						return builder.CreateMethodBody(parameters, out mm);
					} catch (OperationCanceledException) {
						throw;
					} catch (Exception ex) {
						throw new ICSharpCode.Decompiler.DecompilerException(methodDef, ex);
					}
				}
			} finally {
				context.CurrentMethod = oldCurrentMethod;
			}
		}
开发者ID:nakijun,项目名称:dnSpy,代码行数:39,代码来源:AstMethodBodyBuilder.cs


示例16: Write

		public static ITextOutput Write(ITextOutput output, MethodDef method, Language language) {
			output.Write(UIUtils.CleanUpIdentifier(method.Name), TextTokenHelper.GetTextTokenType(method));
			output.Write('(', TextTokenType.Operator);
			for (int i = 0; i < method.Parameters.Count; i++) {
				if (method.Parameters[i].IsHiddenThisParameter)
					continue;
				if (method.Parameters[i].MethodSigIndex > 0) {
					output.Write(',', TextTokenType.Operator);
					output.WriteSpace();
				}
				language.TypeToString(output, method.Parameters[i].Type.ToTypeDefOrRef(), false, method.Parameters[i].ParamDef);
			}
			if (method.CallingConvention == CallingConvention.VarArg || method.CallingConvention == CallingConvention.NativeVarArg) {
				if (method.MethodSig.GetParamCount() > 0) {
					output.Write(',', TextTokenType.Operator);
					output.WriteSpace();
				}
				output.Write("...", TextTokenType.Operator);
			}
			output.Write(')', TextTokenType.Operator);
			output.WriteSpace();
			output.Write(':', TextTokenType.Operator);
			output.WriteSpace();
			language.TypeToString(output, method.ReturnType.ToTypeDefOrRef(), false, method.Parameters.ReturnParameter.ParamDef);
			method.MDToken.WriteSuffixString(output);
			return output;
		}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:27,代码来源:MethodTreeNode.cs


示例17: CanShow

 public static bool CanShow(MethodDef method)
 {
     return method.IsVirtual &&
         !method.IsFinal &&
         !method.DeclaringType.IsSealed &&
         !method.DeclaringType.IsInterface;	// interface methods are definitions not implementations - cannot be overridden
 }
开发者ID:BahNahNah,项目名称:dnSpy,代码行数:7,代码来源:AnalyzedMethodOverridesTreeNode.cs


示例18: Check

		void Check(MethodDef method) {
			if (method.Body == null)
				return;
			if (possiblyUnusedMethods.ContainsKey(method))
				return;
			if (removedMethods.Exists(method))
				return;

			foreach (var instr in method.Body.Instructions) {
				switch (instr.OpCode.Code) {
				case Code.Call:
				case Code.Calli:
				case Code.Callvirt:
				case Code.Newobj:
				case Code.Ldtoken:
				case Code.Ldftn:
				case Code.Ldvirtftn:
					break;
				default:
					continue;
				}

				var calledMethod = DotNetUtils.GetMethod2(module, instr.Operand as IMethod);
				if (calledMethod == null)
					continue;
				if (possiblyUnusedMethods.ContainsKey(calledMethod))
					notUnusedStack.Push(calledMethod);
			}
		}
开发者ID:heartbleeded,项目名称:de4dot,代码行数:29,代码来源:UnusedMethodsFinder.cs


示例19: CheckHandlerMethod

		protected override bool CheckHandlerMethod(MethodDef method) {
			if (!method.IsStatic || !method.HasBody)
				return false;

			EmbeddedAssemblyInfo info = null;
			var instructions = method.Body.Instructions;
			for (int i = 0; i < instructions.Count; i++) {
				var instrs = DotNetUtils.GetInstructions(instructions, i, OpCodes.Ldstr, OpCodes.Call);
				if (instrs == null)
					continue;

				var s = instrs[0].Operand as string;
				var calledMethod = instrs[1].Operand as IMethod;
				if (s == null || calledMethod == null)
					continue;

				info = assemblyResolverInfo.Find(Utils.GetAssemblySimpleName(s));
				if (info != null)
					break;
			}
			if (info == null)
				return false;

			resourceInfo = info;
			Logger.v("Found embedded assemblies resource {0}", Utils.ToCsharpString(info.resourceName));
			return true;
		}
开发者ID:GodLesZ,项目名称:de4dot,代码行数:27,代码来源:ResourceResolverInfo.cs


示例20: JumpToStatement

		static bool JumpToStatement(MethodDef method, uint ilOffset, DecompilerTextView textView) {
			if (method == null)
				return false;
			var serMod = method.Module.ToSerializedDnSpyModule();
			var key = new SerializedDnSpyToken(serMod, method.MDToken);
			if (textView == null)
				textView = MainWindow.Instance.SafeActiveTextView;

			bool found = MainWindow.Instance.DnSpyFileListTreeNode.FindModuleNode(method.Module) != null;
			if (found) {
				return MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => {
					if (success)
						return MoveCaretTo(textView, key, ilOffset);
					return false;
				});
			}

			MainWindow.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => {
				MainWindow.Instance.JumpToReference(textView, method, (success, hasMovedCaret) => {
					if (success)
						return MoveCaretTo(textView, key, ilOffset);
					return false;
				});
			}));
			return true;
		}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:26,代码来源:DebugUtils.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MethodDefinition类代码示例发布时间:2022-05-24
下一篇:
C# MethodDeclaration类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap