Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a DLL is signed C++

I am trying to check if a DLL is signed based on the file path. I see that there are pre-existing solutions for this type of problem using WinVerifyTrust, however, when I tried checking it against "C:\Windows\System32\kernel32.dll" it said: "The file "C:\Windows\System32\kernel32.dll" is not signed." although kernel32 should be a signed dll. I am on Windows 7 fyi.

This is the source code to the function I called: https://msdn.microsoft.com/en-us/library/windows/desktop/aa382384(v=vs.85).aspx

How can I fix the function?

like image 387
Rob Gates Avatar asked Jul 19 '17 04:07

Rob Gates


1 Answers

Yes WinVerifyTrust is the correct function to use but you have to be prepared to call it twice.

First you call it with 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 to avoid calling it twice but I assume this is slower)

There are various threads (this and this) on the Sysinternals forum is perhaps the best resource for questions related to this.

like image 155
Anders Avatar answered Sep 16 '22 18:09

Anders