Exemple #1
1
        internal static WINTRUST_DATA InitWintrustDataStructFromBlob(WINTRUST_BLOB_INFO wbi)
        {
            WINTRUST_DATA wtd = new WINTRUST_DATA();

            wtd.cbStruct = (DWORD)Marshal.SizeOf(wbi);
            wtd.pPolicyCallbackData = IntPtr.Zero;
            wtd.pSIPClientData = IntPtr.Zero;
            wtd.dwUIChoice = (DWORD)WintrustUIChoice.WTD_UI_NONE;
            wtd.fdwRevocationChecks = 0;
            wtd.dwUnionChoice = (DWORD)WintrustUnionChoice.WTD_CHOICE_BLOB;

            IntPtr pBlob = Marshal.AllocCoTaskMem(Marshal.SizeOf(wbi));
            Marshal.StructureToPtr(wbi, pBlob, false);
            wtd.Choice.pBlob = pBlob;

            wtd.dwStateAction = (DWORD)WintrustAction.WTD_STATEACTION_VERIFY;
            wtd.hWVTStateData = IntPtr.Zero;
            wtd.pwszURLReference = null;
            wtd.dwProvFlags = 0;

            return wtd;
        }
Exemple #2
0
        internal static WINTRUST_BLOB_INFO InitWintrustBlobInfoStruct(string fileName, string content)
        {
            WINTRUST_BLOB_INFO structure = new WINTRUST_BLOB_INFO();

            byte[] bytes = Encoding.Unicode.GetBytes(content);
            structure.gSubject.Data1   = 0x603bcc1f;
            structure.gSubject.Data2   = 0x4b59;
            structure.gSubject.Data3   = 0x4e08;
            structure.gSubject.Data4   = new byte[] { 0xb7, 0x24, 210, 0xc6, 0x29, 0x7e, 0xf3, 0x51 };
            structure.cbStruct         = (int)Marshal.SizeOf(structure);
            structure.pcwszDisplayName = fileName;
            structure.cbMemObject      = (int)bytes.Length;
            structure.pbMemObject      = Marshal.AllocCoTaskMem(bytes.Length);
            Marshal.Copy(bytes, 0, structure.pbMemObject, bytes.Length);
            return(structure);
        }
Exemple #3
0
        internal static WINTRUST_DATA InitWintrustDataStructFromBlob(WINTRUST_BLOB_INFO wbi)
        {
            WINTRUST_DATA wintrust_data = new WINTRUST_DATA {
                cbStruct            = (int)Marshal.SizeOf(wbi),
                pPolicyCallbackData = IntPtr.Zero,
                pSIPClientData      = IntPtr.Zero,
                dwUIChoice          = 2,
                fdwRevocationChecks = 0,
                dwUnionChoice       = 3
            };
            IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(wbi));

            Marshal.StructureToPtr(wbi, ptr, false);
            wintrust_data.Choice.pBlob     = ptr;
            wintrust_data.dwStateAction    = 1;
            wintrust_data.hWVTStateData    = IntPtr.Zero;
            wintrust_data.pwszURLReference = null;
            wintrust_data.dwProvFlags      = 0;
            return(wintrust_data);
        }
Exemple #4
0
        public void DestroyStructure_NestedNonBlittableStruct_Success()
        {
            WINTRUST_BLOB_INFO wbi = new WINTRUST_BLOB_INFO();

            byte[] contentBytes = System.Text.Encoding.Unicode.GetBytes("foo");

            wbi.gSubject.Data1 = 0x603bcc1f;
            wbi.gSubject.Data2 = 0x4b59;
            wbi.gSubject.Data3 = 0x4e08;
            wbi.gSubject.Data4 = new byte[] { 0xb7, 0x24, 0xd2, 0xc6, 0x29, 0x7e, 0xf3, 0x51 };

            wbi.cbStruct         = (uint)Marshal.SizeOf(wbi);
            wbi.pcwszDisplayName = "bar";

            IntPtr pBlob = Marshal.AllocCoTaskMem(Marshal.SizeOf(wbi));

            Marshal.StructureToPtr(wbi, pBlob, false);

            Marshal.DestroyStructure <WINTRUST_BLOB_INFO>(pBlob);

            Marshal.FreeCoTaskMem(pBlob);
        }
