From a0db68742f517af17269934667b19e6041a521cd Mon Sep 17 00:00:00 2001 From: de4dot Date: Thu, 15 Mar 2012 19:29:56 +0100 Subject: [PATCH] Add callsMethod() methods --- blocks/DotNetUtils.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/blocks/DotNetUtils.cs b/blocks/DotNetUtils.cs index 2f9d56ab..81251bba 100644 --- a/blocks/DotNetUtils.cs +++ b/blocks/DotNetUtils.cs @@ -1113,5 +1113,36 @@ namespace de4dot.blocks { return DotNetRuntimeType.Unknown; } + + public static bool callsMethod(MethodDefinition method, string methodFullName) { + if (method == null || method.Body == null) + return false; + + foreach (var instr in method.Body.Instructions) { + if (instr.OpCode.Code != Code.Call && instr.OpCode.Code != Code.Callvirt) + continue; + var calledMethod = instr.Operand as MethodReference; + if (calledMethod == null) + continue; + if (calledMethod.FullName == methodFullName) + return true; + } + + return false; + } + + public static bool callsMethod(MethodDefinition method, string returnType, string parameters) { + if (method == null || method.Body == null) + return false; + + foreach (var instr in method.Body.Instructions) { + if (instr.OpCode.Code != Code.Call && instr.OpCode.Code != Code.Callvirt) + continue; + if (isMethod(instr.Operand as MethodReference, returnType, parameters)) + return true; + } + + return false; + } } }