如何使用 ICLRStrongName::StrongNameSignatureVerificationEx 方法来识别延迟签名的程序集 [英] How to use ICLRStrongName::StrongNameSignatureVerificationEx Method to identify delay signed assemblies

查看:23
本文介绍了如何使用 ICLRStrongName::StrongNameSignatureVerificationEx 方法来识别延迟签名的程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以建议如何使用 ICLRStrongName::StrongNameSignatureVerificationEx 方法来识别延迟签名的程序集.我在互联网上找不到任何例子.我不明白如何使用这种方法.

Can anybody please suggest how to use ICLRStrongName::StrongNameSignatureVerificationEx method to identify delay signed assembly. I could not find any example in the internet. I am not understanding how to work with this method.

请不要给我任何链接,我几乎对网络上的不同建议和不同链接感到沮丧.任何人都可以提供相同的代码示例.

Please don't refer me any link, I am almost frustrated with different suggestions and different links available in the web. Can anybody please give code sample for the same.

推荐答案

我也遇到了同样的问题,终于找到时间去调查了.我真的不明白为什么微软没有花时间编写足够的文档.

I had the same problem and finally found the time to investigate. I really don't understand why Microsoft did not take the time to write an adequate documentation.

以下链接非常有用并且还包含一个示例项目,即使它也没有回答所有问题:http://clractivation.codeplex.com/

Following link is very helpful and also contains a sample project, even if it also doesn't answer all questions: http://clractivation.codeplex.com/

我将尝试用一个简短的代码示例来回答所有问题.您可以使用类似这样的方法来验证程序集的强名称:

I'll try to answer all questions with a short code sample. You could use something like this to verify a assembly's strong name:

public bool VerifyStrongName(string assemblyPath, bool force)
{
  if (string.IsNullOrEmpty(assemblyPath))
    throw new ArgumentException(string.Empty, "assemblyPath");

  var host = HostingInteropHelper.GetClrMetaHost<IClrMetaHost>();

  var bufferSize = 100;
  var version = new StringBuilder(bufferSize);
  var result = host.GetVersionFromFile(Assembly.GetExecutingAssembly().Location, version, ref bufferSize);
  if ((HResult)result != HResult.S_OK)
    throw new COMException("Error", result);

  IClrRuntimeInfo info = host.GetRuntime(version.ToString(), new Guid(IID.IClrRuntimeInfo)) as IClrRuntimeInfo;
  ICLRStrongName sn = info.GetInterface(new Guid(CLSID.ClrStrongName), new Guid(IID.IClrStrongName)) as ICLRStrongName;

  var verResult = sn.StrongNameSignatureVerificationEx(assemblyPath, Convert.ToByte(force));
  return Convert.ToBoolean(verResult);
}

您可以在 ClrActivation 示例项目中找到此示例中使用的所有类和接口.

You can find all classed and interfaces used in this sample in the ClrActivation sample project.

此外,我将 HRESULT 类更改为枚举...

Additionaly I changed the HRESULT class to be an enum...

  /// <summary>
  /// A set of common, useful HRESULTS, and related functionality
  /// </summary>
  public enum HResult
  {
    /// <summary>
    /// OK/true/Success
    /// </summary>
    S_OK = 0,
    /// <summary>
    /// False
    /// </summary>
    S_FALSE = 1,
    /// <summary>
    /// The method is not implemented
    /// </summary>
    E_NOTIMPL = unchecked((int)0x80004001),
    /// <summary>
    /// The interface is not supported
    /// </summary>
    E_NOINTERFACE = unchecked((int)0x80004002),
    /// <summary>
    /// Bad Pointer
    /// </summary>
    E_POINTER = unchecked((int)0x8004003),
    /// <summary>
    /// General failure HRESULT
    /// </summary>
    E_FAIL = unchecked((int)0x8004005),
    /// <summary>
    /// Invalid Argument
    /// </summary>
    E_INVALIDARG = unchecked((int)0x80070057),
    /// <summary>
    /// Insufficient buffer
    /// </summary>
    ERROR_INSUFFICIENT_BUFFER = unchecked((int)0x8007007A),
    /// <summary>
    /// HRESULT for failure to find or load an appropriate runtime
    /// </summary>
    CLR_E_SHIM_RUNTIMELOAD = unchecked((int)0x80131700),

    SEVERITY = unchecked((int)0x80000000)
  }

...并添加了静态分类的 CLSIDIID(我花了一些时间才找到正确的 CLSID):

...and added the static classed CLSID and IID (took me some time to find the correct CLSID):

  public static class IID
  {
    public const string IClrRuntimeInfo = "BD39D1D2-BA2F-486A-89B0-B4B0CB466891";
    public const string IClrMetaHost = "D332DB9E-B9B3-4125-8207-A14884F53216";
    public const string IClrStrongName = "9FD93CCF-3280-4391-B3A9-96E1CDE77C8D";
    public const string IEnumUnknown = "00000100-0000-0000-C000-000000000046";
  }

  public static class CLSID
  {
    public const string ClrStrongName = "B79B0ACD-F5CD-409b-B5A5-A16244610B92";
  }

希望能帮到你.如果您还有其他问题,请随时提出.

I hope I could help you. If you have further questions, don't hesitate to ask.

这篇关于如何使用 ICLRStrongName::StrongNameSignatureVerificationEx 方法来识别延迟签名的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