找回密码
 注册创意安天

验证微软数字签名zz

[复制链接]
发表于 2009-7-28 15:52 | 显示全部楼层 |阅读模式
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[100];
CryptCATAdminCalcHashFromFileHandle( hFile, &dwCnt, byHash, 0 );
CloseHandle( hFile );

LPWSTR pszMemberTag = new WCHAR[dwCnt * 2 + 1];
for ( DWORD dw = 0; dw < dwCnt; ++dw )
{
wsprintfW( &pszMemberTag[dw * 2], L"%02X", byHash[dw] );
}

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  

--------------------------------------------------------------------------------
吼吼,楼上签名真帅。
<---- 以上言论仅代表本人立场 ---->



__________________
这其实是个变量名.
您需要登录后才可以回帖 登录 | 注册创意安天

本版积分规则

Archiver|手机版|小黑屋|创意安天 ( 京ICP备09068574,ICP证100468号。 )

GMT+8, 2024-11-18 09:45

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表