From 60c98cc9443634418ada7493f8db66d249d340d8 Mon Sep 17 00:00:00 2001 From: de4dot Date: Thu, 26 Apr 2012 01:14:46 +0200 Subject: [PATCH] Add method to find a PInvoke method --- blocks/DotNetUtils.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/blocks/DotNetUtils.cs b/blocks/DotNetUtils.cs index a445eec5..2a322266 100644 --- a/blocks/DotNetUtils.cs +++ b/blocks/DotNetUtils.cs @@ -382,6 +382,22 @@ namespace de4dot.blocks { return method != null && method.FullName == returnType + " " + method.DeclaringType.FullName + "::" + method.Name + parameters; } + public static bool hasPinvokeMethod(TypeDefinition type, string methodName) { + return getPInvokeMethod(type, methodName) != null; + } + + public static MethodDefinition getPInvokeMethod(TypeDefinition type, string methodName) { + if (type == null) + return null; + foreach (var method in type.Methods) { + if (method.PInvokeInfo == null) + continue; + if (method.PInvokeInfo.EntryPoint == methodName) + return method; + } + return null; + } + public static MethodDefinition getPInvokeMethod(TypeDefinition type, string dll, string funcName) { foreach (var method in type.Methods) { if (isPinvokeMethod(method, dll, funcName))