Exemple #5
0
        internal static uint DestroyWintrustDataStruct(WINTRUST_DATA wtd)
        {
            uint   num       = 0x80004005;
            IntPtr zero      = IntPtr.Zero;
            IntPtr ptr       = IntPtr.Zero;
            Guid   structure = new Guid("00AAC56B-CD44-11d0-8CC2-00C04FC295EE");

            try
            {
                zero = Marshal.AllocCoTaskMem(Marshal.SizeOf(structure));
                Marshal.StructureToPtr(structure, zero, false);
                wtd.dwStateAction = 2;
                ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(wtd));
                Marshal.StructureToPtr(wtd, ptr, false);
                num = WinVerifyTrust(IntPtr.Zero, zero, ptr);
                wtd = (WINTRUST_DATA)Marshal.PtrToStructure(ptr, typeof(WINTRUST_DATA));
            }
            finally
            {
                Marshal.DestroyStructure(ptr, typeof(WINTRUST_DATA));
                Marshal.FreeCoTaskMem(ptr);
                Marshal.DestroyStructure(zero, typeof(Guid));
                Marshal.FreeCoTaskMem(zero);
            }
            if (wtd.dwUnionChoice == 3)
            {
                WINTRUST_BLOB_INFO wintrust_blob_info = (WINTRUST_BLOB_INFO)Marshal.PtrToStructure(wtd.Choice.pBlob, typeof(WINTRUST_BLOB_INFO));
                Marshal.FreeCoTaskMem(wintrust_blob_info.pbMemObject);
                Marshal.DestroyStructure(wtd.Choice.pBlob, typeof(WINTRUST_BLOB_INFO));
                Marshal.FreeCoTaskMem(wtd.Choice.pBlob);
                return(num);
            }
            Marshal.DestroyStructure(wtd.Choice.pFile, typeof(WINTRUST_FILE_INFO));
            Marshal.FreeCoTaskMem(wtd.Choice.pFile);
            return(num);
        }
Exemple #6
0
 internal static WINTRUST_DATA InitWintrustDataStructFromBlob(WINTRUST_BLOB_INFO wbi)
 {
     WINTRUST_DATA wintrust_data = new WINTRUST_DATA {
         cbStruct = (int) Marshal.SizeOf(wbi),
         pPolicyCallbackData = IntPtr.Zero,
         pSIPClientData = IntPtr.Zero,
         dwUIChoice = 2,
         fdwRevocationChecks = 0,
         dwUnionChoice = 3
     };
     IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(wbi));
     Marshal.StructureToPtr(wbi, ptr, false);
     wintrust_data.Choice.pBlob = ptr;
     wintrust_data.dwStateAction = 1;
     wintrust_data.hWVTStateData = IntPtr.Zero;
     wintrust_data.pwszURLReference = null;
     wintrust_data.dwProvFlags = 0;
     return wintrust_data;
 }
Exemple #7
0
 internal static WINTRUST_BLOB_INFO InitWintrustBlobInfoStruct(string fileName, string content)
 {
     WINTRUST_BLOB_INFO structure = new WINTRUST_BLOB_INFO();
     byte[] bytes = Encoding.Unicode.GetBytes(content);
     structure.gSubject.Data1 = 0x603bcc1f;
     structure.gSubject.Data2 = 0x4b59;
     structure.gSubject.Data3 = 0x4e08;
     structure.gSubject.Data4 = new byte[] { 0xb7, 0x24, 210, 0xc6, 0x29, 0x7e, 0xf3, 0x51 };
     structure.cbStruct = (int) Marshal.SizeOf(structure);
     structure.pcwszDisplayName = fileName;
     structure.cbMemObject = (int) bytes.Length;
     structure.pbMemObject = Marshal.AllocCoTaskMem(bytes.Length);
     Marshal.Copy(bytes, 0, structure.pbMemObject, bytes.Length);
     return structure;
 }
Exemple #8
0
        internal static WINTRUST_BLOB_INFO InitWintrustBlobInfoStruct(string fileName, string content)
        {
            WINTRUST_BLOB_INFO bi = new WINTRUST_BLOB_INFO();
            byte[] contentBytes = System.Text.Encoding.Unicode.GetBytes(content);

            // The GUID of the PowerShell SIP
            bi.gSubject.Data1 = 0x603bcc1f;
            bi.gSubject.Data2 = 0x4b59;
            bi.gSubject.Data3 = 0x4e08;
            bi.gSubject.Data4 = new byte[] { 0xb7, 0x24, 0xd2, 0xc6, 0x29, 0x7e, 0xf3, 0x51 };

            bi.cbStruct = (DWORD)Marshal.SizeOf(bi);
            bi.pcwszDisplayName = fileName;
            bi.cbMemObject = (uint)contentBytes.Length;
            bi.pbMemObject = Marshal.AllocCoTaskMem(contentBytes.Length);
            Marshal.Copy(contentBytes, 0, bi.pbMemObject, contentBytes.Length);

            return bi;
        }