1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
// mycert.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwWritten;
DWORD bigEnough;
HANDLE hCertFile;
BYTE *pbHashData = new BYTE[bigEnough]; // call api to find out real size first in real code
DWORD pbHashDatasize = bigEnough;
PCCERT_CONTEXT certcontext = NULL;
// Get the cert data
MsiGetFileSignatureInformation(argv[1], 0, &certcontext, pbHashData, &pbHashDatasize);
// Write it to a file
hCertFile = CreateFile(argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
WriteFile(hCertFile, certcontext->pbCertEncoded, certcontext->cbCertEncoded, &dwWritten, NULL);
CloseHandle(hCertFile);
// Clean up
CertFreeCertificateContext(certcontext);
return 0;
}
|