Changeset 1531
- Timestamp:
- 1/15/2010 4:22:46 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser.Util/WintrustApi.cs
r1360 r1531 37 37 public static bool VerifyAuthenticode(string pathToFile) 38 38 { 39 NativeMethods.WINTRUST_FILE_INFO fileinfo = new NativeMethods.WINTRUST_FILE_INFO(); 40 fileinfo.cbStruct = (uint)Marshal.SizeOf(typeof(NativeMethods.WINTRUST_FILE_INFO)); 41 fileinfo.pcwszFilePath = pathToFile; 42 43 NativeMethods.WINTRUST_DATA data = new NativeMethods.WINTRUST_DATA(); 44 data.cbStruct = (uint)Marshal.SizeOf(typeof(NativeMethods.WINTRUST_DATA)); 45 data.dwUIChoice = NativeMethods.WINTRUST_DATA.UIChoices.WTD_UI_NONE; 46 data.fdwRevocationChecks = NativeMethods.WINTRUST_DATA.RevocationChecks.WTD_REVOKE_NONE; 47 data.dwUnionChoice = NativeMethods.WINTRUST_DATA.UnionChoices.WTD_CHOICE_FILE; 48 data.pUnion = Marshal.AllocHGlobal((int)fileinfo.cbStruct); 49 Marshal.StructureToPtr(fileinfo, data.pUnion, false); 50 51 Guid guid = NativeMethods.WINTRUST_ACTION_GENERIC_VERIFY_V2; 52 int result = NativeMethods.WinVerifyTrust(IntPtr.Zero, ref guid, ref data); 53 Marshal.FreeHGlobal(data.pUnion); 54 return result == 0; 39 IntPtr unionPointer = IntPtr.Zero; 40 41 try 42 { 43 NativeMethods.WINTRUST_FILE_INFO fileinfo = new NativeMethods.WINTRUST_FILE_INFO(); 44 fileinfo.cbStruct = (uint)Marshal.SizeOf(typeof(NativeMethods.WINTRUST_FILE_INFO)); 45 fileinfo.pcwszFilePath = pathToFile; 46 47 NativeMethods.WINTRUST_DATA data = new NativeMethods.WINTRUST_DATA(); 48 data.cbStruct = (uint)Marshal.SizeOf(typeof(NativeMethods.WINTRUST_DATA)); 49 data.dwUIChoice = NativeMethods.WINTRUST_DATA.UIChoices.WTD_UI_NONE; 50 data.fdwRevocationChecks = NativeMethods.WINTRUST_DATA.RevocationChecks.WTD_REVOKE_NONE; 51 data.dwUnionChoice = NativeMethods.WINTRUST_DATA.UnionChoices.WTD_CHOICE_FILE; 52 unionPointer = data.pUnion = Marshal.AllocHGlobal((int)fileinfo.cbStruct); 53 Marshal.StructureToPtr(fileinfo, data.pUnion, false); 54 55 Guid guid = NativeMethods.WINTRUST_ACTION_GENERIC_VERIFY_V2; 56 return NativeMethods.WinVerifyTrust(IntPtr.Zero, ref guid, ref data) == 0; 57 } 58 finally 59 { 60 if (unionPointer != IntPtr.Zero) 61 Marshal.FreeHGlobal(unionPointer); 62 } 55 63 } 56 64
Note: See TracChangeset
for help on using the changeset viewer.
