Skip to content

Instantly share code, notes, and snippets.

@HoShiMin
Created January 26, 2016 21:35
Show Gist options
  • Save HoShiMin/f4a7a704d7918d066e77 to your computer and use it in GitHub Desktop.
Save HoShiMin/f4a7a704d7918d066e77 to your computer and use it in GitHub Desktop.
Функция для проверки валидности цифровой подписи бинарника
unit WinTrust;
interface
uses
Windows, System.SysUtils;
// Проверить валидность цифровой подписи:
function IsFileTrusted(const FileName: string): Boolean;
implementation
function IsFileTrusted(const FileName: string): Boolean;
type
TWINTRUST_FILE_INFO = record
cbStruct : LongWord;
FilePath : PWideChar;
hFile : THandle;
KnownObject : PGUID;
end;
PWINTRUST_FILE_INFO = ^TWINTRUST_FILE_INFO;
TWINTRUST_DATA = record
cbStruct : LongWord;
pPolicyCallbackData : Pointer;
pSIPClientData : Pointer;
dwUIChoise : LongWord;
fdwRevocationChecks : LongWord;
dwUnionChoise : LongWord;
pFileInfo : PWINTRUST_FILE_INFO;
dwStateAction : LongWord;
hWVTStateData : THandle;
pwszURLReference : PWideChar;
dwProvFlags : LongWord;
dwUIContext : LongWord;
pSignatureSettings : Pointer;
end;
var
FileInfo: TWINTRUST_FILE_INFO;
PolicyGUID: TGUID;
WinTrustData: TWINTRUST_DATA;
const
WINTRUST_ACTION_GENERIC_VERIFY_V2: string = '{00AAC56B-CD44-11d0-8CC2-00C04FC295EE}';
WTD_UI_NONE = 2;
WTD_REVOKE_NONE = 0;
WTD_CHOICE_FILE = 1;
STATUS_SUCCESS = 0;
begin
FileInfo.cbStruct := SizeOf(FileInfo);
FileInfo.FilePath := PWideChar(FileName);
FileInfo.hFile := 0;
FileInfo.KnownObject := nil;
PolicyGUID := StringToGUID(WINTRUST_ACTION_GENERIC_VERIFY_V2);
FillChar(WinTrustData, SizeOf(WinTrustData), #0);
WinTrustData.cbStruct := SizeOf(WinTrustData);
WinTrustData.dwUIChoise := WTD_UI_NONE;
WinTrustData.fdwRevocationChecks := WTD_REVOKE_NONE;
WinTrustData.dwUnionChoise := WTD_CHOICE_FILE;
WinTrustData.pFileInfo := @FileInfo;
Result := WinVerifyTrust(0, PolicyGUID, @WinTrustData) = STATUS_SUCCESS;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment