检查 DLL 是否已签名 C++

Check if a DLL is signed C++

我正在尝试检查是否根据文件路径对 DLL 进行了签名。我看到使用 WinVerifyTrust 已经存在针对此类问题的解决方案,但是,当我尝试根据 "C:\Windows\System32\kernel32.dll" 检查它时,它说:“文件 "C:\Windows\System32\kernel32.dll" 未签名。”虽然 kernel32 应该是一个签名的 dll。我在 Windows 7 fyi.

这是我调用的函数的源代码:https://msdn.microsoft.com/en-us/library/windows/desktop/aa382384(v=vs.85).aspx

如何修复该功能?

WinVerifyTrust 是正确的函数,但您必须做好调用它两次的准备。

首先你用 WTD_CHOICE_FILE, if that succeeds then you are done. If not, you must call it again with WTD_CHOICE_CATALOG (CryptCATAdminCalcHashFromFileHandle + CryptCATAdminEnumCatalogFromHash + CryptCATCatalogInfoFromContext) because some Windows files do not embed the certificate information (especially non-PE files). (You can also try to find the catalog info first 调用它以避免调用它两次,但我认为这比较慢)

Sysinternals 论坛上有各种主题 (this and this) 也许是解决与此相关问题的最佳资源。