Einzelnen Beitrag anzeigen

user

Registriert seit: 13. Jul 2010
25 Beiträge
 
Delphi 2 Desktop
 
#1

check this error pls

  Alt 10. Nov 2011, 01:47
I received a bug report (MadExcept) from my client. Maybe you can determine what made the problem?

Code:
callstack crc    : $057d639d, $abfa8e22, $abfa8e22
exception number : 1
exception class  : EAccessViolation
exception message : Access violation at address 057D639D. Write of address 302AEA36.

main thread ($788):
057d639d +0000 ???
77dd8116 +0095 ADVAPI32.dll                            RegEnumValueW
769c6a77 +00ea USERENV.dll                             CreateEnvironmentBlock
769c7745 +001a USERENV.dll                             ExpandEnvironmentStringsForUserW
769c1cae +00ed USERENV.dll                             #149
75e64a6a +1136 cryptnet.dll                            CryptRetrieveObjectByUrlW
75e62330 +004c cryptnet.dll                            CryptGetTimeValidObject
75e6245b +0000 cryptnet.dll                            CertDllVerifyRevocation
77a95f2c +004a CRYPT32.dll                             CertVerifyRevocation
77a9129f +005c CRYPT32.dll                             CertGetCertificateChain
76c3317d +0025 wintrust.dll                            WinVerifyTrust
004d2d3a +02be MyProg.exe   uSimpleTrustCheck 251 +106 CheckFileTrust
0066e7f0 +05e0 MyProg.exe   uBlaBLa        538 +149 Blabla
00671270 +06ac MyProg.exe   uBlaBLa       2067 +197 Blabla
0068183a +040e MyProg.exe   uMain            4148 +116 TFClnMain.btnScanClick
004a704c +0064 MyProg.exe   Controls                   TControl.Click
0048c55e +001e MyProg.exe   StdCtrls                   TButton.Click
0048c65c +000c MyProg.exe   StdCtrls                   TButton.CNCommand
004a6b47 +02bb MyProg.exe   Controls                   TControl.WndProc
004aab3e +04fa MyProg.exe   Controls                   TWinControl.WndProc
0048c408 +006c MyProg.exe   StdCtrls                   TButtonControl.WndProc
004a67d4 +0024 MyProg.exe   Controls                   TControl.Perform
004aac8f +0023 MyProg.exe   Controls                   DoControlMsg
004ab65b +000b MyProg.exe   Controls                   TWinControl.WMCommand
004a6b47 +02bb MyProg.exe   Controls                   TControl.WndProc
004aab3e +04fa MyProg.exe   Controls                   TWinControl.WndProc
004aa268 +002c MyProg.exe   Controls                   TWinControl.MainWndProc
00475ecc +0014 MyProg.exe   Classes                    StdWndProc
77d4e361 +0016 USER32.dll                              CallWindowProcA
004aac3b +00d7 MyProg.exe   Controls                   TWinControl.DefaultHandler
004a746c +0010 MyProg.exe   Controls                   TControl.WMLButtonUp
004a6b47 +02bb MyProg.exe   Controls                   TControl.WndProc
004aab3e +04fa MyProg.exe   Controls                   TWinControl.WndProc
0048c408 +006c MyProg.exe   StdCtrls                   TButtonControl.WndProc
004aa268 +002c MyProg.exe   Controls                   TWinControl.MainWndProc
00475ecc +0014 MyProg.exe   Classes                    StdWndProc
77d4bcc7 +000a USER32.dll                              DispatchMessageA
004c47f4 +00fc MyProg.exe   Forms                      TApplication.ProcessMessage
004c482e +000a MyProg.exe   Forms                      TApplication.HandleMessage
004c4b3f +00b3 MyProg.exe   Forms                      TApplication.Run
0069027d +01c9 MyProg.exe   MyProg             223  +79 initialization

.....

cpu registers:
eax = 302aea36
ebx = 7c90d977
ecx = 0012dd34
edx = 0012dd2c
esi = 0012dd15
edi = 0012dc04
eip = 057d639d
esp = 0012dbb9
ebp = 0012dce4

stack dump:
0012dbb9  7f dd 77 34 2b 00 00 00 - 00 00 00 01 00 00 00 04  ..w4+...........
0012dbc9  dc 12 00 dc 00 00 00 f4 - db 12 00 00 00 00 00 84  ................
0012dbd9  dd 12 00 a0 c2 46 08 34 - dd 12 00 a0 c2 46 08 2c .....F.4.....F.,
0012dbe9  dd 12 00 3c dd 12 00 01 - 00 00 00 18 6a dd 77 34  ...<........j.w4
0012dbf9  2b 00 00 00 00 00 00 02 - 00 00 80 ed 00 00 00 18  +...............
0012dc09  00 00 00 30 00 00 00 70 - dc 12 00 40 00 00 00 00  ...0...p...@....
0012dc19  00 00 00 00 00 00 00 72 - 00 72 00 98 61 9c 76 67  .......r.r..a.vg
0012dc29  00 72 00 00 00 00 00 fc - db 12 00 69 00 6c 00 3c .r.........i.l.<
0012dc39  ea 12 00 00 4b 00 00 78 - dc 12 00 54 70 dd 77 34  ....K..x...Tp.w4
0012dc49  2b 00 00 7c dc 12 00 5c - 9a 80 7c 88 dc 12 00 08  +..|...\..|.....
0012dc59  b9 80 7c 30 3f 17 00 13 - b9 80 7c ec b8 80 7c 24  ..|0?.....|...|$
0012dc69  00 00 00 e8 df 12 00 3d - fb 90 7c 2c dd 12 00 00  .......=..|,....
0012dc79  00 00 00 ac dc 12 00 6c - fb 90 7c 71 fb 90 7c 00  .......l..|q..|.
0012dc89  00 00 00 07 00 00 00 3d - fb 90 7c 88 dc 12 00 0c .......=..|.....
0012dc99  e0 12 00 f4 dc 12 00 18 - ee 90 7c 78 fb 90 7c ff ..........|x..|.
0012dca9  ff ff ff 00 4b 00 00 14 - dd 12 00 8e cd df 77 34  ....K.........w4
0012dcb9  2b 00 00 00 00 00 00 f0 - 3d 46 08 24 dd 12 00 20  +.......=F.$....
0012dcc9  dd 12 00 38 00 00 00 28 - dd 00 00 00 00 15 00 d0  ...8...(........
0012dcd9  da 12 00 ec dc 12 00 00 - 4b 00 00 24 dd 12 00 1b ........K..$....
0012dce9  81 dd 77 34 2b 00 00 00 - 00 00 00 14 dd 12 00 34  ..w4+..........4

disassembling:
77dd8081 public RegEnumValueW:           ; function entry point
77dd8081   mov    edi, edi
77dd8083   push   ebp
77dd8084   mov    ebp, esp
77dd8086   sub    esp, $10
77dd8089   push   ebx
77dd808a  push   esi
77dd808b  push   edi
77dd808c  xor    edi, edi
77dd808e  cmp    [ebp+$18], edi
77dd8091   mov    [ebp-4], edi
77dd8094   jnz    loc_77dfc583
77dd8094
77dd809a  mov    ebx, [ebp+$20]
77dd809d  cmp    ebx, edi
77dd809f  jz     loc_77dd80aa
77dd809f
77dd80a1   cmp    [ebp+$24], edi
77dd80a4   jz     loc_77dfc583
77dd80a4
77dd80aa loc_77dd80aa:
77dd80aa  cmp    [ebp+$14], edi
77dd80ad  jz     loc_77dfc583
77dd80ad
77dd80b3   mov    esi, [ebp+$10]
77dd80b6   cmp    esi, edi
77dd80b8   jz     loc_77dfc583
77dd80b8
77dd80be  lea    eax, [ebp-4]
77dd80c1   push   eax
77dd80c2   push   dword ptr [ebp+8]
77dd80c5   call   -$180a ($77dd68c0)
77dd80c5
77dd80ca  cmp    eax, edi
77dd80cc  jz     loc_77e06a8a
77dd80cc
77dd80d2   mov    ecx, [ebp+$14]
77dd80d5   mov    cx, [ecx]
77dd80d8   mov    [ebp-$c], esi
77dd80db  mov    esi, [ebp+$24]
77dd80de  shl    cx, 1
77dd80e1   cmp    esi, edi
77dd80e3   mov    [ebp-$10], di
77dd80e7   mov    [ebp-$e], cx
77dd80eb  mov    [ebp+8], edi
77dd80ee  jz     loc_77dfc57b
77dd80ee
77dd80f4   mov    ecx, [esi]
77dd80f6   mov    [ebp+$18], ecx
77dd80f4
77dd80f9 loc_77dd80f9:
77dd80f9   test   al, 1
77dd80fb  jnz    loc_77e06a96
77dd80fb
77dd8101   lea    ecx, [ebp+8]
77dd8104   push   ecx
77dd8105   lea    ecx, [ebp+$18]
77dd8108   push   ecx
77dd8109   push   ebx
77dd810a  lea    ecx, [ebp+$10]
77dd810d  push   ecx
77dd810e  lea    ecx, [ebp-$10]
77dd8111   push   ecx
77dd8112   push   dword ptr [ebp+$c]
77dd8115   push   eax
77dd8116 > call   -$212 ($77dd7f09)
77dd8116
77dd811b loc_77dd811b:
77dd811b  mov    [ebp+$c], eax
77dd8116
77dd811e loc_77dd811e:
77dd811e  cmp    [ebp+$c], edi
77dd8121   jz     loc_77dfc6f6
77dd8121
77dd8127 loc_77dd8127:
77dd8127   cmp    [ebp-$10], di
77dd812b  jnz    loc_77dfc726
77dd812b
77dd8131 loc_77dd8131:
77dd8131   cmp    esi, edi
77dd8133   jz     loc_77dd813a
77dd8133
77dd8135   mov    eax, [ebp+$18]
77dd8138   mov    [esi], eax
77dd8135
77dd813a loc_77dd813a:
77dd813a  mov    eax, [ebp+$1c]
77dd813d  cmp    eax, edi
77dd813f  jz     loc_77dd8146
77dd813f
77dd8141   mov    ecx, [ebp+$10]
77dd8144   mov    [eax], ecx
77dd8141
77dd8146 loc_77dd8146:
77dd8146   cmp    [ebp-4], edi
77dd8149   jnz    loc_77e06b8c
77dd8149
77dd814f loc_77dd814f:
77dd814f  mov    eax, [ebp+$c]
77dd8149
77dd8152 loc_77dd8152:
77dd8152   pop    edi
77dd8153   pop    esi
77dd8154   pop    ebx
77dd8155   leave
77dd8156   ret    $20
77dd8156
77dd8156 ; ---------------------------------------------------------
77dd8156
77dfc57b loc_77dfc57b:
77dfc57b  mov    [ebp+$18], edi
77dfc57e  jmp    loc_77dd80f9
77dfc57e
77dfc57e ; ---------------------------------------------------------
77dfc57e
77dfc583 loc_77dfc583:
77dfc583   push   $57
77dfc585   pop    eax
77dfc586   jmp    loc_77dd8152
77dfc586
77dfc586 ; ---------------------------------------------------------
77dfc586
77dfc6f6 loc_77dfc6f6:
77dfc6f6   cmp    ebx, edi
77dfc6f8   jz     loc_77dd8127
77dfc6f8
77dfc6fe  cmp    dword ptr [ebp+$10], 1
77dfc702   jnz    loc_77dfc737
77dfc702
77dfc704 loc_77dfc704:
77dfc704   mov    ecx, [ebp+$18]
77dfc707   cmp    ecx, 2
77dfc70a  jbe    loc_77dd8127
77dfc70a
77dfc710   mov    eax, ecx
77dfc712   shr    eax, 1
77dfc714   lea    eax, [ebx+eax*2]
77dfc717   cmp    [eax-2], di
77dfc71b  jnz    loc_77e06b79
77dfc71b
77dfc721   jmp    loc_77dd8127
77dfc721
77dfc721 ; ---------------------------------------------------------
77dfc721
77dfc726 loc_77dfc726:
77dfc726   movzx  eax, word ptr [ebp-$10]
77dfc72a  mov    ecx, [ebp+$14]
77dfc72d  shr    eax, 1
77dfc72f  dec    eax
77dfc730   mov    [ecx], eax
77dfc732   jmp    loc_77dd8131
77dfc732
77dfc732 ; ---------------------------------------------------------
77dfc732
77dfc737 loc_77dfc737:
77dfc737   cmp    dword ptr [ebp+$10], 2
77dfc73b  jz     loc_77dfc704
77dfc73b
77dfc73d  cmp    dword ptr [ebp+$10], 7
77dfc741   jnz    loc_77dd8127
77dfc741
77dfc747   jmp    loc_77dfc704
77dfc747
77dfc747 ; ---------------------------------------------------------
77dfc747
77e06a8a loc_77e06a8a:
77e06a8a  mov    dword ptr [ebp+$c], 6
77e06a91   jmp    loc_77dd8146
77e06a91
77e06a91 ; ---------------------------------------------------------
77e06a91
77e06a96 loc_77e06a96:
77e06a96   mov    esi, eax
77e06a98   lea    eax, [ebp-8]
77e06a9b  push   eax
77e06a9c  and    esi, -2
77e06a9f  push   esi
77e06aa0   call   +$2f9af ($77e36454)
77e06aa0
77e06aa5   test   eax, eax
77e06aa7   jnz    loc_77e06b57
77e06aa7
77e06aad  cmp    dword ptr [ebp-8], 5
77e06ab1   jb     loc_77e06abd
77e06ab1
77e06ab3   cmp    dword ptr [ebp-8], $a
77e06ab7   jbe    loc_77e06b57
77e06ab7
77e06abd loc_77e06abd:
77e06abd  mov    eax, fs:[$18]
77e06ac3   mov    ecx, [ebp+$18]
77e06ac6   mov    eax, [eax+$30]
77e06ac9   add    ecx, 2
77e06acc  push   ecx
77e06acd  push   edi
77e06ace  push   dword ptr [eax+$18]
77e06ad1   call   dword ptr [$77dd139c] ; RtlAllocateHeap (ntdll.dll)
77e06ad1
77e06ad7   mov    ebx, eax
77e06ad9   cmp    ebx, edi
77e06adb  jnz    loc_77e06ae9
77e06adb
77e06add  mov    dword ptr [ebp+$c], 8
77e06ae4   jmp    loc_77dd8146
77e06ae4
77e06ae4 ; ---------------------------------------------------------
77e06ae4
77e06ae9 loc_77e06ae9:
77e06ae9   lea    eax, [ebp+8]
77e06aec  push   eax
77e06aed  lea    eax, [ebp+$18]
77e06af0   push   eax
77e06af1   push   ebx
77e06af2   lea    eax, [ebp+$10]
77e06af5   push   eax
77e06af6   lea    eax, [ebp-$10]
77e06af9   push   eax
77e06afa  push   dword ptr [ebp+$c]
77e06afd  push   esi
77e06afe  call   +$2f708 ($77e3620b)
77e06afe
77e06b03   cmp    eax, edi
77e06b05   mov    [ebp+$c], eax
77e06b08   jnz    loc_77e06b38
77e06b08
77e06b0a  cmp    dword ptr [ebp+$10], 1
77e06b0e  jz     loc_77e06b1c
77e06b0e
77e06b10   cmp    dword ptr [ebp+$10], 7
77e06b14   jz     loc_77e06b1c
77e06b14
77e06b16   cmp    dword ptr [ebp+$10], 2
77e06b1a  jnz    loc_77e06b20
77e06b1a
77e06b1c loc_77e06b1c:
77e06b1c  sub    dword ptr [ebp+$18], 2
77e06b1a
77e06b20 loc_77e06b20:
77e06b20   mov    ecx, [ebp+$18]
77e06b23   mov    edi, [ebp+$20]
77e06b26   mov    eax, ecx
77e06b28   shr    ecx, 2
77e06b2b  mov    esi, ebx
77e06b2d  rep movsd
77e06b2f  mov    ecx, eax
77e06b31   and    ecx, 3
77e06b34   rep movsb
77e06b36   xor    edi, edi
77e06b34
77e06b38 loc_77e06b38:
77e06b38   mov    eax, fs:[$18]
77e06b3e  mov    eax, [eax+$30]
77e06b41   push   ebx
77e06b42   push   edi
77e06b43   push   dword ptr [eax+$18]
77e06b46   call   dword ptr [$77dd1394] ; RtlFreeHeap (ntdll.dll)
77e06b46
77e06b4c  mov    ebx, [ebp+$20]
77e06b4f  mov    esi, [ebp+$24]
77e06b52   jmp    loc_77dd811e
77e06b52
77e06b52 ; ---------------------------------------------------------
77e06b52
77e06b57 loc_77e06b57:
77e06b57   lea    eax, [ebp+8]
77e06b5a  push   eax
77e06b5b  lea    eax, [ebp+$18]
77e06b5e  push   eax
77e06b5f  push   ebx
77e06b60   lea    eax, [ebp+$10]
77e06b63   push   eax
77e06b64   lea    eax, [ebp-$10]
77e06b67   push   eax
77e06b68   push   dword ptr [ebp+$c]
77e06b6b  push   esi
77e06b6c  call   +$2f69a ($77e3620b)
77e06b6c
77e06b71   mov    esi, [ebp+$24]
77e06b74   jmp    loc_77dd811b
77e06b74
77e06b74 ; ---------------------------------------------------------
77e06b74
77e06b79 loc_77e06b79:
77e06b79   add    ecx, 2
77e06b7c  cmp    ecx, [esi]
77e06b7e  ja     loc_77dd8127
77e06b7e
77e06b84   mov    [eax], di
77e06b87   jmp    loc_77dd8127
77e06b87
77e06b87 ; ---------------------------------------------------------
77e06b87
77e06b8c loc_77e06b8c:
77e06b8c  lea    eax, [ebp-4]
77e06b8f  push   eax
77e06b90   call   -$3001d ($77dd6b78)
77e06b90
77e06b95   jmp    loc_77dd814f
Line 251 is
Code:
ilRet := WinVerifyTrust(INVALID_HANDLE_VALUE, @WINTRUST_ACTION_GENERIC_VERIFY_V2, @WTrustData);
Here's the full source of the unit:
Delphi-Quellcode:
{-----------------------------------------------------------------------------
Unit Name: uSimpleTrustCheck
Author:    ACE-ppc
Date:      04-Apr-2005
Purpose:  Unit for simple check if a file is Trusted
History:  V1.0: Erste Version
            v1.1: Speicher Leaks beseitigt, WINTRUST_DATA Struktur angepasst

-----------------------------------------------------------------------------}



unit uSimpleTrustCheck;

interface

function CheckFileTrust(const sFilename: string): Boolean;

implementation

uses
  Windows,
  SysUtils;

const
  //Kostanten für die dwUnionChoice in WINTRUST_DATA
  WTD_CHOICE_FILE = 1;
  WTD_CHOICE_CATALOG = 2;

  //Konstanten für dwStateAction
  WTD_STATEACTION_IGNORE = 0;
  WTD_STATEACTION_VERIFY = 1;

  //UI Konstanten für WINTRUST_DATA
  WTD_UI_NONE = 2; //kein UI anzeigen

  //Konstanten zur Prüfung auf zurückgezogene Zertifikate
  WTD_REVOKE_NONE = 0; // keine zusätzliche Prüfun

  //Konstanten für TrustProvider
  WTD_SAFER_FLAG = 256; // für Winxp Sp2 benötigt

  //Wintrust Action GUID´s
  WINTRUST_ACTION_GENERIC_VERIFY_V2: TGUID = '{00AAC56B-CD44-11d0-8CC2-00C04FC295EE}';


type

  CATALOG_INFO = record
    cbStruct: DWORD; // = sizeof(WINTRUST_CATALOG_INFO)
    sCatalogFile: array[0..MAX_PATH] of WCHAR; // Dateiname incl. Pfad zur CAT Datei
  end;
  PCATALOG_INFO = ^CATALOG_INFO;


  WINTRUST_CATALOG_INFO = record
    cbStruct: DWORD; // = sizeof(WINTRUST_CATALOG_INFO)
    dwCatalogVersion: DWORD; // optional
    pcwszCatalogFilePath: LPCWSTR; // benötigt, Dateiname incl. Pfad zur CAT Datei
    pcwszMemberTag: LPCWSTR; // benötigt, tag zum Mitglied im Katalog
    pcwszMemberFilePath: LPCWSTR; // benötigt, Dateiname incl. Pfad
    hMemberFile: THANDLE; // optional
  end;
  PWINTRUST_CATALOG_INFO = ^WINTRUST_CATALOG_INFO;


  WINTRUST_FILE_INFO = record
    cbStruct: DWORD; // = sizeof(WINTRUST_FILE_INFO)
    pcwszFilePath: LPCWSTR; // benötigt, Dateiname incl. Pfad
    pgKnownSubject: PGUID; // optional
    hFile: THANDLE; // optional
  end;
  PWINTRUST_FILE_INFO = ^WINTRUST_FILE_INFO;


  WINTRUST_DATA = packed record
    cbStruct: DWORD; // = sizeof(WINTRUST_DATA)
    pPolicyCallbackData: pointer; // optional - auf 0 setzen
    pSIPClientData: pointer; // optional - auf 0 setzen
    dwUIChoice: DWORD; // benötigt, UI auswahl
    fdwRevocationChecks: DWORD; // benötigt, auf zurückgezogene Zertifikate prüfen (online ben.)
    dwUnionChoice: DWORD; // benötigt, welche Datenstruktur soll verwendet werden
    pWTDINFO: pointer; // Pointer zu einer der Wintrust_X_Info Strukturen
    pFake: pointer; //Fake Pointer - nötig damit der Speicer wieder freigegeben wird
    pFake1: pointer; //Fake Pointer - nötig damit der Speicer wieder freigegeben wird
    pFake2: pointer; //Fake Pointer - nötig damit der Speicer wieder freigegeben wird
    pFake3: pointer; //Fake Pointer - nötig damit der Speicer wieder freigegeben wird
    dwStateAction: DWORD;
    hWVTStateData: THANDLE;
    pwszURLReference: PWChar;
    dwProvFlags: DWORD;
    dwUIContext: DWORD;

  end;
  PWINTRUST_DATA = ^WINTRUST_DATA;

  //Handle und Pointer auf KatalogAdminKontext
  HCatAdmin = THANDLE;
  PHCatAdmin = ^HCatAdmin;


var
  hLibWintrust : THANDLE;

  //dynamische Dll Aufrufe - keine Statische einbindung möglich
  CryptCATAdminAcquireContext : function(PHCatAdmin: PHCatAdmin; pgSubsystem: PGUID; dwFlags: DWORD): BOOL; stdcall;
  CryptCATAdminReleaseContext : function(HCatAdmin: HCatAdmin; dwFlags: DWORD): BOOL; stdcall;
  CryptCATAdminCalcHashFromFileHandle: function(hFile: THANDLE; pHashSize: PDWORD; pbHash: PByteArray; dwFlags: DWORD): BOOL; stdcall;
  CryptCATAdminEnumCatalogFromHash: function(HCatAdmin: HCatAdmin; pbHash: PByteArray; pHashSize: DWORD; dwFlags: DWORD; phPrevCatInfo: PHandle): THANDLE; stdcall;
  CryptCATCatalogInfoFromContext: function(hCatInfo: THANDLE; psCatInfo: PCATALOG_INFO; dwFlags: DWORD): BOOL; stdcall;
  CryptCATAdminReleaseCatalogContext: function(HCatAdmin: HCatAdmin; hCatInfo: THANDLE; dwFlags: DWORD): BOOL; stdcall;
  WinVerifyTrust : function(hwnd: THANDLE; pgActionID: PGUID; pWintrustData: PWINTRUST_DATA): Longint; stdcall;





{-----------------------------------------------------------------------------
  Funcktion:  CheckFileTrust
  Date:        02-Mrz-2005
  Arguments:  const sFilename: string
  Result:      Boolean
  Description: Prüft ob die angegebene Datei Trusted ist
-----------------------------------------------------------------------------}

function CheckFileTrust(const sFilename: string): Boolean;
var
  //Byte Array und Counter
  aByteHash : array[0..255] of Byte;
  iByteCount : Integer;

  hCatAdminContext : HCatAdmin;
  WTrustData : WINTRUST_DATA;
  WTDCatalogInfo : WINTRUST_CATALOG_INFO;
  WTDFileInfo : WINTRUST_FILE_INFO;
  CatalogInfo : CATALOG_INFO;

  hFile : THANDLE;
  hCatalogContext : THANDLE;

  swFilename : WideString;
  swMemberTag : WideString;

  ilRet : Longint;
  x : Integer;

begin

  //Standard Result setzen
  Result := False;

  //Sicherheitsabfrage ob Datei existiert
  if FileExists(sFilename) = False then Exit;

  //String in Widestring wandeln
  swFilename := sFilename;


  ZeroMemory(@CatalogInfo, SizeOf(CatalogInfo));
  ZeroMemory(@WTDFileInfo, SizeOf(WTDFileInfo));
  ZeroMemory(@WTDCatalogInfo, SizeOf(WTDCatalogInfo));
  ZeroMemory(@WTrustData, SizeOf(WTrustData));


  //Catalog Admin Kontext öffnen und falls nicht möglich Prozedur verlassen
  if CryptCATAdminAcquireContext(@hCatAdminContext, nil, 0) = False then Exit;


  //Filehandle auf die zu prüfende Datei holen
  hFile := CreateFile(PChar(string(sFilename)), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

  //Wenn das Handle nicht erhalten wurde Prozedur verlassen
  if hFile = INVALID_HANDLE_VALUE then
  begin
  CloseHandle(hFile);
  Exit;
  end;


  //iaBytescount nach größe des Arrays setzen
  iByteCount := SizeOf(aByteHash);

  //ByteArray mit Hash füllen lassen und die Größe in iByteCount bekommen
  CryptCATAdminCalcHashFromFileHandle(hFile, @iByteCount, @aByteHash, 0);

  // MemberTag brechnen (vom ByteArray auf HEX)
  for x := 0 to iByteCount - 1 do
  begin
    swMemberTag := swMemberTag + IntToHex(aByteHash[x], 2);
  end;

  //FileHandle schließen - wird nicht mehr gebraucht
  CloseHandle(hFile);


  //Erste Prüfung erfolgt mit WINTRUST_DATA.dwUnionChoice := WTD_CHOICE_CATALOG;
  //also muss WINTRUST_CATALOG_INFO gefüllt werden
  //
  //Handle auf den Katalog Kontext holen
  hCatalogContext := CryptCATAdminEnumCatalogFromHash(hCatAdminContext, @aByteHash, iByteCount, 0, nil);

  //Wenn das Handle 0 ist muss die Prüfung mit der
  //WINTRUST_DATA.dwUnionChoice := WTD_CHOICE_FILE; Struktur durchgeführt werden
  if hCatalogContext = 0 then
  begin
    //CatalogContext = 0 also
    //
    //WINTRUST_FILE_INFO Struktur initialisieren und füllen
    WTDFileInfo.cbStruct := SizeOf(WTDFileInfo);
    WTDFileInfo.pcwszFilePath := PWideChar(swFilename);
    WTDFileInfo.pgKnownSubject := nil;
    WTDFileInfo.hFile := 0;

    //WINTRUST_DATA Struktur initialisieren und füllen
    WTrustData.cbStruct := SizeOf(WTrustData);
    WTrustData.dwUnionChoice := WTD_CHOICE_FILE; //WINTRUST_FILE_INFO Struktur wählen
    WTrustData.pWTDINFO := @WTDFileInfo; //Pointer zu WINTRUST_FILE_INFO
    WTrustData.dwUIChoice := WTD_UI_NONE;
    WTrustData.fdwRevocationChecks := WTD_REVOKE_NONE;
    WTrustData.dwStateAction := WTD_STATEACTION_IGNORE;
    WTrustData.dwProvFlags := WTD_SAFER_FLAG; //UI bei XP SP2 unterbinden
    WTrustData.hWVTStateData := 0;
    WTrustData.pwszURLReference := nil;
  end
  else
  begin
    //CatalogContext <> 0 also CATALOG_INFO benutzen
    //
    //CATALOG_INFO Struktur füllen
    CryptCATCatalogInfoFromContext(hCatalogContext, @CatalogInfo, 0);

    //WINTRUST_CATALOG_INFO Struktur initialisieren und füllen
    WTDCatalogInfo.cbStruct := SizeOf(WTDCatalogInfo);
    WTDCatalogInfo.pcwszCatalogFilePath := CatalogInfo.sCatalogFile;
    WTDCatalogInfo.pcwszMemberFilePath := PWideChar(swFilename);
    WTDCatalogInfo.pcwszMemberTag := PWideChar(swMemberTag);

    //WINTRUST_DATA Struktur initialisieren und füllen
    WTrustData.cbStruct := SizeOf(WTrustData);
    WTrustData.dwUnionChoice := WTD_CHOICE_CATALOG; //WINTRUST_CATALOG_INFO Struktur wählen
    WTrustData.pWTDINFO := @WTDCatalogInfo; //Pointer zu WINTRUST_CATALOG_INFO
    WTrustData.dwUIChoice := WTD_UI_NONE;
    WTrustData.fdwRevocationChecks := WTD_REVOKE_NONE;
    WTrustData.pPolicyCallbackData := nil;
    WTrustData.pSIPClientData := nil;
    WTrustData.dwStateAction := WTD_STATEACTION_VERIFY;
    WTrustData.dwProvFlags := 0; //WTD_SAFER_FLAG; //UI bei XP SP2 unterbinden
    WTrustData.hWVTStateData := 0;
    WTrustData.pwszURLReference := nil;
  end;

  //WinVerifyTrust aufrufen um die Prüfung durchzuführen
  ilRet := WinVerifyTrust(INVALID_HANDLE_VALUE, @WINTRUST_ACTION_GENERIC_VERIFY_V2, @WTrustData);

  //Wenn Erg. 0 ist dann ist das File Trusted - alle anderen Werte sind Fehlercodes
  if ilRet = 0 then
  begin
    Result := True
  end
  else
    Result := False;

  //Handle zum Catalogfile schließen
  CryptCATAdminReleaseCatalogContext(hCatAdminContext, hCatalogContext, 0);

  //Catalog Admin Kontext schließen
  CryptCATAdminReleaseContext(hCatAdminContext, 0);
end;



initialization
  //Dynamisches laden der Dll und deren Funktionen
  hLibWintrust := LoadLibrary('wintrust.dll');
  if hLibWintrust >= 32 then { success }
  begin
    CryptCATAdminAcquireContext := GetProcAddress(hLibWintrust, 'CryptCATAdminAcquireContext');
    CryptCATAdminReleaseContext := GetProcAddress(hLibWintrust, 'CryptCATAdminReleaseContext');
    CryptCATAdminCalcHashFromFileHandle := GetProcAddress(hLibWintrust, 'CryptCATAdminCalcHashFromFileHandle');
    CryptCATAdminEnumCatalogFromHash := GetProcAddress(hLibWintrust, 'CryptCATAdminEnumCatalogFromHash');
    CryptCATCatalogInfoFromContext := GetProcAddress(hLibWintrust, 'CryptCATCatalogInfoFromContext');
    CryptCATAdminReleaseCatalogContext := GetProcAddress(hLibWintrust, 'CryptCATAdminReleaseCatalogContext');
    WinVerifyTrust := GetProcAddress(hLibWintrust, 'WinVerifyTrust');
  end;

finalization
  FreeLibrary(hLibWintrust);
end.
Actually, I never get this error in my computer but maybe you know the problem maker and how to avoid this error? Should I use try except in line 251 or is there any better way?

Geändert von SirThornberry (10. Nov 2011 um 11:41 Uhr) Grund: Code-Tags durch Delphi-Tags ersetzt
  Mit Zitat antworten Zitat