验证微软数字签名zz
robinh00d普通会员
发贴: 46
积分: 0
来自:
注册日期: 2006-11-29
发表时间: 2007-03-28 15:48:53
--------------------------------------------------------------------------------
BOOL CheckFileTrust( LPCWSTR lpFileName )
{
BOOL bRet = FALSE;
WINTRUST_DATA wd = { 0 };
WINTRUST_FILE_INFO wfi = { 0 };
WINTRUST_CATALOG_INFO wci = { 0 };
CATALOG_INFO ci = { 0 };
HCATADMIN hCatAdmin = NULL;
if ( !CryptCATAdminAcquireContext( &hCatAdmin, NULL, 0 ) )
{
return FALSE;
}
HANDLE hFile = CreateFileW( lpFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, NULL );
if ( INVALID_HANDLE_VALUE == hFile )
{
CryptCATAdminReleaseContext( hCatAdmin, 0 );
return FALSE;
}
DWORD dwCnt = 100;
BYTE byHash;
CryptCATAdminCalcHashFromFileHandle( hFile, &dwCnt, byHash, 0 );
CloseHandle( hFile );
LPWSTR pszMemberTag = new WCHAR;
for ( DWORD dw = 0; dw < dwCnt; ++dw )
{
wsprintfW( &pszMemberTag, L"%02X", byHash );
}
HCATINFO hCatInfo = CryptCATAdminEnumCatalogFromHash( hCatAdmin,
byHash, dwCnt, 0, NULL );
if ( NULL == hCatInfo )
{
wfi.cbStruct = sizeof( WINTRUST_FILE_INFO );
wfi.pcwszFilePath = lpFileName;
wfi.hFile = NULL;
wfi.pgKnownSubject = NULL;
wd.cbStruct = sizeof( WINTRUST_DATA );
wd.dwUnionChoice = WTD_CHOICE_FILE;
wd.pFile = &wfi;
wd.dwUIChoice = WTD_UI_NONE;
wd.fdwRevocationChecks = WTD_REVOKE_NONE;
wd.dwStateAction = WTD_STATEACTION_IGNORE;
wd.dwProvFlags = WTD_SAFER_FLAG;
wd.hWVTStateData = NULL;
wd.pwszURLReference = NULL;
}
else
{
CryptCATCatalogInfoFromContext( hCatInfo, &ci, 0 );
wci.cbStruct = sizeof( WINTRUST_CATALOG_INFO );
wci.pcwszCatalogFilePath = ci.wszCatalogFile;
wci.pcwszMemberFilePath = lpFileName;
wci.pcwszMemberTag = pszMemberTag;
wd.cbStruct = sizeof( WINTRUST_DATA );
wd.dwUnionChoice = WTD_CHOICE_CATALOG;
wd.pCatalog = &wci;
wd.dwUIChoice = WTD_UI_NONE;
wd.fdwRevocationChecks = WTD_STATEACTION_VERIFY;
wd.dwProvFlags = 0;
wd.hWVTStateData = NULL;
wd.pwszURLReference = NULL;
}
GUID action = WINTRUST_ACTION_GENERIC_VERIFY_V2;
HRESULT hr = WinVerifyTrust( NULL, &action, &wd );
bRet = SUCCEEDED( hr );
if ( NULL != hCatInfo )
{
CryptCATAdminReleaseContext( hCatInfo, 0 );
}
CryptCATAdminReleaseCatalogContext( hCatAdmin, hCatInfo, 0 );
delete[] pszMemberTag;
return bRet;
}
此贴由robinh00d在 2007-03-28 15:49 编辑过。
<---- 以上言论仅代表本人立场 ---->
__________________
海纳百川
有容乃大
andy
普通会员
发贴: 104
积分: 0
来自:
注册日期: 2006-05-17
发表时间: 2007-04-10 09:08:56
--------------------------------------------------------------------------------
该代码有些问题,出现句柄泄露和内存泄露!令外缺少结构和函数声明的头文件!在VC6.0下需要自定义这些函数和结构!
<---- 以上言论仅代表本人立场 ---->
andy
普通会员
发贴: 104
积分: 0
来自:
注册日期: 2006-05-17
发表时间: 2007-04-10 09:09:55
--------------------------------------------------------------------------------
缺少的头文件在下列网站中
http://source.winehq.org/source/include/mscat.h
http://source.winehq.org/source/include/softpub.h
<---- 以上言论仅代表本人立场 ---->
andy
普通会员
发贴: 104
积分: 0
来自:
注册日期: 2006-05-17
发表时间: 2007-04-10 09:10:49
--------------------------------------------------------------------------------
令外
if ( NULL != hCatInfo )
{
CryptCATAdminReleaseContext( hCatInfo, 0 );
}
CryptCATAdminReleaseCatalogContext( hCatAdmin, hCatInfo, 0 );
这句写的有问题
应该在这样的
CryptCATAdminReleaseCatalogContext( hCatAdmin, hCatInfo, 0 );
if ( NULL != hCatAdmin)
{
CryptCATAdminReleaseContext( hCatAdmin, 0 );
}
<---- 以上言论仅代表本人立场 ---->
不累的王
普通会员
发贴: 339
积分: 0
来自:
注册日期: 2006-05-26
发表时间: 2007-04-10 19:15:25
--------------------------------------------------------------------------------
楼上真丢人...竟然写白字...
<---- 以上言论仅代表本人立场 ---->
__________________
“……机器人罗诺,现在我要对你下达最新指令了。”
“是,主人。我都等了三万年了呢。”
“你还记得回地球的航路吧?”
Winter_Leaf
普通会员
发贴: 25
积分: 0
来自:
注册日期: 2006-09-18
发表时间: 2007-05-29 15:43:19
--------------------------------------------------------------------------------
吼吼,楼上签名真帅。
<---- 以上言论仅代表本人立场 ---->
__________________
这其实是个变量名.
页:
[1]