コード例 #1
0
        public static bool IsTrusted(string filename)
        {
            try
            {
                Guid wintrust_action_generic_verify_v2 = new Guid(@"{00AAC56B-CD44-11d0-8CC2-00C04FC295EE}");
                uint result = 0;

                using (WINTRUST_FILE_INFO fileInfo = new WINTRUST_FILE_INFO(filename, Guid.Empty))
                    using (UnmanagedPointer guidPtr = new UnmanagedPointer(Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Guid))), AllocMethod.HGlobal))
                        using (UnmanagedPointer wvtDataPtr = new UnmanagedPointer(Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WINTRUST_DATA))), AllocMethod.HGlobal))
                        {
                            WINTRUST_DATA data  = new WINTRUST_DATA(fileInfo);
                            IntPtr        pGuid = guidPtr;
                            IntPtr        pData = wvtDataPtr;
                            Marshal.StructureToPtr(wintrust_action_generic_verify_v2, pGuid, true);
                            Marshal.StructureToPtr(data, pData, true);
                            result = WinVerifyTrust(IntPtr.Zero, pGuid, pData);
                        }

                return(result == 0);
            }
            catch
            {
                //assume we are not running on a platform which supports wintrust and just allow the update to proceed.
                return(true);
            }
        }
コード例 #2
0
        private void Dispose(bool disposing)
        {
            if (dwUnionChoice == UnionChoice.File)
            {
                WINTRUST_FILE_INFO info = new WINTRUST_FILE_INFO();
                Marshal.PtrToStructure(pInfoStruct, info);
                info.Dispose();
                Marshal.DestroyStructure(pInfoStruct, typeof(WINTRUST_FILE_INFO));
            }

            Marshal.FreeHGlobal(pInfoStruct);
        }
コード例 #3
0
        public WINTRUST_DATA(WINTRUST_FILE_INFO fileInfo)
        {
            this.cbStruct = (uint)Marshal.SizeOf(typeof(WINTRUST_DATA));
            pInfoStruct   = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WINTRUST_FILE_INFO)));

            Marshal.StructureToPtr(fileInfo, pInfoStruct, false);

            this.dwUnionChoice = UnionChoice.File;

            pPolicyCallbackData = IntPtr.Zero;
            pSIPCallbackData    = IntPtr.Zero;
            dwUIChoice          = UiChoice.NoUI;
            fdwRevocationChecks = RevocationCheckFlags.None;
            dwStateAction       = StateAction.Ignore;
            hWVTStateData       = IntPtr.Zero;
            pwszURLReference    = IntPtr.Zero;
            dwProvFlags         = TrustProviderFlags.Safer;
            dwUIContext         = UIContext.Execute;
        }