Ejemplo n.º 1
0
    private static uint WinVerifyTrust(string fileName)
    {
        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);
    }
Ejemplo n.º 2
0
        public static WinVerifyTrustResult WinVerifyTrust(string fileName)
        {
            WINTRUST_FILE_INFO fileInfo = new WINTRUST_FILE_INFO(fileName, Guid.Empty);
            WINTRUST_DATA      data     = new WINTRUST_DATA(fileInfo);

            uint result;

#if DEBUG
            uint r2;
#endif

            using (UnmanagedPointer guidPtr = new UnmanagedPointer(typeof(Guid), true))
                using (UnmanagedPointer wvtDataPtr = new UnmanagedPointer(typeof(WINTRUST_DATA), true))
                {
                    IntPtr pGuid = guidPtr;
                    IntPtr pData = wvtDataPtr;

                    Marshal.StructureToPtr(wintrust_action_generic_verify_v2, pGuid, false);

                    data.dwStateAction = NativeMethods.StateAction.Verify;
                    Marshal.StructureToPtr(data, pData, false);

                    result = NativeMethods.WinVerifyTrust(INVALID_HANDLE_VALUE, pGuid, pData);

                    data.dwStateAction = NativeMethods.StateAction.Close;
                    Marshal.StructureToPtr(data, pData, true);
#if DEBUG
                    r2 =
#endif
                    NativeMethods.WinVerifyTrust(INVALID_HANDLE_VALUE, pGuid, pData);
                }

            if ((result >= (uint)NativeMethods.TrustE.ProviderUnknown) && (result <= (uint)NativeMethods.TrustE.SubjectNotTrusted))
            {
                return((WinVerifyTrustResult)((int)(result - (uint)NativeMethods.TrustE.Unknown) + (int)WinVerifyTrustResult.FunctionCallFailed));
            }

            switch (result)
            {
            case NativeMethods.ERROR_SUCCESS:
                return(WinVerifyTrustResult.Success);

            case (uint)NativeMethods.TrustE.FileError:
                return(WinVerifyTrustResult.FileError);

            case (uint)NativeMethods.TrustE.BadMsg:
                return(WinVerifyTrustResult.BadMsg);

            case (uint)NativeMethods.TrustE.SecuritySettings:
                return(WinVerifyTrustResult.SecuritySettings);

            case (uint)NativeMethods.TrustE.ASN1BadTag:
                return(WinVerifyTrustResult.ASN1BadTag);

            case (uint)NativeMethods.TrustE.CounterSigner:
                return(WinVerifyTrustResult.CounterSigner);

            case (uint)NativeMethods.TrustE.BadDigest:
                return(WinVerifyTrustResult.BadDigest);

            case (uint)NativeMethods.TrustE.NoSignature:
                return(WinVerifyTrustResult.NoSignature);

            case (uint)NativeMethods.TrustE.CertExpired:
                return(WinVerifyTrustResult.CertExpired);

            case (uint)NativeMethods.TrustE.CertUntrustedRoot:
                return(WinVerifyTrustResult.CertUntrustedRoot);

            case (uint)NativeMethods.TrustE.CertChaining:
                return(WinVerifyTrustResult.CertChaining);

            case (uint)NativeMethods.TrustE.CertRevoked:
                return(WinVerifyTrustResult.CertRevoked);

            case (uint)NativeMethods.TrustE.CertWrongUsage:
                return(WinVerifyTrustResult.CertWrongUsage);

            case (uint)NativeMethods.TrustE.ExplicitDistrust:
                return(WinVerifyTrustResult.ExplicitDistrust);

            default:
                return(WinVerifyTrustResult.FunctionCallFailed);
            }
        }
Ejemplo n.º 3
0
        public IntPtr GetPixelPointer(int column, int row)
        {
            IntPtr rowPtr = GetRowPointer(row);
            int columnoffset = PixRectInfo.GetPixelInformation().BytesPerPixel * column;
            UnmanagedPointer ump = new UnmanagedPointer(rowPtr);
            ump += columnoffset;

            return (IntPtr)ump;
        }
Ejemplo n.º 4
0
        public IntPtr GetRowPointer(int row)
        {
            int offset = 0;

            if (Orientation == PixmapOrientation.TopToBottom)
            {
                offset = BytesPerRow * row;
            }
            else
            {
                offset = (BytesPerRow * (Height - 1 - row));
            }

            UnmanagedPointer ump = new UnmanagedPointer(Pixels);
            ump += offset;

            return (IntPtr)ump;
        }