Ruthg
Ruthg

Reputation: 241

Programmatically verify signed dll's C++

I have a signed dll and want to verify its signature before I use it. my application is written by C++. How can I get programmatically the dll's signature?

Upvotes: 4

Views: 6979

Answers (3)

Roman Ryltsov
Roman Ryltsov

Reputation: 69632

One of the options is CAPICOM library, which is available as 32-bit redistributable from Microsoft. The verification code can be as simple as:

CComPtr<Capicom::ISignedCode> pSignedCode;
ATLENSURE_SUCCEEDED(pSignedCode.CoCreateInstance(__uuidof(Capicom::SignedCode)));
ATLENSURE_SUCCEEDED(pSignedCode->put_FileName(CComBSTR(pszPath)));
HRESULT nVerifyResult = pSignedCode->Verify(ATL_VARIANT_FALSE);

You can also easily obtain additional information such as signer, certificate etc.

If you don't feel like using CAPICOM, MSDN suggests alternate options to SignedCode class used in code snippet above.

Upvotes: 0

SChepurin
SChepurin

Reputation: 1854

MSDN recommended way is to run SignTool which is part of CryptoAPI -

SignTool returns command-line text that states the result of the signature check. Additionally, SignTool returns an exit code of zero for successful execution, one for failed execution, and two for execution that completed with warnings.

See Using SignTool to Verify a File Signature for details.

Upvotes: 0

perilbrain
perilbrain

Reputation: 8187

You can use WinVerifyTrust function.
Dlls and PE are almost same except for 2 to 3 bytes difference in there header.
A full code example is here (also applicable to dll).

Upvotes: 6

Related Questions