|
| 1 | +using System; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | +using DWORD = System.UInt32; |
| 4 | +using BOOL = System.UInt32; |
| 5 | + |
| 6 | +namespace wcommsixwrap |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Contains all of the native Win32 stuff |
| 10 | + /// </summary> |
| 11 | + class NativeMethods |
| 12 | + { |
| 13 | + [StructLayout(LayoutKind.Sequential)] |
| 14 | + internal struct CRYPTCATATTRIBUTE |
| 15 | + { |
| 16 | + private DWORD _cbStruct; |
| 17 | + [MarshalAs(UnmanagedType.LPWStr)] |
| 18 | + internal string pwszReferenceTag; |
| 19 | + private DWORD _dwAttrTypeAndAction; |
| 20 | + internal DWORD cbValue; |
| 21 | + internal System.IntPtr pbValue; |
| 22 | + private DWORD _dwReserved; |
| 23 | + }; |
| 24 | + |
| 25 | + [StructLayout(LayoutKind.Sequential)] |
| 26 | + internal struct CRYPTCATMEMBER |
| 27 | + { |
| 28 | + internal DWORD cbStruct; |
| 29 | + [MarshalAs(UnmanagedType.LPWStr)] |
| 30 | + internal string pwszReferenceTag; |
| 31 | + [MarshalAs(UnmanagedType.LPWStr)] |
| 32 | + internal string pwszFileName; |
| 33 | + internal GUID gSubjectType; |
| 34 | + internal DWORD fdwMemberFlags; |
| 35 | + internal IntPtr pIndirectData; |
| 36 | + internal DWORD dwCertVersion; |
| 37 | + internal DWORD dwReserved; |
| 38 | + internal IntPtr hReserved; |
| 39 | + internal CRYPT_ATTR_BLOB sEncodedIndirectData; |
| 40 | + internal CRYPT_ATTR_BLOB sEncodedMemberInfo; |
| 41 | + }; |
| 42 | + |
| 43 | + [StructLayout(LayoutKind.Sequential)] |
| 44 | + internal struct CRYPT_ATTR_BLOB |
| 45 | + { |
| 46 | + /// DWORD->unsigned int |
| 47 | + public uint cbData; |
| 48 | + |
| 49 | + /// BYTE* |
| 50 | + public System.IntPtr pbData; |
| 51 | + } |
| 52 | + |
| 53 | + [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)] |
| 54 | + internal struct GUID |
| 55 | + { |
| 56 | + /// unsigned int |
| 57 | + internal uint Data1; |
| 58 | + |
| 59 | + /// unsigned short |
| 60 | + internal ushort Data2; |
| 61 | + |
| 62 | + /// unsigned short |
| 63 | + internal ushort Data3; |
| 64 | + |
| 65 | + /// unsigned char[8] |
| 66 | + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] |
| 67 | + internal byte[] Data4; |
| 68 | + } |
| 69 | + |
| 70 | + [StructLayout(LayoutKind.Sequential)] |
| 71 | + internal struct SIP_INDIRECT_DATA |
| 72 | + { |
| 73 | + internal CRYPT_ATTRIBUTE_TYPE_VALUE Data; |
| 74 | + internal CRYPT_ALGORITHM_IDENTIFIER DigestAlgorithm; |
| 75 | + internal CRYPT_ATTR_BLOB Digest; |
| 76 | + } |
| 77 | + |
| 78 | + [StructLayout(LayoutKind.Sequential)] |
| 79 | + internal struct CRYPT_ATTRIBUTE_TYPE_VALUE |
| 80 | + { |
| 81 | + [MarshalAs(UnmanagedType.LPStr)] |
| 82 | + internal string pszObjId; |
| 83 | + internal CRYPT_ATTR_BLOB Value; |
| 84 | + } |
| 85 | + |
| 86 | + [DllImport("wintrust.dll", CharSet = CharSet.Unicode)] |
| 87 | + internal static extern IntPtr CryptCATOpen( |
| 88 | + [MarshalAs(UnmanagedType.LPWStr)] |
| 89 | + string pwszFilePath, |
| 90 | + DWORD fdwOpenFlags, |
| 91 | + IntPtr hProv, |
| 92 | + DWORD dwPublicVersion, |
| 93 | + DWORD dwEncodingType |
| 94 | + ); |
| 95 | + |
| 96 | + [StructLayoutAttribute(LayoutKind.Sequential)] |
| 97 | + internal struct CRYPT_ALGORITHM_IDENTIFIER |
| 98 | + { |
| 99 | + /// LPSTR->CHAR* |
| 100 | + [MarshalAsAttribute(UnmanagedType.LPStr)] |
| 101 | + internal string pszObjId; |
| 102 | + |
| 103 | + /// CRYPT_OBJID_BLOB->_CRYPTOAPI_BLOB |
| 104 | + internal CRYPT_ATTR_BLOB Parameters; |
| 105 | + } |
| 106 | + |
| 107 | + [StructLayout(LayoutKind.Sequential)] |
| 108 | + internal struct CRYPTCATSTORE |
| 109 | + { |
| 110 | + private DWORD _cbStruct; |
| 111 | + internal DWORD dwPublicVersion; |
| 112 | + [MarshalAs(UnmanagedType.LPWStr)] |
| 113 | + internal string pwszP7File; |
| 114 | + private IntPtr _hProv; |
| 115 | + private DWORD _dwEncodingType; |
| 116 | + private DWORD _fdwStoreFlags; |
| 117 | + private IntPtr _hReserved; |
| 118 | + private IntPtr _hAttrs; |
| 119 | + private IntPtr _hCryptMsg; |
| 120 | + private IntPtr _hSorted; |
| 121 | + }; |
| 122 | + |
| 123 | + [DllImport("wintrust.dll")] |
| 124 | + internal static extern BOOL CryptCATClose( |
| 125 | + IntPtr hCatalog |
| 126 | + ); |
| 127 | + |
| 128 | + [DllImport("wintrust.dll", CharSet = CharSet.Unicode)] |
| 129 | + internal static extern IntPtr CryptCATEnumerateCatAttr( |
| 130 | + IntPtr hCatalog, |
| 131 | + IntPtr pPrevAttr |
| 132 | + ); |
| 133 | + |
| 134 | + [DllImport("wintrust.dll", CharSet = CharSet.Unicode)] |
| 135 | + internal static extern IntPtr CryptCATEnumerateMember( |
| 136 | + IntPtr hCatalog, |
| 137 | + IntPtr pPrevMember |
| 138 | + ); |
| 139 | + |
| 140 | + [DllImport("wintrust.dll", CharSet = CharSet.Unicode)] |
| 141 | + internal static extern IntPtr CryptCATEnumerateAttr( |
| 142 | + IntPtr hCatalog, |
| 143 | + IntPtr pCatMember, |
| 144 | + IntPtr pPrevAttr |
| 145 | + ); |
| 146 | + |
| 147 | + [DllImport("wintrust.dll", CharSet = CharSet.Unicode)] |
| 148 | + internal static extern IntPtr CryptCATStoreFromHandle( |
| 149 | + IntPtr hCatalog |
| 150 | + ); |
| 151 | + |
| 152 | + [DllImport("wintrust.dll", CharSet = CharSet.Unicode)] |
| 153 | + internal static extern bool CryptCATAdminAcquireContext2( |
| 154 | + ref IntPtr phCatAdmin, |
| 155 | + IntPtr pgSubsystem, |
| 156 | + [MarshalAs(UnmanagedType.LPWStr)] |
| 157 | + string pwszHashAlgorithm, |
| 158 | + IntPtr pStrongHashPolicy, |
| 159 | + DWORD dwFlags |
| 160 | + ); |
| 161 | + |
| 162 | + [DllImport("wintrust.dll", SetLastError = true, CharSet = CharSet.Unicode)] |
| 163 | + internal static extern bool CryptCATAdminCalcHashFromFileHandle2( |
| 164 | + IntPtr hCatAdmin, |
| 165 | + IntPtr hFile, |
| 166 | + [In, Out] ref DWORD pcbHash, |
| 167 | + IntPtr pbHash, |
| 168 | + DWORD dwFlags |
| 169 | + ); |
| 170 | + |
| 171 | + [DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)] |
| 172 | + internal static extern unsafe IntPtr CreateFile( |
| 173 | + string lpFileName, |
| 174 | + DWORD dwDesiredAccess, |
| 175 | + DWORD dwShareMode, |
| 176 | + DWORD lpSecurityAttributes, |
| 177 | + DWORD dwCreationDisposition, |
| 178 | + DWORD dwFlagsAndAttributes, |
| 179 | + IntPtr hTemplateFile |
| 180 | + ); |
| 181 | + |
| 182 | + [DllImport("wintrust.dll", CharSet = CharSet.Unicode)] |
| 183 | + internal static extern bool CryptCATAdminReleaseContext( |
| 184 | + IntPtr phCatAdmin, |
| 185 | + DWORD dwFlags |
| 186 | + ); |
| 187 | + |
| 188 | + internal const string CloseHandleDllName = "api-ms-win-core-handle-l1-1-0.dll"; /*32*/ |
| 189 | + /// Return Type: BOOL->int |
| 190 | + ///hObject: HANDLE->void* |
| 191 | + [DllImportAttribute(CloseHandleDllName, EntryPoint = "CloseHandle")] |
| 192 | + [return: MarshalAsAttribute(UnmanagedType.Bool)] |
| 193 | + internal static extern bool CloseHandle([InAttribute()] System.IntPtr hObject); |
| 194 | + } |
| 195 | +} |
0 commit comments