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


C# MethodDef类代码示例

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


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


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